doum
4 天以前 3c7399c25c0f35c8aa7cb6af1935e31d1a3f0102
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
<template>
  <div v-loading="loading">
    <el-form label-width="120px" size="small">
      <el-form-item label="选择电表">
        <el-select v-model="electricalId" placeholder="请选择电表" filterable style="width: 360px" @change="loadRemoteInfo">
          <el-option v-for="item in electricalList" :key="item.id" :label="item.name + ' (' + item.address + ')'" :value="item.id"/>
        </el-select>
      </el-form-item>
    </el-form>
    <account-recharge-panel
      v-if="electricalId"
      :info="info"
      :latest="latest"
      :form="form"
      :is-operating="isOperating"
      :purchase-count="purchaseCount"
      mode="recharge"
      @read="readMeter"
      @confirm="confirmRecharge"
    />
  <!--  <div v-if="electricalId" class="extra-btns">
      <el-button type="warning" plain :loading="isOperating" v-permissions="['business:ywcustomerrecharge:recharge']" @click="resetAccount('resetPrepay')">清零(预付费)</el-button>
      <el-button type="warning" plain :loading="isOperating" v-permissions="['business:ywcustomerrecharge:recharge']" @click="resetAccount('resetPostpay')">清零(后付费)</el-button>
    </div>
    -->
    <div v-if="!electricalList.length && !loading" class="empty-tip">该商户尚未关联电表,请先在关联设备中添加</div>
  </div>
</template>
 
<script>
import AccountRechargePanel from './AccountRechargePanel'
import * as api from '@/api/business/ywcustomerrecharge'
 
export default {
  name: 'YwCustomerElectricalRechargePanel',
  components: { AccountRechargePanel },
  props: {
    customer: { type: Object, default: () => ({}) }
  },
  data () {
    return {
      loading: false,
      electricalList: [],
      electricalId: null,
      info: {},
      latest: null,
      purchaseCount: '0',
      form: { money: 0, remark: '' },
      isOperating: false
    }
  },
  mounted () {
    this.loadElectricalList()
  },
  methods: {
    loadElectricalList () {
      this.loading = true
      api.electricalPage(this.customer.id, { page: 1, capacity: 500, model: {} })
        .then(data => {
          this.electricalList = data.records || []
          if (this.electricalList.length) {
            this.electricalId = this.electricalList[0].id
            this.loadRemoteInfo()
          }
        })
        .catch(e => this.$tip.apiFailed(e))
        .finally(() => { this.loading = false })
    },
    loadRemoteInfo () {
      if (!this.electricalId) return
      api.getElectricalRemoteInfo(this.electricalId).then(res => {
        this.info = res.electrical || {}
        this.latest = res.latestData
        this.purchaseCount = res.purchaseCount || '0'
      }).catch(e => this.$tip.apiFailed(e))
    },
    readMeter () {
      if (!this.electricalId) return
      this.isOperating = true
      api.readMeter(this.customer.id, this.electricalId)
        .then(res => {
          this.info = res.electrical || this.info
          this.latest = res.latestData
          this.$tip.success(res.message || '抄表完成')
        })
        .catch(e => this.$tip.apiFailed(e))
        .finally(() => { this.isOperating = false })
    },
    confirmRecharge () {
      this.$dialog.actionConfirm('确认充值吗?', '操作确认')
        .then(() => {
          this.isOperating = true
          return api.rechargeElectrical({
            customerId: this.customer.id,
            electricalId: this.electricalId,
            money: this.form.money,
            remark: this.form.remark
          })
        })
        .then(msg => {
          this.$tip.success(msg || '提交成功,请在充值记录中查看结果')
          this.loadRemoteInfo()
          this.$emit('success')
        })
        .catch(e => { if (e !== 'cancel') this.$tip.apiFailed(e) })
        .finally(() => { this.isOperating = false })
    },
    resetAccount (resetAction) {
      const label = resetAction === 'resetPrepay' ? '预付费' : '后付费'
      this.$dialog.actionConfirm('确认清零并切换到' + label + '模式吗?', '操作确认')
        .then(() => {
          this.isOperating = true
          return api.resetElectrical({
            customerId: this.customer.id,
            electricalId: this.electricalId,
            resetAction
          })
        })
        .then(msg => {
          this.$tip.success(msg || '提交成功')
          this.loadRemoteInfo()
          this.$emit('success')
        })
        .catch(e => { if (e !== 'cancel') this.$tip.apiFailed(e) })
        .finally(() => { this.isOperating = false })
    }
  }
}
</script>
 
<style scoped>
.extra-btns { margin-top: 12px; }
.empty-tip { padding: 24px; color: #909399; text-align: center; }
</style>