<template>
  <ele-modal
    custom-class="ele-dialog-form long-dialog-form"
    :centered="true"
    v-if="visible"
    :visible.sync="visible"
    :title="title"
    :close-on-click-modal="false"
    width="70%"
    @close="cancel"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="el-form-box">
      <headerTitle title="订单信息"></headerTitle>
      <el-row>
        <el-col :span="12">
          <el-form-item
            label="项目名称"
            prop="projectName">
            <el-input
              clearable
              v-model="form.projectName"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="销售类型"
            prop="saleType">
            <DictSelection
              dictName="销售类型"
              clearable
              v-model="form.saleType"
              :listFormatte="listFormatte">
            </DictSelection>
          </el-form-item>

          <el-form-item
            label="销售部门"
            prop="salesDeptId">
            <ele-tree-select
              clearable
              :data="groupTreeData"
              v-model="form.salesDeptId"
              valueKey="id"
              labelKey="name"
              placeholder="请选择"
              @change="change_principalDep"
              default-expand-all
            />
          </el-form-item>
          <el-form-item
            label="订单类型"
            prop="needProduce"
          >
            <el-radio v-model="form.needProduce" :label="1">生产性订单</el-radio>
            <el-radio v-model="form.needProduce" :label="0">库存式订单</el-radio>
          </el-form-item>
          <el-form-item prop="orderFiles" label="订单附件">
            <fileUpload
              v-model="form.orderFiles"
              module="main"
              :showLib="false"
              :limit="10"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="选择合同"
            prop="contractName"

          >
            <el-input
              clearable
              v-model="form.contractName"
              @click.native="handleContractBtn"
              @clear="clearContrcat"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="合同编号"
            prop="contractNumber"

          >
            <el-input
              disabled
              v-model="form.contractNumber"
            />
          </el-form-item>
          <!-- <el-form-item
            label="交货日期"
            prop="deliveryDate"

          >
            <el-date-picker
              v-model="form.deliveryDate"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </el-form-item> -->
          <el-form-item label="结算方式" prop="settlementMode">
            <DictSelection
              dictName="结算方式"
              clearable
              @itemChange="settlementModeChange"
              v-model="form.settlementMode"
            >
            </DictSelection>
          </el-form-item>
          <el-form-item
            label="计价方式"
            prop="pricingWay"
          >
            <el-radio-group v-model="form.pricingWay" @change="changePricingWay" :disabled="!!form.contractId">
              <el-radio v-for="item in pricingWayList" :label="item.id">{{ item.name }}</el-radio>
            </el-radio-group>
          </el-form-item>

        </el-col>

      </el-row>
      <headerTitle title="基本信息"></headerTitle>
      <el-row>
        <el-col :span="12">
          <el-form-item
            label="客户名称"
            prop="partaName"

          >
            <el-input
              clearable
              v-model="form.partaName"
              @click.native="handParent"
              placeholder="请选择"
            />
          </el-form-item>
          <el-form-item
            label="客户统一社会信用代码"
            prop="partaUnifiedSocialCreditCode"
            class="form_item_label">
            <el-input
              clearable
              v-model="form.partaUnifiedSocialCreditCode"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="客户联系人"
            prop="partaLinkName">
            <el-select
              v-model="form.partaLinkName"
              placeholder="请选择"
              @change="onchangeLink"
              @focus="selectFocus"
              style="width: 100%"
            >
              <el-option
                v-for="item in linkNameOptions"
                :key="item.id"
                :label="item.linkName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="客户电话"
            prop="partaTel"

          >
            <el-input
              clearable
              :maxlength="20"
              v-model="form.partaTel"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="客户传真"
            prop="partaFax"

          >
            <el-input clearable v-model="form.partaFax" placeholder="请输入"/>
          </el-form-item>
          <el-form-item
            label="	客户Email"
            prop="partaEmail"

          >
            <el-input
              clearable
              v-model="form.partaEmail"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="客户地址"
            prop="partaAddress"

          >
            <el-input
              clearable
              v-model="form.partaAddress"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="售出方名称"
            prop="partbName"

          >
            <!-- <el-input
                clearable
                v-model="form.partbName"
                placeholder="请输入"
              /> -->
            <el-input
              v-if="enterprisePage.length <= 1"
              clearable
              v-model="form.partbName"
              placeholder="请输入"
            />
            <el-select
              v-if="enterprisePage.length > 1"
              style="width: 100%"
              v-model="form.partbName"
              placeholder="请选择"
              @change="getEnterprise()"
            >
              <el-option
                v-for="item in enterprisePage"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="售出方统一社会信用代码"
            prop="partbUnifiedSocialCreditCode"
            class="form_item_label"
          >
            <el-input
              clearable
              v-model="form.partbUnifiedSocialCreditCode"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="售出方联系人"
            prop="partbLinkName"

          >
            <el-input
              clearable
              v-model="form.partbLinkName"
              @click.native="handHead"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item prop="partbTel" label="售出方联系电话">
            <el-input clearable v-model="form.partbTel" placeholder="请输入"/>
          </el-form-item>
          <el-form-item prop="partbFax" label="售出方传真">
            <el-input clearable v-model="form.partbFax" placeholder="请输入"/>
          </el-form-item>

          <el-form-item
            label="售出方Email"
            prop="partbEmail"

          >
            <el-input
              clearable
              v-model="form.partbEmail"
              placeholder="请输入"
            />
          </el-form-item>

          <el-form-item
            label="售出方地址"
            prop="partbAddress"

          >
            <el-input
              clearable
              v-model="form.partbAddress"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <headerTitle title="产品清单" style="margin-top: 30px"></headerTitle>
      <inventoryTable
        @orderDiscountAmount="orderDiscountAmount"
        :pricingWay="form.pricingWay"
        ref="inventoryTable"
        :isCustomerMark="true"
        :isContractId=!!form.contractId
      ></inventoryTable>
      <el-row style="margin-top: 20px">
        <el-col :span="12">
          <el-form-item
            label="优惠总金额"
            prop="payAmount"

          >
            <el-input
              type="number"
              :min="0"
              :max="allcountAmount"
              clearable
              :disabled="!!form.contractId||!allcountAmount"
              v-model.number="form.payAmount"
              @blur="discountInput"
              placeholder="请输入">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item
            label="收货地址"
            prop="receiveAddress"

          >
            <el-input
              clearable
              type="textarea"
              v-model="form.receiveAddress"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="总金额"
            prop="totalAmount"

          >
            {{ allcountAmount || 0 }}元
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input
              clearable
              type="textarea"
              v-model="form.remark"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div slot="footer" class="footer">
      <el-button type="primary" @click="save">保存</el-button>
      <el-button type="primary" @click="save('sub')">提交</el-button>

      <el-button @click="cancel">返回</el-button>
    </div>

    <parentList ref="parentRef" @changeParent="changeParent"></parentList>
    <head-list ref="headRef" @changeParent="changePersonel"></head-list>
    <contractListDialog
      ref="selectContractRef"
      @changeParent="changeContract"
    ></contractListDialog>
    <autogenerate-dialog :autogenerate-dialog-flag.sync="autogenerateDialogFlag" ref="autogenerateDialogRef"
                         v-if="autogenerateDialogFlag" @getAutogenerateParams="getAutogenerateParams"></autogenerate-dialog>
  </ele-modal>
