<template>
    <div style="width:500px">
      <div class="customerAuditCancel">
        <div style="display: flex;align-items: center;margin-bottom: 16px;">
          <Form
            ref="formValidate"
            :model="VarianceForm"
            :label-width="78"
          >
            <FormItem
              label="驳回原因"
              required
              width="420"
            >
              <Input
                v-model="VarianceForm.reason"
                type="textarea"
                :rows="4"
                placeholder=""
              />
            </FormItem>
          </Form>
        </div>
        <footer style="display: flex; justify-content: flex-end; margin-top: 16px">
          <Button
            type="fcdefault"
            style="width: 80px; height: 34px; font-size: 14px"
            @click="cancelModal"
          >
            取消
          </Button>
          <Button
            type="posdefault"
            style="width: 80px; height: 34px; font-size: 14px; margin-left: 8px"
            @click="okToAddBill"
          >
            确定
          </Button>
        </footer>
      </div>
    </div>
  </template>
  <script>
    const R3 = window.R3;
    const { network } = R3;
    export default {
      props: {
        idArray: { // 获取ID用于多选
          type: Array,
          default: () => []
        },
      },
      data() {
        return {
          VarianceForm: {
            reason: ''
          },
          errorModal: false, // 替换失败
          errorMsg: {
            message: '',
            errorList: []
          },
          mask: 'true',
          showCancel: true,
        };
      },
      methods: {
        //   取消按钮
        cancelModal() {
          this.$emit('closeActionDialog', true);
        },
        // 确定取消原因
        okToAddBill() {
          if (!this.VarianceForm.reason) {
            return this.$Message.warning('驳回原因不能为空！');
          }
          let params = {
            ids: this.idArray,
            reject_reason: this.VarianceForm.reason
          };
          network.post('/p/cs/returnmoney/finance_audit/cancel', params).then((res)=>{
            if(res.data.code == 0){
                document.querySelector('#refresh').click(); // 标准列表刷新按钮
                this.$emit('closeActionDialog', true);
                return this.$Message.success(res.data.message);
            } else if(res.data.data.notice.remit_id_list.length > 0){
                this.$emit('closeActionDialog', true);
                this.$Modal.fcWarning({
                  title: '警告',
                  mask: true,
                  showCancel: true,
                  content: res.data.message, // '单据编号XX，YY已打款，您确定要执行操作（反财审）？',
                  onOk:()=>{
                      this.secondToAdd();
                  }
                });
            }
          });
        },
        secondToAdd() {
            let params = {
            ids: this.idArray,
            reject_reason: this.VarianceForm.reason
          };
          network.post('/p/cs/returnmoney/finance_audit/cancel_remit', params).then((res)=>{
            if(res.data.code == 0){
                document.querySelector('#refresh').click(); // 标准列表刷新按钮
                this.$emit('closeActionDialog', true);
                return this.$Message.success(res.data.message);
            }
          }) 
        },
        onOk() {
          this.$emit('closeActionDialog', true);
        }
      }
    };
  </script>
  <style lang="less">
    .customerAuditCancel textarea.ark-input {
      width: 420px;
      max-width: 420px;
    }
    .cancelResult .ark-btn-text {
      display: none;
    }
  </style>
  