strategicAddModal.vue 11.2 KB
<template>
  <a-modal :title="title" :width="800" :visible="visible" :maskClosable="false" :confirmLoading="confirmLoading"
    okText="下一步" @ok="handleNextStep" @cancel="handleCancel" cancelText="取消" style="top:20px;">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="审批流程编号" :labelCol="labelCol" :wrapperCol="wrapperCol"
          v-show="model.strategyNo ? true : false">
          <a-input placeholder="请输入审批流程编号" v-decorator="['strategyNo', { 'initialValue': model ? model.strategyNo : '' }]"
            :disabled="model.strategyNo ? true : false" />
        </a-form-item>
        <a-form-item label="审批流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input placeholder="请输入审批流程名称" :maxLength="16"
            v-decorator="['strategyName', validatorRules.strategyName]" />
        </a-form-item>
        <a-form-item label="审批流程类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select placeholder="请选择审批流程类型" v-decorator="['strategyType', validatorRules.strategyType]"
            @change="handleSelectChange">
            <a-select-option :value="1">进件审批</a-select-option>
            <a-select-option :value="2">用信审批</a-select-option>
          </a-select>
        </a-form-item>
        <!-- <a-form-item label="进件/用信流名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select 
            placeholder="请选择进件/用信流名称"
            v-decorator="['processName', validatorRules.processName]" 
            @change="handleSelectChangeProcessName"
            >
            <a-select-option v-for="(item,index) in copyProcessList" :key="index" :value="item.code">{{item.value}}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="进件/用信流编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input placeholder="请输入进件/用信流编号" v-decorator="['processNo', validatorRules.processNo]" :disabled="true"/>
        </a-form-item> -->
        <a-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select placeholder="请选择产品" v-decorator="['productNo', validatorRules.productNo]"  ref="cpbh" @change="chanpin">
            <a-select-option v-for="(item, index) in cpOption" :key="index" :value="item.productNo">{{ item.productName }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="产品编号" :labelCol="labelCol" :wrapperCol="wrapperCol" style="display: none;">
          <a-input placeholder="请输入产品编号" v-decorator="['productName', validatorRules.productName]" :disabled="true"/>
        </a-form-item>
        <a-form-item label="资金方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select placeholder="请选择资金方" v-decorator="['fundNo']">
            <a-select-option v-for="(item, index) in zjOption" :key="index" :value="item.fundNo">{{ item.fundName }}
            </a-select-option>
            <!-- <a-select-option :value="2">拍拍贷</a-select-option> -->
          </a-select>
        </a-form-item>
        <!-- <a-form-item :label-col="labelCol" :wrapper-col="wrapperCol" label="风控授信区间">
          <a-input-number :min="0" :max="999999999" v-decorator="['minAmount']" @change="handleNumberChangeMin" />
          <label style="margin:0 10px;">—</label>
          <a-input-number :min="0" :max="999999999" v-decorator="['maxAmount']" @change="handleNumberChangeMax" />
        </a-form-item> -->
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="备注">
          <a-textarea :rows="4" placeholder="最多输入60字" :maxLength="60" v-decorator="['strategyNote']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
<script>
import Vue from 'vue'
import store from '@/store'
import pick from 'lodash.pick'
import { postAction } from '@/api/configApi'
import { saveApprovalStrategyConfig, modifyApprovalStrategyConfig } from '@/api/insys'
export default {
  name: "strategicAddModel",
  data() {
    return {
      cpOption: [],
      zjOption:[],
      form: this.$form.createForm(this),
      visible: false,
      confirmLoading: false,
      confirmDirty: false,
      disableSubmit: false,
      validatorRules: {
        strategyName: {
          rules: [{
            required: true,
            message: '请输入审批流程名称'
          }]
        },
        strategyType: {
          rules: [{
            required: true,
            message: '请选择审批流程类型'
          }]
        },
        processName: {
          rules: [{
            required: true,
            message: '请选择进件/用信流名称'
          }]
        },
        processNo: {
          rules: [{
            required: true,
            message: '请输入进件/用信流编号'
          }]
        },
      },
      tips: '',
      model: {},

      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      copyProcessList: [],
      dbFund: JSON.parse(sessionStorage.getItem('FUND_APPROVAL')),
      title: '',
    }
  },
  created() {
    this.cpInitPrudect()
    this.zjInitPrudect()
  },
  methods: {
    cpInitPrudect() {
      let _params = {
        pageNo: 1,
        pageSize: 10000,
        params: {}
      }
      postAction('/config/admin/queryProductList', _params).then(r => {
        this.cpOption = r.result.records.filter(item => item.status ==1)
        //console.log(this.cpOption)
       // alert("1111")
      })
    },
    zjInitPrudect() {
      let _params = {
        pageNo: 1,
        pageSize: 10000,
        params: {}
      }
      postAction('/config/admin/queryFundList', _params).then(r => {
        this.zjOption = r.result.records.filter(item => item.status ==1)
        //console.log(this.zjOption)
       // alert("1111")
      })
    },
    chanpin(value){
      let obj = this.cpOption.find(o => o.productNo === value);
      console.log(obj.productName)
      this.form.setFieldsValue({
        productName: obj.productName,
      });
      // this.form.setFieldsValue({
      //   productNo: value,
      // });
      
    },
    handleSelectChange(value) {
      // if(value == 1){
      //     this.copyProcessList = Vue.ls.get('SET_PROCESSLIST').length <=0 ? [] : Vue.ls.get('SET_PROCESSLIST')
      // }else{
      //     this.copyProcessList = Vue.ls.get('SET_COLLECTPROCESSLIST').length <=0 ? [] : Vue.ls.get('SET_COLLECTPROCESSLIST')

      // }
      // if(this.copyProcessList.length<=0){
      //   this.form.setFieldsValue({
      //     processName:'',
      //     processNo: '',
      //   });
      // }
    },
    handleSelectChangeProcessName(value) {
      this.form.setFieldsValue({
        processNo: value,
      });
    },
    show(record) {
      this.title = '查看'
      this.form.resetFields();
      this.visible = true;
      this.model = record;
      this.model.show = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(record, 'strategyNo', 'strategyName', 'productNo', 'productName', 'strategyType', 'processName', 'processNo', 'fundNo', 'minAmount', 'maxAmount', 'strategyNote'));
      });
    },
    edit(record) {
      this.title = '编辑'
      this.model = record;
      this.form.resetFields();
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(record, 'strategyNo', 'strategyName', 'productName', 'productNo', 'strategyType', 'processName', 'processNo', 'fundNo', 'minAmount', 'maxAmount', 'strategyNote'));
        this.handleSelectChange(record.strategyType)
      });
    },
    add() {
      this.title = '新增'
      this.model = {};
      this.form.resetFields();
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue();
      });
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.disableSubmit = false;
      this.selectedRole = [];
    },
    handleNumberChangeMin(value) {
      this.model.minAmount = value
    },
    handleNumberChangeMax(value) {
      this.model.maxAmount = value
    },
    handleNextStep() {
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          let promiseFn, formData
          //查看逻辑处理
          if (!!this.model.show) {
            this.$router.push({
              path: "/core/strategicModel/activiti",
              query: {
                modelId: this.model.modelId,
                disabled: true
              }
            });
            return false
          }
          console.log("chufalema")
          //金额区间判断
          if (((values.minAmount == null || values.minAmount == undefined) && (values.maxAmount != null || values.maxAmount != undefined)) || ((values.minAmount != null || values.minAmount != undefined) && (values.maxAmount == null || values.maxAmount == undefined))) {
            this.$message.error('请输入完整的金额区间');
            return false
          }
          // if((values.minAmount != null || values.minAmount != undefined) && (values.maxAmount != null || values.maxAmount != undefined)){
          // }
          // else if((values.minAmount === null || values.minAmount === undefined ) && (values.maxAmount === null || values.maxAmount === undefined )){
          // }
          // else{
          //   this.$message.error('请输入完整的金额区间');
          //   return false
          // }
          console.log("chufalema2")
          this.confirmLoading = true;
          console.log()
          //code value 转换
          // let list = values.strategyType == '1' ? Vue.ls.get('SET_PROCESSLIST') : Vue.ls.get('SET_COLLECTPROCESSLIST')
          // for(var i=0 ;i<list.length; i++){
          //     if( values.processName == list[i].code){
          //         values.processName = list[i].value
          //     }
          // }
          console.log("chufalema3")
          if (!!this.model.id) { //编辑
            formData = Object.assign({ modelId: this.model.modelId, id: this.model.id }, values);
            promiseFn = modifyApprovalStrategyConfig(formData);
          } else {
            formData = Object.assign(values);
            promiseFn = saveApprovalStrategyConfig(formData)
          }
          console.log("chufalema4")
          promiseFn.then((res) => {
            console.log("you")
            if (res.status.statusCode == 0) {

              this.$message.success(res.status.statusReason);
              this.$emit('ok');
              this.$router.push({
                path: "/core/strategicModel/activiti",
                query: {
                  modelId: res.result.modelId,
                }
              });
              this.confirmLoading = false;
              this.close();
            } else {
              this.$message.warning(res.status.statusReason);
            }
          }).finally(() => {
            this.confirmLoading = false;
            this.close();
          });
        }
      })
    },
    handleCancel() {
      this.close()
    },
    handleConfirmBlur(e) {
      const value = e.target.value
      this.confirmDirty = this.confirmDirty || !!value
    }
  }
}
</script>