doum
7 天以前 e46bfa3ff94a8a1b4daf37c7fcb79c2fab22a72c
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
<template>
  <div>
    <div class="toolbar-row">
      <el-button type="primary" size="small" v-permissions="['business:ywcustomerrecharge:bindDevice']" @click="openSelector">去选择电表</el-button>
    </div>
    <el-table v-loading="loading" :data="list" stripe size="small">
      <el-table-column prop="name" label="名称" min-width="120" align="center" show-overflow-tooltip/>
      <el-table-column prop="address" label="表地址" min-width="130" align="center" show-overflow-tooltip/>
      <el-table-column prop="accountId" label="开户号" min-width="100" align="center"/>
      <el-table-column prop="roomNames" label="房间" min-width="120" align="center" show-overflow-tooltip/>
      <el-table-column label="在线" min-width="80" align="center">
        <template slot-scope="{ row }">
          <span :class="row.online === 1 ? 'green' : 'red'">{{ row.online === 1 ? '在线' : '离线' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="继电器" min-width="80" align="center">
        <template slot-scope="{ row }">{{ relayText(row.relayStatus) }}</template>
      </el-table-column>
      <el-table-column label="操作" min-width="80" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" class="red" v-permissions="['business:ywcustomerrecharge:bindDevice']" @click="remove(row)">移除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination small @size-change="onSizeChange" @current-change="onPageChange" :pagination="pagination"/>
 
    <GlobalWindow title="选择电表" :visible.sync="selectorVisible" width="780px" @confirm="confirmSelect">
      <el-form inline @submit.native.prevent>
        <el-form-item label="关键字">
          <el-input v-model="selectorKeyword" placeholder="名称/地址" clearable @keypress.enter.native="searchSelectable"/>
        </el-form-item>
        <el-button type="primary" @click="searchSelectable">查询</el-button>
      </el-form>
      <el-table ref="selectTable" v-loading="selectorLoading" :data="selectorList" stripe size="small" @selection-change="onSelectionChange">
        <el-table-column type="selection" width="45"/>
        <el-table-column prop="name" label="名称" min-width="120" align="center"/>
        <el-table-column prop="address" label="表地址" min-width="130" align="center"/>
        <el-table-column prop="roomNames" label="房间" min-width="120" align="center" show-overflow-tooltip/>
        <el-table-column label="在线" min-width="80" align="center">
          <template slot-scope="{ row }">
            <span :class="row.online === 1 ? 'green' : 'red'">{{ row.online === 1 ? '在线' : '离线' }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination small @current-change="onSelectorPageChange" :pagination="selectorPagination"/>
    </GlobalWindow>
  </div>
</template>
 
<script>
import GlobalWindow from '@/components/common/GlobalWindow'
import Pagination from '@/components/common/Pagination'
import * as api from '@/api/business/ywcustomerrecharge'
 
export default {
  name: 'YwCustomerElectricalTab',
  components: { GlobalWindow, Pagination },
  props: {
    customerId: Number,
    active: Boolean
  },
  data () {
    return {
      loading: false,
      list: [],
      pagination: { pageIndex: 1, pageSize: 10, total: 0 },
      selectorVisible: false,
      selectorLoading: false,
      selectorList: [],
      selectorKeyword: '',
      selectorPagination: { pageIndex: 1, pageSize: 10, total: 0 },
      selectedRows: []
    }
  },
  watch: {
    active (val) {
      if (val) this.loadList()
    },
    customerId () {
      if (this.active) this.loadList()
    }
  },
  mounted () {
    if (this.active) this.loadList()
  },
  methods: {
    relayText (v) {
      if (v === '0' || v === 0) return '拉闸'
      if (v === '1' || v === 1) return '合闸'
      return v || '-'
    },
    loadList () {
      if (!this.customerId) return
      this.loading = true
      api.electricalPage(this.customerId, {
        page: this.pagination.pageIndex,
        capacity: this.pagination.pageSize,
        model: {}
      }).then(data => {
        this.list = data.records || []
        this.pagination.total = data.total || 0
      }).catch(e => this.$tip.apiFailed(e)).finally(() => { this.loading = false })
    },
    onPageChange (p) {
      this.pagination.pageIndex = p
      this.loadList()
    },
    onSizeChange (s) {
      this.pagination.pageSize = s
      this.pagination.pageIndex = 1
      this.loadList()
    },
    remove (row) {
      this.$dialog.actionConfirm('确认移除该电表关联吗?', '操作确认')
        .then(() => api.deleteElectrical(this.customerId, row.id))
        .then(() => {
          this.$tip.success('已移除')
          this.loadList()
          this.$emit('success')
        })
        .catch(e => { if (e !== 'cancel') this.$tip.apiFailed(e) })
    },
    openSelector () {
      this.selectorVisible = true
      this.selectorKeyword = ''
      this.selectedRows = []
      this.selectorPagination.pageIndex = 1
      this.loadSelectable()
    },
    loadSelectable () {
      this.selectorLoading = true
      api.selectableElectricalPage(this.customerId, {
        page: this.selectorPagination.pageIndex,
        capacity: this.selectorPagination.pageSize,
        model: this.selectorKeyword ? { name: this.selectorKeyword } : {}
      }).then(data => {
        this.selectorList = data.records || []
        this.selectorPagination.total = data.total || 0
      }).catch(e => this.$tip.apiFailed(e)).finally(() => { this.selectorLoading = false })
    },
    searchSelectable () {
      this.selectorPagination.pageIndex = 1
      this.loadSelectable()
    },
    onSelectorPageChange (p) {
      this.selectorPagination.pageIndex = p
      this.loadSelectable()
    },
    onSelectionChange (rows) {
      this.selectedRows = rows
    },
    confirmSelect () {
      if (!this.selectedRows.length) {
        this.$tip.warning('请选择电表')
        return
      }
      api.saveElectrical({
        customerId: this.customerId,
        electricalIds: this.selectedRows.map(r => r.id)
      }).then(() => {
        this.$tip.success('保存成功')
        this.selectorVisible = false
        this.loadList()
        this.$emit('success')
      }).catch(e => this.$tip.apiFailed(e))
    }
  }
}
</script>
 
<style scoped>
.toolbar-row { margin-bottom: 12px; }
.green { color: #67c23a; }
.red { color: #f56c6c; }
</style>