payApproval.vue 9.87 KB
<!-- 付款审批 -->
<template>
  <GLDialog class="gl-form-page gl-form-min payWrap" title="付款审批" mode="mid" :visible.sync="isVisible" :close-on-click-modal="false" :before-close="cancelPay">
    <glsx-combi-form formRef="payChildRef" defaultWidth="284px" ref="payFormRef" :formObj="payForm" :formData="payFormData" :formRules="payRule">
      <template slot="captcha">
        <div class="captcha-wrap">
          <el-input v-model="payForm.captcha" placeholder="请输入"></el-input>
          <div class="captcha-text" @click.prevent="getCode">
            {{ !isCodeDisabled ? '获取验证码' : count + 's' }}
          </div>
        </div>
      </template>
      <template slot="textHtml" slot-scope="scope">
        {{ recordInfo[scope.scope.name] }}
      </template>
    </glsx-combi-form>
    <span slot="footer" class="dialog-footer">
      <el-button plain size="small" class="btn-three" @click="cancelPay">取消</el-button>
      <el-button type="primary" size="small" :loading="loading" @click="comfirmPay">确定</el-button>
    </span>
  </GLDialog>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      isVisible: false,
      count: '',
      timer: null,
      isCodeDisabled: false,
      payForm: {
        paymentChannelId: '',
        paymentSubjectId: '',
        explain: '',
        approverId: '',
        phone: '',
        captcha: '',
        remark: ''
      },
      payFormData: [
        {
          label: '此次付款渠道',
          name: 'paymentChannelId',
          type: 'select',
          optionsName: 'payChannelList',
          optionId: 'id',
          optionLabel: 'channelInfo',
          changeAttr: val => {
            this.payForm.channel = this.baseData.payChannelList.find(item => item.id === val).channel
            this.recordInfo.taxRate = this.baseData.payChannelList.find(item => item.id === val).tax+'%'
            this.getAdmin()
            this.getPaymentEntityList()
            this.calculateAmount()
            this.isCodeDisabled = false
            clearInterval(this.timer)
            this.timer = null
            this.payForm.captcha = ''
          }
        },
        {
          label: '此次付款主体',
          name: 'paymentSubjectId',
          type: 'select',
          optionsName: 'paymentEntityList',
          optionId: 'id',
          optionLabel: 'name',
          changeAttr: val => {}
        },
        {
          label: '批次号',
          name: 'batchNo',
          addHtml: 'textHtml'
        },
        {
          label: '积分总额',
          name: 'pointTotal',
          addHtml: 'textHtml'
        },
        {
          label: '付款总额/元',
          name: 'paymentTotal',
          addHtml: 'textHtml'
        },
        {
          label: '税点',
          name: 'taxRate',
          addHtml: 'textHtml'
        },
        {
          label: '管理员',
          name: 'approverId',
          type: 'select',
          optionsName: 'adminList',
          optionId: 'adminId',
          optionLabel: 'adminName',
          changeAttr: val => {
            this.payForm.phone = val
            this.isCodeDisabled = false
            clearInterval(this.timer)
            this.timer = null
            this.payForm.captcha = ''
          }
        },
        {
          label: '验证码',
          addHtml: 'captcha',
          name: 'captcha'
        },
        {
          label: '发票及其他说明',
          name: 'explain',
          type: 'input',
          inputType: 'textarea',
          maxlength: 200
        },
        {
          label: '备注',
          name: 'remark',
          type: 'input',
          inputType: 'textarea',
          maxlength: 50
        }
      ],
      payRule: {
        approverId: [{ required: true, message: '请选择管理员', trigger: 'change' }],
        paymentChannelId: [{ required: true, message: '请选择付款渠道', trigger: 'change' }],
        paymentSubjectId: [{ required: true, message: '请选择付款主体', trigger: 'change' }],
        captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
        explain: [{ required: true, message: '请输入发票及其他说明', trigger: 'blur' }]
      },
      // 基本数据
      baseData: {
        payChannelList: [],
        //付款主体
        paymentEntityList: []
      }
    }
  },
  props: {
    payVisible: { type: Boolean, default: false },
    recordInfo: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  watch: {
    payVisible(newVal) {
      console.log(newVal)
      this.isVisible = newVal
      if (newVal) {
        this.getChannel()
        this.$utils.getOptionsList(this, 'payFormData', false)
      }
    }
  },
  mounted() {},
  methods: {
    calculateAmount() {
      let {taxRate,pointTotal} =this.recordInfo,
      rate = taxRate.split('%')[0];
      console.log(rate)
      //本批次号积分提现总金额+渠道税点(积分总额×税点),保留小数点后 2位
      this.recordInfo.paymentTotal = (pointTotal+pointTotal*(rate/100)).toFixed(2)
    },
    //积分提现获取业务对应的付款渠道
    getChannel(transferType) {
      let arr = []
      this.$apis.withdraw.getChannelAccount().then(res => {
        if (res) {
          console.log(res)
          arr = res.map(item => {
            let channelInfo = item.channelName + item.name
            return {
              channelInfo,
              ...item
            }
          })
          this.baseData.payChannelList = arr
          this.$utils.getOptionsList(this, 'payFormData', false, 'paymentChannelId')
          //默认选择
          if (this.baseData.payChannelList.length > 0) {
            this.payForm.paymentChannelId = this.baseData.payChannelList[0].id
            this.payForm.channel = this.baseData.payChannelList[0].channel
            this.recordInfo.taxRate = this.baseData.payChannelList[0].tax+'%'
            this.calculateAmount()
          }
          this.getPaymentEntityList()
          this.getAdmin()
        }
      })
    },
    //支付主体
    getPaymentEntityList() {
      let params = { channelAccountId: this.payForm.paymentChannelId }
      this.$apis.withdraw.getPaymentEntityList(params).then(res => {
        if (res) {
          console.log(res)
          this.baseData.paymentEntityList = res
          this.$utils.getOptionsList(this, 'payFormData', false, 'paymentSubjectId')
          // 默认选择
          if (this.baseData.paymentEntityList.length > 0) {
            this.payForm.paymentSubjectId = this.baseData.paymentEntityList[0].id
          }
        }
      })
    },
    getAdmin() {
      this.$apis.withdraw.getAdmin({ channel: this.payForm.channel }).then(res => {
        if (res) {
          this.baseData.adminList = res.map(item => {
            return {
              adminId: `${item.phone}`,
              adminName: `${item.name} ${item.phone}`,
              name: item.name,
              phone: item.phone
            }
          })
          this.$utils.getOptionsList(this, 'payFormData', false, 'approverId')
          this.payForm.approverId = this.baseData.adminList[0].adminId
          this.payForm.phone = this.baseData.adminList[0].phone
        }
      })
    },
    //付款
    comfirmPay() {
      this.$refs.payFormRef.$refs.payChildRef.validate(valid => {
        if (valid) {
          this.loading = true
          let params = {
            phone: this.payForm.phone,
            id: this.recordInfo.id,
            paymentChannelId: this.payForm.paymentChannelId,
            paymentSubjectId: this.payForm.paymentSubjectId,
            captcha: this.payForm.captcha,
            explain: this.payForm.explain,
            remark: this.payForm.remark
          }
          params.approver=this.baseData.adminList.find(item=>item.adminId ==this.payForm.approverId).name
          this.$apis.withdraw
            .applyApprovalOA(params)
            .then(res => {
              this.$message({
                message: res.code == '0' ? '付款审批成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
            })
            .finally(() => {
              this.cancelPay()
              this.loading = false
            })
        }
      })
    },
    cancelPay() {
      this.ids = ''
      this.payForm = {
        paymentChannelId: '',
        paymentSubjectId: '',
        explain: '',
        approverId: '',
        phone: '',
        captcha: '',
        remark: ''
      }
      this.isCodeDisabled = false
      clearInterval(this.timer)
      this.timer = null
      this.$emit('cancelPay')
    },

    getCode() {
      if (this.isCodeDisabled) return
      if (!this.timer) {
        this.count = 60
        // var params = {
        //   phoneType: 'RG',
        //   phone: this.ruleForm.registerPhone
        // }
        this.$apis.withdraw
          .getSms({
            channel: this.payForm.channel,
            phone: this.payForm.phone
          })
          .then(res => {
            if (res.code == 0) {
              this.$message.success('短信验证码发送成功')
              this.isCodeDisabled = true
              this.timer = setInterval(() => {
                if (this.count > 0 && this.count <= 60) {
                  this.count--
                } else {
                  this.isCodeDisabled = false
                  clearInterval(this.timer)
                  this.timer = null
                }
              }, 1000)
            } else {
              this.$message.error(res.message)
            }
          })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.payWrap {
  /deep/ {
    .el-form--inline .el-form-item {
      display: block;
    }
  }
  .captcha-wrap {
    .captcha-text {
      font-size: 12px;
      color: #5850ff;
      position: absolute;
      right: 0;
      top: 2px;
      margin-right: 10px;
      cursor: pointer;
      width: 100px;
      height: 32px;
      text-align: right;
    }
  }
}
</style>