<!--
  @description: 异常缴费处理-新增
  @Modifier: haofengxian
  @routerPath:
  @date: 2021-3-11-14:03
-->
<template>
  <div>
    <el-form
      ref="formData"
      label-position="left"
      :model="formData"
      :rules="rules"
      :inline-message="true"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="异常虚拟订单号" />
          </td>
          <td>{{ formData.excepFictOrderCode }}</td>
          <td>
            <el-form-item label="供应商名称" prop="supplierName" />
          </td>
          <td>{{ formData.supplierName }}</td>
        </tr>
        <tr>
          <td>
            <el-form-item label="入账银行账号" prop="bankno" />
          </td>
          <td>{{ formData.bankno }}</td>
          <td>
            <el-form-item label="入账时间" prop="entryTime" />
          </td>
          <td>{{ formData.entryTime }}</td>
        </tr>
        <tr>
          <td>
            <el-form-item label="需处理异常金额(元)" prop="excepHandMoney" />
          </td>
          <td colspan="3">
            {{ numFilter(formData.excepHandMoney) }}
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="异常原因" prop="excepRemarks" />
          </td>
          <td colspan="3">
            <gx-input
              v-model.trim="formData.excepRemarks"
              :autosize="{ minRows: 3, maxRows: 3 }"
              type="textarea"
              gx-maxlength="varchar200"
            />
          </td>
        </tr>
        <tr>
          <td>说明文件</td>
          <td colspan="3">
            <upload
              ref="upload"
              :data="upLoadData"
              :auto-delete="true"
              :auto-upload="true"
              title=""
              file-ref="fileRef"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <!--保存按钮-->
    <div v-if="flowStatus" class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button type="primary" :loading="confirmLoading" @click="submitFormData">
          提 交
        </el-button>
      </div>
    </div>
    <!--工作流选择节点组件-->
    <processNode-com
      ref="processNode"
      :process-definition-key="processDefinitionKey"
      @processNodeData="processNodeData"
    />
    <!--工作流流程节点/获取审核用户-->
    <depart-dialog
      ref="departDialog"
      :process-node="processNode"
      @isSingleUser="isSingleUser"
      @processInitData="processInitData"
      @submit="submitAbnormalPay"
    />
  </div>
</template>

<script>
/* api*/
import { excepPayeeHandSubmit, excepPayeeHandDetailsInfo } from '@/api/procurement/procurementOrder'
/* 公共方法*/
import { characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* 组件*/
import upload from '@comp/common/updownload/upload'// 文件上传组件
/* ==========工作流===========*/
import { workCommonMixins } from '@views/work/mixins/workCommonMixins' // 工作流公共配置
import workconstant from '@/assets/js/workutils/workconstant/purOrder' // 配置流程key
import processNodeCom from '@views/work/processNodeCom' // 工作流选择节点组件
import departDialog from '@views/work/depart-dialog' // 选择审核人员
/* ============================*/
import { orderServeFeeMixins } from '../../mixins/orderServeFeeMixins'
export default {
  name: 'ServiceOrderAbnormalPayProcessingDialog',
  components: {
    upload, // 金额
    processNodeCom,
    departDialog
  },
  mixins: [workCommonMixins, orderServeFeeMixins],
  props: {
    orderReceiptInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      flowStatus: this.$route.query.flowStatus, // true 工作流进入驳回编辑
      confirmLoading: false, // 控制按钮重复点击Loding
      processDefinitionKey: '', // 工作流流程key
      voucherAuditConfig: false, // 是否启动工作流配置
      visibleDialog: false,
      formData: {
        excepFictOrderCode: 'O99999999999',
        recordId: '', // 异常费用ID
        excepRemarks: '', // 备注
        supplierId: '', // 供应商ID
        supplierName: '', // 供应商名称
        excepHandMoney: 0 // 需处理异常金额
      },
      upLoadData: {
        bizId: '',
        fileType: 'excep_pay_handle'
      },
      // 校验输入内容
      rules: {
        excepRemarks: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 异常原因
      }
    }
  },
  created() {
    this.processDefinitionKey = workconstant.receiptModelCreateException // 工作流流程key
    this.getSystemConfig() // 获取配置是否启动工作流
  },
  mounted() {
    // 工作流进入编辑获取详情
    if (this.flowStatus) {
      const id = this.$route.query.packId
      this.getExcepPayeeHandDetailsInfo(id)
    } else {
      this.initData()
    }
  },
  methods: {
    // 异常缴费处理记录详情
    getExcepPayeeHandDetailsInfo(id) {
      excepPayeeHandDetailsInfo(id).then(res => {
        this.formData = res.data
      }).catch(() => {
      })
    },
    // 根据键获取配置 是否工作流审核
    getSystemConfig() {
      this.$store.dispatch('getSystemConfigValue', 'voucher-audit-config').then(() => {
        this.voucherAuditConfig = this.$store.getters.systemConfigVo.configType
      }).catch(() => {
      })
    },
    // 初始化供应商信息
    initData() {
      this.formData.supplierId = this.orderReceiptInfo.supplierId // 供应商ID
      this.formData.supplierName = this.orderReceiptInfo.supplierName // 供应商名称
      this.formData.bankno = this.orderReceiptInfo.bankno// 账号（入账账号）
      this.formData.entryTime = this.orderReceiptInfo.payTime // 创建时间（入账时间）
      this.formData.excepHandMoney = this.orderReceiptInfo.surplusMoney // 剩余费用额度
      this.formData.recordId = this.orderReceiptInfo.id // 异常费用id
    },
    // 提交按钮
    submitFormData() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          // 是否启动工作流
          if (this.voucherAuditConfig) {
            if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
              this.$refs.departDialog.getUserDepart(this.processNode)
            }
          } else {
            this.submitAbnormalPay()
          }
        } else {
          this.$message({
            type: 'warning',
            message: '注意页面提示信息'
          })
        }
      })
    },
    // 提交异常缴费处理
    submitAbnormalPay() {
      this.confirmLoading = true
      // 启动工作流添加工作流参数
      if (this.voucherAuditConfig) {
        this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
        this.formData.processInitDto = this.processInitDto // 审核人信息传回得信息
      }
      excepPayeeHandSubmit(this.formData).then(response => {
        this.confirmLoading = false
        this.handelClose()
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    handelClose() {
      // 工作流进入
      if (this.flowStatus) {
        const routePathStatus = sessionStorage.getItem('routePathStatus') // 工作流处理 00桌面进入 01待办列表进入
        this.$router.push({
          path: routePathStatus === '00' ? '/home' : '/work/todo'
        })
      } else {
        this.$emit('close')
        this.$refs.formData.resetFields()
      }
    }
  }
}
</script>

<style scoped lang="less">
  /deep/.from_table{
    .file-list{
      .fileBtn{
        margin-bottom: 0;
      }
    }
  }
</style>
