RedDialog.vue 4.67 KB
<template>
  <d2-dialog :title="title" :is-visible="redVisible" class="redDialog" width="680px" @closeDialog="handleRedClose" @confirmDialog="handleRedConfirm">
    <div class="red-box">
      <glsx-combi-form class="edit-form-container" ref="editFormRef" label-width="180px" default-width="400px" :isBlock="isBlock" :form-ref="editChildRef" :form-obj="editForm" :form-data="editFormData" :form-rules="formRules"></glsx-combi-form>
    </div>
  </d2-dialog>
</template>

<script>
import { deepClone } from '@/common/util'
import { redReasonOpt } from "@/common/constants.js"
import { invoiceRed } from "@api/invoiceManage"
export default {
  name: 'RedDialog',
  props: {
    redVisible: {
      type: Boolean,
      default: false
    },
    redInfo: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    //这里存放数据
    return {
      title: '冲红',
      isBlock: true,
      editChildRef: 'editChildRef',
      editForm: {
        reason: ''
      },
      formRules: {
        reason: [{ required: true, message: '请选择冲红原因', trigger: 'change' }]
      },
      editFormData: [{
        label: "数电票号码",
        name: "electronicInvoiceNo",
        type: 'showTxt'
      }, {
        label: "原发票价税合计金额",
        name: "amountWithTax",
        type: 'showTxt'
      }, {
        label: "原发票金额(不含税)",
        name: "noTaxAmount",
        type: 'showTxt'
      }, {
        label: "原发票税额",
        name: "taxAmount",
        type: 'showTxt'
      }, {
        label: "剩余可冲红金额",
        name: "noTaxAmount",
        type: 'showTxt'
      }, {
        label: "剩余可冲红税额",
        name: "taxAmount",
        type: 'showTxt'
      }, {
        label: "冲红原因",
        name: "reason",
        type: "select",
        isClear: true,
        optionList: [],
        optionId: "confId",
        optionLabel: "confValue",
        optionsName: "redReasonOpt"
      }],
      baseData: {
        redReasonOpt: deepClone(redReasonOpt)
      }
    }
  },
  methods: {
    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find((k) => k.name == refreshSigle)
        var index = this[formName].findIndex((k) => k.name == refreshSigle)
        this.$set(
          this[formName][index],
          "optionList",
          deepClone(this.baseData[item.optionsName])
        )
        if (
          hasAll &&
          this.baseData[item.optionsName].length &&
          this.baseData[item.optionsName][0][
          this[formName][index].optionLabel
          ] !== "全部"
        ) {
          const temp = {}
          temp[this[formName][index].optionId] = ""
          temp[this[formName][index].optionLabel] = "全部"
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (
            item.type === "select" &&
            this.baseData[item.optionsName].length
          ) {
            this.$set(
              this[formName][index],
              "optionList",
              deepClone(this.baseData[item.optionsName])
            )
            if (
              hasAll &&
              this.baseData[item.optionsName].length &&
              this.baseData[item.optionsName][0][
              this[formName][index].optionLabel
              ] !== "全部"
            ) {
              const temp = {}
              temp[this[formName][index].optionId] = ""
              temp[this[formName][index].optionLabel] = "全部"
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    handleRedClose() {
      this.$emit('handleRedClose')
    },
    handleRedConfirm() {
      this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
        if (valid) {
          this.$confirm('请确认是否要执行当前操作', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.loading = true
            const params = {
              electronicInvoiceNo: this.redInfo.electronicInvoiceNo,
              reason: this.editForm.reason
            }
            invoiceRed(params).then(res => {
              this.notice.okTips('冲红成功')
              this.$emit('handleRedClose', true)
            })
          }).catch(err => {
            console.log(err)
          }).finally(() => {
            this.loading = false
          })
        }
      })
    }
  },
  mounted() {
    this.editForm = deepClone(this.redInfo)
    this.getOptionsList('editFormData', false)
  }
};
</script>
<style lang='scss' scoped>
</style>