</template>

<script>
import {emailReg, numberReg} from 'ele-admin';
import {acceptUnpackoptions} from '@/enum/dict';
import inventoryTable from './inventoryTable.vue';
import fileUpload from '@/components/upload/fileUpload';
import dictMixins from '@/mixins/dictMixins';
import parentList from '@/views/saleManage/contact/components/parentList.vue';
import autogenerateDialog from "@/BIZComponents/autogenerateDialog.vue";
import {getDetail} from '@/api/contractManage/contractBook';
import {
  getSaleOrderDetail,
  UpdateInformation,
  addInformation,
  submit
} from '@/api/saleManage/saleorder';
import {getcontactlink} from '@/api/saleManage/businessFollow';
import headList from '@/views/saleManage/businessOpportunity/components/headList.vue';
import contractListDialog from './contractListDialog.vue';
import paymentList from './paymentList.vue';
import {listOrganizations} from '@/api/system/organization';
import {copyObj} from '@/utils/util';
import {enterprisePage} from '@/api/contractManage/contractBook';

export default {
  mixins: [dictMixins],
  components: {
    fileUpload,
    headList,
    contractListDialog,
    paymentList,
    inventoryTable,
    parentList,
    autogenerateDialog
  },
  data() {
    let formDef = {
      id: '',
      contractId: '',
      orderFiles: [],
      contractName: '',
      // deliveryDate: '',
      pricingWay: 1,
      payAmount: '',
      projectName: '',
      projectId: '',
      receiveAddress: '',
      remark: '',
      saleType: '',
      saleTypeName: '',
      totalAmount: '',
      settlementMode: '4',
      settlementModeName: '分期付款',
      partaUnifiedSocialCreditCode: '',
      partbUnifiedSocialCreditCode: '',
      partaAddress: '',
      partaEmail: '',
      partaFax: '',
      partaId: '',
      partaLinkId: '',
      partaLinkName: '',
      partaName: '',
      partaTel: '',
      partbAddress: '',
      partbEmail: '',
      partbFax: '',
      partbId: '',
      partbLinkId: '',
      partbLinkName: '',
      partbName: '',
      partbTel: '',
      needProduce: 1
    };

    return {
      clearing: false, //是否清除合同
      autogenerateDialogFlag: false,
      payWayOptions: [],
      delDetailIds: [],
      linkNameOptions: [],
      pricingWayList: [
        {id: 1, name: '按数量计价'},
        {id: 2, name: '按重量计价'}
      ],
      acceptUnpackoptions,
      visible: false,
      title: '',
      row: {},
      activeName: 'base',
      formDef,
      form: copyObj(formDef),
      tableBankData: [],
      tableLinkData: [],
      // 组织机构树形结构数据
      groupTreeData: [],
      groupData: [],
      rules: {
        // deliveryDate: [
        //   { required: true, message: '请选择交货日期', trigger: 'change' }
        // ],
        settlementMode: [
          {required: true, message: '请选择结算方式', trigger: 'change'}
        ],

        saleType: [
          {required: true, message: '请选择销售类型', trigger: 'change'}
        ],

        partaName: [
          {required: true, message: '请选择客户名称', trigger: 'change'}
        ],
        partaLinkName: [
          {required: true, message: '请选择客户联系人', trigger: 'change'}
        ],
        acceptUnpack: [
          {required: true, message: '请选择是否接受', trigger: 'change'}
        ],
        partaTel: [
          {
            required: true,
            pattern: numberReg,
            message: '请输入客户联系电话',
            trigger: 'blur'
          }
        ],

        partbName: [
          {required: true, message: '请输入售出方名称', trigger: 'change'}
        ],
        partbLinkName: [
          {required: true, message: '请输入售出方联系人', trigger: 'change'}
        ],
        partbTel: [
          {
            required: true,
            pattern: numberReg,
            message: '请输入售出方联系电话',
            trigger: 'blur'
          }
        ],
        partaEmail: [
          {pattern: emailReg, message: '邮箱格式不正确', trigger: 'blur'}
        ],
        payAmount: [
          {required: true, message: '请输入', trigger: 'blur'}
        ],
      },

      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      enterprisePage: [],
      businessId: ''
    };
  },
  computed: {
    allcountAmount() {
      return this.$store.state.order.allcountAmount;
    }
  },
  created() {
    this.getGroupAll();
    this.getEnterprisePage();
  },
  methods: {
    discountInput() {
      this.$refs.inventoryTable.discountInputByOrder(this.form.payAmount)
    },
    // 选择负责人部门
    change_principalDep(id) {
      const info = this.groupData.find((e) => e.id == id);
      this.form.salesDeptName = info.name;
    },
    // 获取公司数据
    getGroupAll() {
      listOrganizations().then((list) => {
        this.groupData = list;
        this.groupTreeData = this.$util.toTreeData({
          data: list,
          idField: 'id',
          parentIdField: 'parentId'
        });
      });
    },

    //选择供应商
    async changeSupplier(obj) {
      this.form = Object.assign({}, this.form, {
        partbId: obj.id,
        partbName: obj.name,
        partbAddress: obj.addressName + obj.address,
        partbLinkId: '',
        partbLinkName: '',
        partbEmail: '',
        partbTel: ''
      });
      await this.getLinkInfo(obj.id);
      this.$nextTick(() => {
        let firstLink = this.linkNameOptions.find(item => item.ifChief == 1) || {}
        this.form = Object.assign({}, this.form, {
          partbLinkId: firstLink.id || this.linkNameOptions[0]?.id,
          partbLinkName: firstLink.linkName || this.linkNameOptions[0]?.linkName,
          partbTel: firstLink.mobilePhone || this.linkNameOptions[0]?.mobilePhone,
        });
      });
    },
    //选择合同获取合同的详情
    async getDetailData(id) {
      this.loading = true;
      const data = await getDetail(id);
      this.loading = false;
      if (data) {
        this.$nextTick(() => {
          let {contractVO} = data;
          // this.form=contractVOform.receiveAddress
          let {
            partaAddress,
            partaEmail,
            partaFax,
            partaId,
            partaLinkId,
            partaLinkName,
            partaName,
            partaTel,
            partbAddress,
            partbEmail,
            partbFax,
            partbId,
            partbLinkId,
            partbLinkName,
            partbName,
            partbTel,
            totalPrice,
            discountTotalPrice,
            partaUnifiedSocialCreditCode,
            partbUnifiedSocialCreditCode,
            settlementMode,
            settlementModeName,
            pricingWay
          } = contractVO;
          this.form = Object.assign({}, this.form, {
            partaAddress,
            partaEmail,
            partaFax,
            partaId,
            partaLinkId,
            partaLinkName,
            partaName,
            partaTel,
            partbAddress,
            partbEmail,
            partbFax,
            partbId,
            partbLinkId,
            partbLinkName,
            partbName,
            partbTel,
            pricingWay,
            totalPrice,
            discountTotalPrice,
            partaUnifiedSocialCreditCode,
            partbUnifiedSocialCreditCode,
            totalAmount: totalPrice,
            payAmount: discountTotalPrice || totalPrice,
            receiveAddress: partaAddress,
            settlementMode,
            settlementModeName
          });
          this.getLinkInfo(partaId);
          this.$refs.inventoryTable &&
          this.$refs.inventoryTable.putTableValue(data);
          this.$store.commit('order/setAllcountAmount', totalPrice);
        });
      }
    },

    //获取订单详情
    async getSaleOrderDetail(id) {
      this.businessId = id;
      this.loading = true;
      const data = await getSaleOrderDetail(id);
      this.loading = false;
      if (data) {
        this.$nextTick(() => {
          data.saleType = +data.saleType
          this.form = data;
          this.$refs.inventoryTable &&
          this.$refs.inventoryTable.putTableValueByOrder(data);
          this.getLinkInfo(data.partaId);
          this.$store.commit('order/setAllcountAmount', data.totalAmount);
          this.$store.commit('order/setContractId', data.contractId);
        });
      }
    },
    //产品清单修改单价或者数量重置优惠金额
    orderDiscountAmount(val = 0) {
      this.form.payAmount = val
    },
    //更新联系人数据
    async getLinkInfo(contactId) {
      const data = await getcontactlink({contactId});
      if (data && data?.length) {
        this.linkNameOptions = data;
      }
    },
    selectFocus() {
      if (this.linkNameOptions.length === 0) {
        return this.$message.error('请先选择名称');
      }
    },

    //选择下拉框
    onchangeLink(selectedOptions) {
      const option = this.linkNameOptions.find(
        (opt) => opt.id === selectedOptions
      );
      this.form = Object.assign({}, this.form, {
        partaEmail: option?.email,
        partaLinkName: option?.linkName || '',
        partaTel: option?.mobilePhone || option?.phone || '',
        partaLinkId: option?.id
      });
    },

    handHead() {
      let item = {
        id: this.form.partbLinkId
      };
      this.$refs.headRef.open(item);
    },

    //选择售出方人回调
    changePersonel(obj) {
      this.$set(this.form, 'partbLinkId', obj.id);
      this.$set(this.form, 'partbLinkName', obj.name);
      this.$set(this.form, 'partbTel', obj.phone);
      this.$set(this.form, 'partbEmail', obj.email);
    },
    //选择客户回调
    async changeParent(obj) {
      this.form = Object.assign({}, this.form, {
        partaId: obj.id,
        partaName: obj.name,
        partaAddress: obj.addressName + obj.address,
        partaLinkId: '',
        partaLinkName: '',
        partaEmail: '',
        partaTel: ''
      });
      await this.getLinkInfo(obj.id);
      this.$nextTick(() => {
        let firstLink = this.linkNameOptions.find(item => item.ifChief == 1) || {}
        this.form = Object.assign({}, this.form, {
          partaLinkId: firstLink.id || this.linkNameOptions[0]?.id,
          partaLinkName: firstLink.linkName || this.linkNameOptions[0]?.linkName,
          partaTel: firstLink.mobilePhone || this.linkNameOptions[0]?.mobilePhone,
        });
      });
    },

    //选择合同回调
    changeContract(obj) {
      this.form = Object.assign({}, this.form, {
        contractId: obj.id,
        contractName: obj.contractName,
        contractNo: obj.contractNo,
        contractNumber: obj.contractNumber
      });
      this.getDetailData(obj.id);
      this.$store.commit('order/setContractId', obj.id);
    },

    //选择合同弹框
    handleContractBtn() {
      if (this.clearing) return;
      let item = {
        id: this.form.contractId
      };
      this.$refs.selectContractRef.open(item);
    },
    //清除合同
    clearContrcat() {
      this.clearing = true;
      let {
        id,
        projectName,
        saleType,
        saleTypeName,
        // deliveryDate,
        orderFiles,
        remark
      } = this.form;
      this.form = Object.assign({}, copyObj(this.formDef), {
        id,
        projectName,
        saleType,
        saleTypeName,
        // deliveryDate,
        orderFiles,
        remark
      });

      this.$store.commit('order/setContractId', '');
      this.$store.commit('order/setAllcountAmount', 0);
      this.$refs.inventoryTable.putTableValue([]);

      setTimeout(() => {
        this.clearing = false;
      }, 500);
    },

    handParent() {
      if (this.form.contractId) {
        return this.$message.error('选择了合同不能更改客户名称');
      }
      let item = {
        id: this.form.contactId
      };
      this.$refs.parentRef.open(item);
    },
    listFormatte(data) {
      return data.filter(item => item.dictCode !== 0)
    },
    //切换计价方式重新算费用
    changePricingWay() {
      this.$refs.inventoryTable.getTotalPrice()
    },
    //打开新增编辑弹框
    async open(type, row, contactCategoryId) {
      this.title = type === 'add' ? '新增' : '修改';
      this.row = row;
      if (this.enterprisePage.length == 0) {
        await this.getEnterprisePage();
      }
      this.visible = true;
      if (type == 'add') {
        this.isUpdate = false;
        if (this.enterprisePage.length > 0) {
          this.form.partbName = this.enterprisePage[0].name;
          this.form.partbUnifiedSocialCreditCode =
            this.enterprisePage[0].unifiedSocialCreditCode;
          this.form.partbFax = this.enterprisePage[0].fax;
          this.form.partbAddress = this.enterprisePage[0].address;
        }
      } else {
        this.isUpdate = true;
        this.getSaleOrderDetail(row.id);
      }
    },

    //从合同页面新增订单
    async contractOpen(row) {
      this.title = '新增'
      this.visible = true;
      this.isUpdate = false;
      if (this.enterprisePage.length == 0) {
        await this.getEnterprisePage();
      }
      if (this.enterprisePage.length > 0) {
        this.form.partbName = this.enterprisePage[0].name;
        this.form.partbUnifiedSocialCreditCode = this.enterprisePage[0].unifiedSocialCreditCode;
        this.form.partbFax = this.enterprisePage[0].fax;
        this.form.partbAddress = this.enterprisePage[0].address;
      }
      await this.changeContract(row)

    },
    getEnterprisePage() {
      enterprisePage({
        pageNum: 1,
        size: 100
      }).then((res) => {
        this.enterprisePage = [];
        this.enterprisePage.push(...res.list);
      });
    },
    getEnterprise() {
      let data = this.enterprisePage.find(
        (item) => item.name == this.form.quoteName
      );
      this.form.partbName = data.name;
      this.form.partbUnifiedSocialCreditCode = data.unifiedSocialCreditCode;
      this.form.partbFax = data.fax;
      this.form.partbAddress = data.address;
    },
    salesmanChange(val, info) {
      this.otherForm.salesmanName = info.name;
    },
    settlementModeChange(info) {
      this.form.settlementModeName = info.dictValue;
    },
    ifChiefChange(value, idx) {
      if (value === 1) {
        this.tableLinkData.forEach((e) => (e.ifChief = 0));
        this.tableLinkData[idx].ifChief = 1;
      }
    },

    getValidate() {
      return Promise.all([
        new Promise((resolve, reject) => {
          this.$refs.form.validate((valid) => {
            if (!valid) {
              reject(false);
            } else {
              resolve(true);
            }
          });
        }),
        new Promise((resolve, reject) => {
          this.$refs.inventoryTable.validateForm((valid) => {
            if (!valid) {
              reject(false);
            } else {
              resolve(true);
            }
          });
        })
      ]);
    },
    async save(type) {
      try {
        await this.getValidate();
        // 表单验证通过，执行保存操作
        this.loading = true;

        if (!this.isUpdate) {
          delete this.form.id;
        }
        if (!this.form.contractId) {
          this.form.totalAmount = this.allcountAmount;
        }

        let commitData = Object.assign({}, this.form, {
          productList: this.$refs.inventoryTable.getTableValue(),
          saleTypeName: this.getDictValue('销售类型', this.form.saleType)
        });

        this.interfaceCall(commitData,type);
        // if (type === 'sub') {
        //   this.autogenerateDialogFlag = true
        // }else {
        //   this.interfaceCall(commitData,type);
        // }
      } catch (error) {
        console.log(error);
        // 表单验证未通过，不执行保存操作
      }
    },
    getAutogenerateParams(params){
      let commitData = Object.assign({}, this.form, {
        productList: this.$refs.inventoryTable.getTableValue(),
        saleTypeName: this.getDictValue('销售类型', this.form.saleType),
        ...params
      });
      this.interfaceCall(commitData,'sub');
    },
    interfaceCall(commitData,type){
      let API = this.isUpdate ? UpdateInformation : addInformation;
      API(commitData).then((res) => {
        this.loading = false;
        this.$message.success('操作成功');
        if (type === 'sub') {
          this.saleOrderSubmit(res);
          return;
        }
        this.cancel();
        this.$emit('done');
      })
        .catch((e) => {
          //this.loading = false;
        });
    },
    saleOrderSubmit(res) {
      submit({
        businessId: this.businessId || res
        // productionSupervisorId
      }).then((res) => {
        this.cancel();
        this.$emit('done');
      });
    },

    cancel() {
      this.$nextTick(() => {
        this.activeName = 'base';
        // 关闭后，销毁所有的表单数据
        this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
        this.$refs['formRef'] && this.$refs['formRef'].resetFields();
        this.$store.commit('order/clearUserData');
        this.form = copyObj(this.formDef);
        this.visible = false;
      });
    },
    //查找合同分类对应name
    findNameById(tree, targetId) {
      for (let i = 0; i < tree.length; i++) {
        const node = tree[i];
        if (node.id === targetId) {
          return node.name;
        }
        if (node.children && node.children.length > 0) {
          const name = this.findNameById(node.children, targetId);
          if (name) {
            return name;
          }
        }
      }
      return null;
    }
  }
};
</script>
<style scoped lang="scss">
.TotalAmount {
  font-size: 16px;
  padding-right: 30px;
}
</style>
