renkang
昨天 4a99240038013c7d962040e6f8eabd2d72095fd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <TableLayout :permissions="['business:ywcustomerrecharge:query']">
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
      <el-form-item label="客户名称" prop="nameKeyword">
        <el-input v-model="searchForm.nameKeyword" placeholder="客户名称" clearable @keypress.enter.native="search"/>
      </el-form-item>
      <el-form-item label="电表状态" prop="electricalStatusFilter">
        <el-select v-model="searchForm.electricalStatusFilter" clearable placeholder="全部" style="min-width: 120px">
          <el-option label="全在线" :value="1"/>
          <el-option label="存在离线" :value="2"/>
          <el-option label="无设备" :value="3"/>
        </el-select>
      </el-form-item>
      <el-form-item label="空调状态" prop="conditionerStatusFilter">
        <el-select v-model="searchForm.conditionerStatusFilter" clearable placeholder="全部" style="min-width: 120px">
          <el-option label="全在线" :value="1"/>
          <el-option label="存在离线" :value="2"/>
          <el-option label="无设备" :value="3"/>
        </el-select>
      </el-form-item>
      <section>
        <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
        <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
      </section>
    </el-form>
    <template v-slot:table-wrap>
      <el-table v-loading="isWorking.search" :data="tableData.list" stripe>
        <el-table-column prop="type" label="客户类型" min-width="80" align="center">
          <template slot-scope="{ row }">
            <span>{{ row.type == 0 || row.type === '0' ? '个人' : '企业' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="客户名称" min-width="140" align="center" show-overflow-tooltip/>
        <el-table-column prop="memberName" label="联系人" min-width="120" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.memberName || '-' }}</template>
        </el-table-column>
        <el-table-column prop="memberPhone" label="联系电话" min-width="130" align="center">
          <template slot-scope="{ row }">{{ row.memberPhone || '-' }}</template>
        </el-table-column>
        <el-table-column prop="electricalCount" label="关联电表数" min-width="100" align="center"/>
        <el-table-column label="电表余额" min-width="140" align="center">
          <template slot-scope="{ row }">
            <span v-if="!row.electricalBalances || !row.electricalBalances.length" class="balance-text">-</span>
            <el-tooltip v-else placement="top" effect="dark">
              <div slot="content" class="balance-tooltip">
                <div v-for="(item, idx) in row.electricalBalances" :key="idx" class="balance-tooltip-line">
                  {{ item.name }}({{ item.address }}):{{ formatBalance(item.balance) }}
                </div>
              </div>
              <span class="balance-text balance-summary">
                <template v-for="(item, idx) in row.electricalBalances">
                  <span :key="'b-' + idx" :class="{ red: isAmountLow(item.balance) }">{{ formatBalance(item.balance) }}</span><span v-if="idx < row.electricalBalances.length - 1" :key="'s-' + idx">/</span>
                </template>
              </span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="conditionerCount" label="空调内机数" min-width="100" align="center"/>
        <el-table-column label="空调余额" min-width="110" align="center">
          <template slot-scope="{ row }">
            <span v-if="row.acBalance == null" class="balance-text">-</span>
            <span v-else class="balance-text" :class="{ red: isAmountLow(row.acBalance) }">{{ row.acBalance }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建时间" min-width="160" align="center"/>
        <el-table-column label="操作" min-width="180" align="center" fixed="right">
          <template slot-scope="{ row }">
            <el-button type="text" v-permissions="['business:ywcustomerrecharge:bindDevice']" @click="openDevice(row)">关联设备</el-button>
            <el-button type="text" v-permissions="['business:ywcustomerrecharge:recharge']" @click="openRecharge(row)">充值</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination @size-change="handleSizeChange" @current-change="handlePageChange" :pagination="tableData.pagination"/>
    </template>
    <YwCustomerDeviceWindow ref="deviceWindow" @success="search"/>
    <YwCustomerRechargeWindow ref="rechargeWindow" @success="search"/>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import * as api from '@/api/business/ywcustomerrecharge'
import YwCustomerDeviceWindow from './components/YwCustomerDeviceWindow'
import YwCustomerRechargeWindow from './components/YwCustomerRechargeWindow'
 
export default {
  name: 'YwCustomerRecharge',
  extends: BaseTable,
  components: { TableLayout, Pagination, YwCustomerDeviceWindow, YwCustomerRechargeWindow },
  data () {
    return {
      searchForm: {
        nameKeyword: '',
        electricalStatusFilter: null,
        conditionerStatusFilter: null
      }
    }
  },
  created () {
    this.search()
  },
  methods: {
    handlePageChange (pageIndex) {
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.loadList()
    },
    loadList () {
      this.isWorking.search = true
      api.merchantPage({
        page: this.tableData.pagination.pageIndex,
        capacity: this.tableData.pagination.pageSize,
        model: this.buildSearchModel()
      }).then(data => {
        this.tableData.list = (data && data.records) || []
        this.tableData.pagination.total = (data && data.total) || 0
      }).catch(e => {
        this.$tip.apiFailed(e)
      }).finally(() => { this.isWorking.search = false })
    },
    search () {
      this.tableData.pagination.pageIndex = 1
      this.loadList()
    },
    handleSizeChange (size) {
      this.tableData.pagination.pageSize = size
      this.loadList()
    },
    buildSearchModel () {
      const model = {}
      if (this.searchForm.nameKeyword) model.nameKeyword = this.searchForm.nameKeyword
      if (this.searchForm.electricalStatusFilter != null) model.electricalStatusFilter = this.searchForm.electricalStatusFilter
      if (this.searchForm.conditionerStatusFilter != null) model.conditionerStatusFilter = this.searchForm.conditionerStatusFilter
      return model
    },
    reset () {
      this.searchForm = { nameKeyword: '', electricalStatusFilter: null, conditionerStatusFilter: null }
      this.search()
    },
    openDevice (row) {
      this.$refs.deviceWindow.open(row)
    },
    openRecharge (row) {
      this.$refs.rechargeWindow.open(row)
    },
    formatBalance (val) {
      if (val == null || val === '') return '0'
      const n = parseFloat(val)
      return isNaN(n) ? val : String(val)
    },
    isAmountLow (val) {
      if (val == null || val === '' || val === '-') return false
      const n = parseFloat(val)
      return !isNaN(n) && n <= 0
    }
  }
}
</script>
 
<style scoped>
.red { color: #f56c6c; }
.balance-text { white-space: nowrap; }
.balance-summary {
  cursor: default;
}
</style>
 
<style>
.balance-tooltip {
  line-height: 22px;
}
.balance-tooltip-line {
  white-space: nowrap;
}
</style>