zhaoxiaoqiang1
2026-01-04 f1d30d03186c79ca2cbcfe60d6d2ce7d73fba97b
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<template>
  <div class="apply-info">
    <SectionTitle title="扣款信息"></SectionTitle>
    <p class="reminder">温馨提示:修改扣款信息成功之后,务必要求客户通过公众号做协议签约验证</p>
    <CommTable
      :isAutoIndex="true"
      :list="list"
      :header="tableHeader"
      :pageInfo="pageInfo"
      :total="total"
      @doAction="doAction"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @updateValue="updateValue"
      ref="deductionTable"
    ></CommTable>
    <Dialog
      v-model="isShowSucc"
      icon="succ"
      iconText="保存成功"
      :close="false"
      :buttons="[{text: '确定', type: 'primary'}]"
      @handleClick="sureSucc"
    ></Dialog>
 
  </div>
</template>
<script>
// 客户还款管理-扣款信息列表查询
import { mapActions } from 'vuex'
import CommTable from '@/components/CommTable'
import SectionTitle from '@/components/SectionTitle'
import Dialog from '@/components/Dialog'
import queryCustomerAccountInfoList from '@/controller/queryCustomerAccountInfoList'
// import addZhBankMessage from '@/controller/addZhBankMessage'
import customerAccountInfoModify from '@/controller/customerAccountInfoModify'
// import modifyZhBankMessage from '@/controller/modifyZhBankMessage'
// import delZhBankMessage from '@/controller/delZhBankMessage'
 
const normalButtons = [
  { text: '修改', prop: 'updateButton' },
]
 
const editButtons = [
  { text: '保存', prop: 'submitButton' },
  { text: '取消', prop: 'cancleButton' }
]
 
export default {
  components: {
    CommTable,
    SectionTitle,
    Dialog
  },
  props: {
    conf: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      tableHeader: [],
      model: null,
      modifyModel: null,
      updateModel: null,
      delModel: null,
      currentIndex: 0,
      isShowSucc: false,
      isDoingAdd: false,
      pageInfo: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      list: [],
      tempList: []
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      const { isEdit } = this
      const { query } = this.$route
      this.query = query
      const model = queryCustomerAccountInfoList()
      const tabList = model.getTableList()
      this.tableHeader = isEdit
        ? tabList
        : tabList.filter(({ type }) => type !== 'buttons')
      this.model = model
      this.modifyModel = customerAccountInfoModify()
      this.getList()
    },
    async getList() {
      const { model, query, pageInfo } = this
      const { customerId = '' } = query
      const { list = [], total } = await model.request({
        ...pageInfo,
        customerId
      })
 
      this.list = list.map(item => ({
        ...item,
        action: {
          buttons: normalButtons
        }
      }))
      this.tempList = []
      this.total = parseInt(total)
    },
 
    // 修改翻页条数
    handleSizeChange(val) {
      this.pageInfo.pageSize = val
      this.getList()
    },
 
    // 修改翻页数
    handleCurrentChange(val) {
      this.pageInfo.currentPage = val
      this.getList()
    },
 
    sureSucc() {
      this.isShowSucc = false
      this.isDoingAdd = false
      this.resetList()
    },
 
    resetList() {
      this.pageInfo.currentPage = 1
      this.getList()
    },
 
    // 表格按钮事件处理
    doAction(item, record, index) {
      const { prop } = item
      this.currentIndex = index
      if (prop === 'updateButton') {
        this.updateRecord()
      }
 
      if (prop === 'cancleButton') {
        this.cancle()
      }
 
      if (prop === 'submitButton') {
        this.toSubmit()
      }
    },
 
    // 取消
    cancle() {
      const { currentIndex, tempList, list } = this
      const temp = list[currentIndex] || {}
      if (temp.baSerialNo) {
        const tempIndex = tempList.findIndex(
          ({ baSerialNo }) => baSerialNo === temp.baSerialNo
        )
        this.$set(list, currentIndex, tempList[tempIndex])
        this.tempList = tempList.filter((item, i) => i !== tempIndex)
      } else {
        this.list = list.filter((item, index) => index > 0)
        this.tempList = tempList.filter((item, index) => index > 0)
        this.isDoingAdd = false
      }
    },
 
    async toSubmit(isAdd = false) {
      const {
        list,
        currentIndex,
        query,
        modifyModel,
      } = this
      const { customerId } = query
      const curr = list[currentIndex]
      const [err, values] = this.$refs.deductionTable.validate(curr)
      const tempModel = modifyModel 
      const currItem = { ...curr, ...values }
      // const { serialNo = '', corebalance = 0 } = currItem
      if (err) {
        this.$message.warning(err)
      } else {
        await tempModel.request({
          customerId,
          ...currItem
        })
        this.updatePaymentInfo()
        this.isShowSucc = true
      }
    },
 
    // 修改
    updateRecord() {
      const { list, currentIndex } = this
      const item = list[currentIndex]  // 当前行的信息
      this.setTempList({ ...item })
      // console.log()
      this.$set(list, currentIndex, this.getEditRecord(list[currentIndex]))
    },
 
    // 新增
    addRecord() {
      const { isDoingAdd, list } = this
      if (isDoingAdd) {
        return false
      }
      const editRecord = this.getEditRecord()
      this.list = [editRecord, ...list]
      this.currentIndex = 0
 
      this.setTempList()
      this.isDoingAdd = true
    },
 
    setTempList(item = {}) {
      const { tempList } = this
      this.tempList = [item, ...tempList]
    },
 
    updateValue(val, inputItem, parentName, recordIndex = 0) {
      const { list } = this
      const { name } = inputItem
      const listItem = list[recordIndex]
      const key = Object.keys(listItem).find(k => k === name)
      this.$set(list, recordIndex, {
        ...listItem,
        [key]: { ...listItem[key], value: val }
      })
    },
 
    updatePaymentInfo() {
      const { query } = this
      const { serialNo, customerId } = query
      this.paymentZhTermInitData({
        customerId,
        loanSerialNo: serialNo
      })
    },
 
    /**
     * info 初始值
     */
    getEditRecord(info = {}) {
      const { tableHeader, modifyModel } = this
      const formList = modifyModel.getFormList(info)
      return tableHeader.reduce(
        (pre, { prop, isMoney = false }) => {
          if (prop === 'action') {
            pre[prop] = {
              // buttons: Object.keys(info).length > 0 ? editButtons : addButtons
              buttons: editButtons
            }
          } else {
            const inputItem = formList.find(({ name }) => name === prop)
            if (inputItem) {
              pre[prop] = inputItem
            }
          }
          return pre
        },
        { ...info }
      )
    },
    ...mapActions(['paymentZhTermInitData'])
  },
  computed: {
    isEdit() {
      const { conf } = this
      return conf.edit === 'Y'
    }
  },
  watch: {
    $route() {
      const { serialNo } = this.$route.query
      if (serialNo) {
        this.init()
      }
    }
  }
}
</script>
<style lang="postcss" scoped>
.middle-button {
  margin-bottom: 20px;
}
.del-id {
  text-align: center;
  margin: 0 0 20px 0;
  padding: 0;
}
.reminder {
  font-size: 14px;
  color: red;
}
</style>