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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<template>
  <div class="apply-info">
    <div class="dialog-form">
      <p class="dialog-form-title">
        {{ addOrEdit === 'add' ? '新增' : '修改' }}
      </p>
      <div v-loading="loading">
        <CommForm
          ref="editMarkForm"
          :column="2"
          :inline="true"
          :list="formList"
          :formValues="formValues"
          :formRules="formRules"
          @updateValue="updateValue"
        ></CommForm>
      </div>
      <div class="dialog-form-buttons">
        <p>
          <el-button class="comm-button" @click="$emit('close')"
            >关闭</el-button
          >
        </p>
        <p>
          <el-button
            class="comm-button"
            type="primary"
            @click="submit"
            :disabled="loading"
            >确定</el-button
          >
        </p>
      </div>
    </div>
  </div>
</template>
<script>
// 特殊减免配置
import CommForm from '@/components/CommForm'
import saveLoanOrgProduct from '@/controller/saveLoanOrgProduct' // 新增、编辑
import queryCodeValueList from '@/controller/queryCodeValueList'
import qryDimensionList from '@/controller/qryDimensionList'
import qryDropDownOptionBatch from '@/controller/qryDropDownOptionBatch'
import queryLoanOrgItem from '@/controller/queryLoanOrgItem'
import qryOrgProduct from '@/controller/qryOrgProduct'
import getDictionaryList from '@/controller/getDictionaryList'
 
