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
<template>
  <div v-loading="loading">
    <div class="info-block">
      <p>客户名称:{{ customer.name }}</p>
      <p>剩余金额(元):{{ leftMoney }}</p>
      <p>余额同步时间:{{ syncDate || '-' }}</p>
      <p v-if="platformInfo">总电量:{{ platformInfo.left_money_y != null ? platformInfo.left_money_y : '-' }}</p>
    </div>
    <el-form label-width="120px" size="small">
      <el-form-item label="充值金额">
        <el-input-number v-model="form.money" :min="0" :precision="2" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="充值备注">
        <el-input v-model="form.remark" maxlength="300" style="width: 400px"/>
      </el-form-item>
    </el-form>
    <div class="footer-btns">
      <el-button type="primary" :loading="isOperating" v-permissions="['business:ywcustomerrecharge:recharge']" @click="confirmRecharge">确认充值</el-button>
      <el-button type="warning" plain :loading="isOperating" v-permissions="['business:ywcustomerrecharge:recharge']" @click="confirmClean">账户清零</el-button>
      <el-button @click="loadInfo">刷新余额</el-button>
    </div>
  </div>
</template>
 
<script>
import * as api from '@/api/business/ywcustomerrecharge'
 
export default {
  name: 'YwCustomerConditionerRechargePanel',
  props: {
    customer: { type: Object, default: () => ({}) }
  },
  data () {
    return {
      loading: false,
      isOperating: false,
      gsConfig: null,
      platformInfo: null,
      form: { money: 0, remark: '' }
    }
  },
  computed: {
    leftMoney () {
      if (this.gsConfig && this.gsConfig.leftMoney != null) return this.gsConfig.leftMoney
      return '-'
    },
    syncDate () {
      return this.gsConfig && this.gsConfig.syncDate
    }
  },
  mounted () {
    this.loadInfo()
  },
  methods: {
    loadInfo () {
      this.loading = true
      api.getConditionerRechargeInfo(this.customer.id)
        .then(res => {
          this.gsConfig = res.gsConfig || null
          this.platformInfo = res.platformInfo || null
        })
        .catch(e => this.$tip.apiFailed(e))
        .finally(() => { this.loading = false })
    },
    confirmRecharge () {
      this.$dialog.actionConfirm('确认充值吗?', '操作确认')
        .then(() => {
          this.isOperating = true
          return api.rechargeConditioner({
            customerId: this.customer.id,
            money: this.form.money,
            remark: this.form.remark
          })
        })
        .then(msg => {
          this.$tip.success(msg || '充值成功')
          this.form.money = 0
          this.loadInfo()
          this.$emit('success')
        })
        .catch(e => { if (e !== 'cancel') this.$tip.apiFailed(e) })
        .finally(() => { this.isOperating = false })
    },
    confirmClean () {
      this.$dialog.actionConfirm('确认清零空调账户吗?', '操作确认')
        .then(() => {
          this.isOperating = true
          return api.cleanConditioner(this.customer.id)
        })
        .then(msg => {
          this.$tip.success(msg || '清零成功')
          this.loadInfo()
          this.$emit('success')
        })
        .catch(e => { if (e !== 'cancel') this.$tip.apiFailed(e) })
        .finally(() => { this.isOperating = false })
    }
  }
}
</script>
 
<style scoped>
.info-block p { margin: 4px 0; line-height: 26px; }
.footer-btns { text-align: right; margin-top: 16px; }
.footer-btns .el-button { margin-left: 8px; }
</style>