// 获取产品api
import qryProdList from '@/controller/qryProdList'
// 获取还款方式api
import queryPaymentMethod from '@/controller/queryPaymentMethod'
export default {
  components: {
    CommForm,
  },
  props: {
    info: {
      type: Object,
      default: () => ({}),
    },
    isShow: {
      type: Boolean,
      default: false,
    },
    trxnBr: {
      type: String,
      default: '',
    },
    buttonProp: {
      type: String,
      default: '',
    },
    // 初始值
    initValue: {
      type: Object,
      default: () => ({}),
    },
    addOrEdit: {
      type: String,
      default: '',
    },
    detail: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      model: null,
      formList: [],
      loading: false,
      paymentMethodName: '',
      orgProductName: '',
      itemName: {},
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.$refs['editMarkForm'] && this.$refs['editMarkForm'].resetFields()
      const { detail, addOrEdit } = this
      const guaranteeFeeClearingType = !detail.guaranteeFeeClearingType.length ? [] : detail.guaranteeFeeClearingType.split(",")
      const model = saveLoanOrgProduct()
      this.model = model
      this.formList = model.getFormList({
        ...detail,
        guaranteeFeeClearingType
      })
      // .filter(item => {
      //   if(addOrEdit === 'add') {
      //     // 新增-客户名称无须编辑
      //     return item.name !== 'customername'
      //   }
      //   return 1
      // })
      this.setSelectOptions()
    },
 
    setSelectOptions() {
      const { formList } = this
      formList.forEach(({ name }) => {
        // 项目
        if (name === 'projectCode') {
          this.qryDropDownOptionBatch(name, 'projectList')
        }
        // 产品
        if (name === 'productCode') {
          this.qryProdList(name)
        }
        // 资金方
        if (name === 'orgId') {
          this.queryLoanOrgItem(name)
        }
        // 维度名称
        if (name === 'productDimensionCode') {
          this.qryDimensionList()
        }
        // 还款方式
        if (name === 'paymentMethodCode') {
          this.qryDropDownOptionBatch(name, 'PaymentName')
        }
        // 资方还款方式
        if (name === 'orgPaymentMethodCode') {
          this.getDictionaryList(name, 'OrgLoanProductRepay')
        }
        // 清分
        if (name === 'useClearing') {
          this.getDictionaryList(name, 'YesNo')
        }
        // 融担清分费用类型
        if (name === 'guaranteeFeeClearingType') {
          this.getDictionaryList(name, 'GUARANTEE_FEE_CLEARING_TYPE')
        }
        // 资方产品配置期数
        if (name === 'period') {
          this.getDictionaryList(name, 'OrgLoanProductTerm')
        }
        // 资金产品
        if (name === 'orgProductCode') {
          this.qryOrgProduct()
        }
        // 状态
        if (name === 'status') {
          this.queryCodeValueList(name, { codeNo: 'YesNo' })
        }
      })
    },
 
    async queryCodeValueList(name, info = {}) {
      const tempModel = queryCodeValueList()
      const { list } = await tempModel.request(info)
      if(name == 'status' && list) {
        list.map(item => {
          item.label = item.value == '1' ? '有效' : '无效'
        })
      }
      this.updateValue(name, { options: list })
    },
    // 产品名称下拉列表
    async qryProdList(name) {
      const tempModel = qryProdList()
      const { list } = await tempModel.request({ productTypeNo: '' })
      this.updateValue(name, { options: list })
    },
    // 下拉选项枚举
    async qryDropDownOptionBatch(name, code) {
      const tempModel = qryDropDownOptionBatch()
      const res = await tempModel.request([code])
      let list = res[code]
      this.updateValue(name, { options: list })
    },
    // 下拉选项枚举
    async getDictionaryList(name, code) {
      const tempModel = getDictionaryList()
      const res = await tempModel.request({codeNo: code})
      let list = res.list
      this.updateValue(name, { options: list })
    },
    // 资金方下拉列表
    async queryLoanOrgItem(name, info = {}) {
      const tempModel = queryLoanOrgItem()
      const { list } = await tempModel.request(info)
      this.updateValue(name, { options: list })
    },
    // 资方产品下拉列表
    async qryOrgProduct() {
      let { formValues } = this
      const res = await qryOrgProduct().request({
        orgid: formValues.orgId || '',
      })
      const { list } = res
      this.updateValue('orgProductCode', { options: list })
    },
    // 产品维度下拉列表
    async qryDimensionList() {
      let { formValues } = this
      const res = await qryDimensionList().request({
        productid: formValues.productCode || '',
      })
      const { list } = res
      this.updateValue('productDimensionCode', { options: list })
    },
    // 还款方式下拉列表
    async queryMethodList(name) {
      const tempModel = queryPaymentMethod()
      const { list } = await tempModel.request({ paymentMethod: '' })
      this.updateValue(name, { options: list })
    },
 
    // 更新表单数据
    updateValue(index, info) {
      const { formList, addOrEdit } = this
      if (isNaN(index)) {
        // index is name
        index = formList.findIndex(({ name }) => name === index)
      }
      if (!isNaN(index) && index > -1) {
        const preInfo = formList[index]
        this.$set(formList, index, { ...preInfo, ...info })
        if (preInfo.type == 'select') {
          const { options } = info
          const referValue = info.value ? info.value : preInfo.value
          const checkedOption = options.find(                                          
            (item) => item.value === referValue
          )
          
          // 设置级联下拉选项
          const linkageOptionsSet = {
            productCode: 'productDimensionCode',  // 产品维度跟产品是级联关系 先选择产品 然后带出维度
            orgId: 'orgProductCode',  // 资方产品跟资金方是级联关系 先选择资金方 然后带出资方产品选项
          }
          if (preInfo.name in linkageOptionsSet) {
            const findIdx = formList.findIndex(
              ({ name }) => name === linkageOptionsSet[preInfo.name]
            )
            const value = preInfo.value !== info.value && !info.value ? formList[findIdx].value : preInfo.value === info.value ? formList[findIdx].value : ''
            this.$set(formList, findIdx, {
              ...formList[findIdx],
              value: value
            })
            preInfo.name === 'productCode' && this.qryDimensionList()
            preInfo.name === 'orgId' && this.qryOrgProduct()
          }
 
          // 关联字段,不可手动编辑
          const codeToNames = {
            paymentMethodCode: 'paymentMethodName',  // 还款方式名称
            orgProductCode: 'orgProductName',  // 资方产品名称
          }
          if (preInfo.name in codeToNames) {
            const findIdx = formList.findIndex(
              ({ name }) => name === codeToNames[preInfo.name]
            )
            this.$set(formList, findIdx, {
              ...formList[findIdx],
              value: !checkedOption ? '' : checkedOption.value,
            })
          }
          if(preInfo.name === 'useClearing') {
            const findIdx = formList.findIndex(
              ({ name }) => name === 'guaranteeFeeClearingType'
            )
            this.$set(formList[findIdx].rules[0], 'required', formList[index].value === '1')
          }
 
          // 后端要求将相关字段中文映射提交
          const nameSet = {
            orgId: 'orgName',
            projectCode: 'projectName',
            productCode: 'productName',
            orgProductCode: 'orgProductName',
            productDimensionCode: 'productDimensionName',
            paymentMethodCode: 'paymentMethodName',
            orgPaymentMethodCode: 'orgPaymentMethodName',
          }
          if (preInfo.name in nameSet) {
            this.itemName[nameSet[preInfo.name]] = !checkedOption ? '' : checkedOption.label
          }
        }
      }
    },
    // 表单按钮事件处理
    async submit() {
      const { model, detail, itemName } = this
      const { id = '' } = detail
      const values = this.$refs.editMarkForm.validate()
      if (values) {
        this.loading = true
        try {
          const guaranteeFeeClearingType = values.guaranteeFeeClearingType.toString()
          await model.request({
            ...values,
            ...itemName,
            id,
            guaranteeFeeClearingType
          })
          this.loading = false
          this.$emit('callback')
        } catch (error) {
          this.loading = false
        }
      } else {
        this.$message.warning('当前页面必填数据未填写完毕或填写数据格式错误!')
      }
    },
    resetForm() {
      const { model } = this
      this.formList = model.getFormList()
    },
  },
  computed: {
    // 表单值信息
    formValues() {
      const { model, formList } = this
      if (model) {
        return model.getFormValues(formList)
      }
      return {}
    },
    formRules() {
      const { model, formList } = this
      if (model) {
        const rules = model.getFormRules(formList);
        rules.guaranteeFeeClearingType[0] = {...rules.guaranteeFeeClearingType[0], type:'array',}
        return rules
      }
      return {}
    },
  },
  watch: {
    isShow() {
      const { isShow } = this
      if (isShow) {
        this.init()
      }
    },
  },
}
</script>
<style lang="postcss" scoped>
.dialog-form {
  & .dialog-form-buttons {
    display: flex;
    justify-content: center;
    padding: 50px 0 10px 0;
    & p {
      margin: 0 40px 0 0;
    }
    & p:last-child {
      margin-right: 0;
    }
  }
  & .dialog-upload {
    display: flex;
    align-content: center;
    margin-left: 100px;
    & .el-button {
      color: #0081f0;
      border-color: #0081f0;
    }
    & .upload {
      color: #0081f0;
      font-size: 12px;
      margin-left: 20px;
      cursor: pointer;
      line-height: 28px;
    }
  }
}
</style>