<template>
  <div class="acceptance-add">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >

      <cy-info-title style="margin: 0px -15px 10px;"> 基础信息 </cy-info-title>
      <el-form-item label="项目名称" prop="businessNumber">
        <el-select v-model="ruleForm.businessNumber" style="width: 100%" placeholder="请选择项目名称" @change="selectProject">
          <el-option
            v-for="(item, index) in businessList"
            :key="index + '_business'"
            :label="item.projectName"
            :value="item.businessNumber"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="核心企业名称">
        <el-input v-model="businessInfo.coreEnterpriseName" disabled />
      </el-form-item>
      <el-form-item label="供应商（主体）名称">
        <el-input v-model="businessInfo.mainEnterpriseName" disabled />
      </el-form-item>
      <el-form-item label="贸易平台">
        <el-input v-model="businessInfo.platformName" disabled />
      </el-form-item>
      <el-form-item label="业务编号">
        <el-input :value="businessInfo.businessNumber" disabled />
      </el-form-item>
      <el-form-item label="预估结算日期" prop="expectedSettlementDate">
        <el-date-picker v-model="ruleForm.expectedSettlementDate" value-format="yyyy-MM-dd" type="date" placeholder="选择预估结算日期" style="width: 100%;" />
      </el-form-item>

      <!-- 签署确认 -->
      <cy-info-title style="margin: 25px -15px 10px;">签署确认<span class="tips">（关于下游验收单请选择是否需要签署确认）</span></cy-info-title>
      <el-form-item
        label="签署确认"
        prop="signConfirm"
        class="industry"
      >
        <el-radio-group v-model="ruleForm.signConfirm">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="特别说明" class="two-form-item" prop="specification">
        <el-input
          v-model="ruleForm.specification"
          placeholder="签署人为：人员信息中的验收经办人（核心企业）；签署文件为：下游验收单文件"
        />
      </el-form-item>

      <!-- 人员信息 -->
      <cy-info-title style="margin: 25px -15px 10px;">人员信息</cy-info-title>
      <el-form-item label="验收经办人（供应商）" prop="checkOperatorSupplier" class="one-form-item">
        <el-select v-model="ruleForm.checkOperatorSupplier" style="width: 100%" allow-create clearable filterable placeholder="请输入验收经办人（供应商）" @change="chooseSuplierPerson">
          <el-option
            v-for="(item, index) in suplierPersonList"
            :key="index + '_suplier'"
            :label="item.name"
            :value="item.name"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="联系方式" prop="checkOperatorSupplierContact" class="one-form-item">
        <el-input v-model="ruleForm.checkOperatorSupplierContact" placeholder="请输入联系方式" />
      </el-form-item>
      <el-form-item label="验收经办人（核心企业）" prop="checkOperatorEnterprise" class="one-form-item">
        <el-select v-model="ruleForm.checkOperatorEnterprise" style="width: 100%" placeholder="请选择验收经办人（核心企业）" @change="chooseCorePerson">
          <el-option
            v-for="(item, index) in corePersonList"
            :key="index + '_core'"
            :label="item.name"
            :value="item.name"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="联系方式" prop="checkOperatorEnterpriseContact" class="one-form-item">
        <el-input v-model="ruleForm.checkOperatorEnterpriseContact" placeholder="请输入联系方式" />
      </el-form-item>

      <!-- 合作平台 -->
      <cy-info-title style="margin: 25px -15px 10px;">合作平台</cy-info-title>
      <el-form-item
        label="是否有合作平台"
        prop="steelWaiter"
        class="industry"
      >
        <el-radio-group v-model="ruleForm.steelWaiter">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="ruleForm.steelWaiter=='1'" label="销售单号" class="two-form-item" prop="sellBillNumber" :rules="[{required: ruleForm.steelWaiter=='1', message: '请选择销售单号', trigger: 'change'}]">
        <el-select v-model="ruleForm.sellBillNumber" style="width: 100%" placeholder="请选择销售单号" multiple @change="getGoodsInfo">
          <el-option
            v-for="(item, index) in salesNumber"
            :key="index + '_sale'"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>

      <!--  货物信息（下游验收） -->
      <cy-info-title style="margin: 25px -15px 0;">
        <span>
          货物信息（下游验收）
          <span class="statistics">数量合计： <span>{{ countTotal }}</span></span>
          <span class="statistics">销售总价合计： <span>{{ priceTotal }}</span></span>
        </span>
        <div slot="right">
          <el-button type="text" @click="downLoadTemplate">下载模板</el-button>
          <el-button type="text" @click="importTemplate">模板导入</el-button>
          <el-button type="text" @click="clearGoods">清空</el-button>
          <input ref="fileButton" type="file" accept="xls, .xlsx, .excel" style="display: none" @change="importFile">
        </div>
      </cy-info-title>
      <div style="width: 100%;margin: 0 -15px;">
        <!-- <cy-comm-table
          ref="commTable"
          :columns="columns"
          :data="goodsInfoList"
          :count="0"
        /> -->
        <el-table :data="goodsInfoList" style="width: 100%;">
          <el-table-column type="index" label="序号" show-overflow-tooltip />
          <el-table-column prop="goodsName" label="名称" show-overflow-tooltip />
          <el-table-column prop="goodsMaterial" label="材质" show-overflow-tooltip />
          <el-table-column prop="goodsType" label="型号" show-overflow-tooltip />
          <el-table-column prop="goodsFactory" label="厂家" show-overflow-tooltip />
          <el-table-column prop="goodsUnit" label="单位" show-overflow-tooltip />
          <el-table-column prop="goodsQuantity" label="数量" show-overflow-tooltip />
          <el-table-column prop="referencePrice" label="参考价格" show-overflow-tooltip>
            <template slot="header" slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="网价" placement="top">
                <span class="table-tip-icon">!</span>
              </el-tooltip>
              <span>参考价格</span>
            </template>
          </el-table-column>
          <el-table-column prop="floatingPrice" label="浮动价格" show-overflow-tooltip>
            <template slot="header" slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="合约中约定的上下浮动差价" placement="top">
                <span class="table-tip-icon">!</span>
              </el-tooltip>
              <span>浮动价格</span>
            </template>
          </el-table-column>
          <el-table-column prop="salesPrice" label="销售单价（元）" show-overflow-tooltip />
          <el-table-column prop="acceptanceDate" label="验收日期" show-overflow-tooltip />
          <el-table-column prop="" label="操作">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="删除" placement="top">
                <span style="cursor: pointer; color: #6bcafc;" @click="deleteGoods(scope.$index)">删除</span>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <cy-info-title style="margin: 25px -15px 10px;">验收文件（下游）</cy-info-title>
      <el-form-item label="验收单附件" prop="acceptanceFile" style="width: 100%" class="required-item">
        <span slot="label" class="required-label">验收单附件</span>
        <cy-upload
          ref="acceptanceFile"
          :upload-params="{fileType: 'acceptanceFile'}"
          :file-data="ruleForm.acceptanceFile"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
        />
      </el-form-item>

      <cy-info-title style="margin: 25px -15px 10px;">补充说明 <span class="tips">（非必填）</span></cy-info-title>
      <el-form-item label=" 补充说明" class="two-form-item" prop="additionalRemarks">
        <el-input
          v-model="ruleForm.additionalRemarks"
          placeholder="请输入补充说明"
        />
      </el-form-item>
      <el-form-item label="补充说明文件" prop="acceptanceSupplementFile">
        <cy-upload
          ref="acceptanceSupplementFile"
          :upload-params="{fileType: 'acceptanceSupplementFile'}"
          :file-data="ruleForm.acceptanceSupplementFile"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
        />
      </el-form-item>

      <cy-info-title style="margin: 25px -15px 10px;">申请审核</cy-info-title>
      <el-form-item
        label="申请审核"
        prop="approval"
        class="industry"
      >
        <el-radio-group v-model="ruleForm.approval">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <div class="submit-btn">
      <el-button style="position: absolute;left: 50px;" @click="validate('preview')">预览上游验收单</el-button>
      <el-button @click="closePage">关闭</el-button>
      <el-button type="primary" @click="validate('temp')">暂存</el-button>
      <el-button type="primary" @click="validate('submit')">提交</el-button>
    </div>
  </div>
</template>

<script>
import { exportFile, exportUrl } from '@/utils/index'
import { getDetails, getOperaterOfCore, getCompletedProjectList, getCompletedProjectDetail, getSteelBillNumber, getGoodsBySaleNumber, acceptanceAddInfo, download, importGoodsTemplate, acceptanceUpdateInfo, previewUpFile } from '@/api/myTrade/acceptanceManagement/index'
export default {
  name: 'AcceptanceFormAdd',
  components: {

  },
  data() {
    const validateMobile = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入联系方式'))
      } else if (!/^1[3456789]\d{9}$/.test(value)) {
        callback(new Error('请输入有效联系方式'))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        id: '',
        taskId: '',
        projectName: '',
        businessNumber: '',
        expectedSettlementDate: '',
        signConfirm: '',
        specification: '',
        checkOperatorSupplier: '',
        checkOperatorSupplierContact: '',
        checkOperatorEnterprise: '',
        checkOperatorEnterpriseContact: '',
        steelWaiter: '',
        sellBillNumber: [],
        approval: '',
        additionalRemarks: '',
        acceptanceSupplementFile: [],
        acceptanceFile: []
      },
      rules: {
        businessNumber: [{ required: true, trigger: 'change', message: '请选择项目名称' }],
        expectedSettlementDate: [{ required: true, trigger: 'change', message: '选择结算日期' }],
        signConfirm: [{ required: true, trigger: 'change', message: '请选择是否签署确认' }],
        checkOperatorSupplier: [{ required: true, trigger: 'blur', message: '请输入验收经办人（供应商）' }],
        checkOperatorSupplierContact: [{ required: true, trigger: 'blur', message: '请输入联系方式' }, { validator: validateMobile, trigger: 'blur' }],
        checkOperatorEnterprise: [{ required: true, trigger: 'change', message: '请选择验收经办人（核心企业）' }],
        checkOperatorEnterpriseContact: [{ required: true, trigger: 'blur', message: '请输入联系方式' }, { validator: validateMobile, trigger: 'blur' }],
        steelWaiter: [{ required: true, trigger: 'change', message: '请选择是否有合作平台' }],
        approval: [{ required: true, trigger: 'change', message: '请选择是否申请审核' }]
      },
      countTotal: 0,
      priceTotal: 0,
      businessList: [],
      businessInfo: {
        projectName: '',
        coreEnterpriseName: '',
        mainEnterpriseName: '',
        platformName: '',
        businessNumber: ''

      },
      corePersonList: [],
      corePersonInfo: {
        mobile: '',
        signer: 0
      },
      suplierPersonList: [],
      suplierPersonInfo: {
        mobile: '',
        signer: 0
      },
      salesNumber: [],
      goodsInfoList: [

      ],
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '名称',
          showTooltip: true,
          prop: 'goodsName'
        },
        {
          label: '材质',
          showTooltip: true,
          prop: 'goodsMaterial'
        },
        {
          label: '型号',
          showTooltip: true,
          prop: 'goodsType'
        },
        {
          label: '厂家',
          showTooltip: true,
          prop: 'goodsFactory'
        },
        {
          label: '单位',
          showTooltip: true,
          prop: 'goodsUnit'
        },
        {
          label: '数量',
          showTooltip: true,
          prop: 'goodsQuantity'
        },
        {
          label: '参考价格',
          showTooltip: true,
          prop: 'referencePrice'
        },
        {
          label: '浮动价格',
          showTooltip: true,
          prop: 'floatingPrice'
        },
        {
          label: '销售单价（元）',
          showTooltip: true,
          prop: 'salesPrice'
        },
        {
          label: '验收日期',
          showTooltip: true,
          prop: 'acceptanceDate'
        },
        {
          label: '操作',
          show: true,
          render: (h, row, index) => {
            const btnList = [
              { msg: '删除', icon: 'el-icon-delete', power: 'projectNumber:empty', category: 'clear' }
            ]
            const options = btnList.map(item => {
              return (
                <span class='table-icon-box' style='font-size: 14px;' onClick={() => { this.deleteGoods(index) }}>
                  { item.msg }
                </span>
              )
            })
            return <div>{ options }</div>
          }

        }
      ],
      deleteFileIds: [],
      originFileIds: []
    }
  },
  watch: {
    goodsInfoList: {
      handler(newV) {
        let num = 0; let price = 0
        this.goodsInfoList.forEach(item => {
          num += Number(item.goodsQuantity)
          price += Number(item.salesPrice) * Number(item.goodsQuantity)
          item.acceptanceDate = item.acceptanceDate.split(' ')[0]
        })

        this.countTotal = num ? num.toFixed(4) : 0
        this.priceTotal = price ? price.toFixed(2) : 0
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    if (this.$route.query.type) {
      const { id, taskId } = this.$route.query
      this.ruleForm.id = id
      this.ruleForm.taskId = taskId
      this.getPojectList()
      this.getDetailInfo()
    } else {
      this.getPojectList()
    }
  },
  methods: {
    getDetailInfo() {
      const { id } = this.$route.query
      getDetails({ id: id }).then(res => {
        if (res.success) {
          const { data } = res
          this.ruleForm.businessNumber = data.businessNumber
          this.selectProject(data.businessNumber)

          for (const k in this.ruleForm) {
            if (data[k] !== '' && data[k] !== null && data[k] !== undefined) {
              this.ruleForm[k] = data[k]
            }
          }

          this.goodsInfoList = data.acceptanceGoodInfos

          this.ruleForm.acceptanceFile = data.fileStorageDOList
          this.ruleForm.acceptanceSupplementFile = data.supplementFiles
          this.originFileIds.push(data.fileStorageDOList[0].id)
          this.originFileIds.push(data.supplementFiles[0].id)
        }
      })
    },

    validate(submitType) {
      const acceptanceFile = this.$refs.acceptanceFile.getFileLists
      const acceptanceSupplementFile = this.$refs.acceptanceSupplementFile.getFileLists

      // 货物
      const acceptanceGoodInfos = []
      this.goodsInfoList.map(item => {
        const obj = {
          goodsName: item.goodsName,
          goodsMaterial: item.goodsMaterial,
          goodsType: item.goodsType,
          goodsFactory: item.goodsFactory,
          goodsUnit: item.goodsUnit,
          goodsQuantity: item.goodsQuantity,
          acceptanceDate: item.acceptanceDate,
          salesPrice: item.salesPrice,
          referencePrice: item.referencePrice,
          floatingPrice: item.floatingPrice
        }
        acceptanceGoodInfos.push(obj)
      })
      const fileStorageIds = []
      acceptanceFile.map(item => {
        fileStorageIds.push(item.id)
      })
      acceptanceSupplementFile.map(item => {
        fileStorageIds.push(item.id)
      })
      // 删除的附件id
      const deleteFileIds = this.originFileIds.filter(item => {
        return !fileStorageIds.includes(item)
      })

      // 人员信息
      const acceptancePersonInfos = []
      const corePersonInfo = this.corePersonList.filter(item => item.name === this.ruleForm.checkOperatorEnterprise).length ? this.corePersonList.filter(item => item.name === this.ruleForm.checkOperatorEnterprise)[0] : { name: this.ruleForm.checkOperatorEnterprise, type: '验收经办人（核心企业）', mobile: '' }
      const suplierPersonInfo = this.suplierPersonList.filter(item => item.name === this.ruleForm.checkOperatorSupplier).length ? this.suplierPersonList.filter(item => item.name === this.ruleForm.checkOperatorSupplier)[0] : { name: this.ruleForm.checkOperatorSupplier, type: '验收经办人（供应商）', mobile: '' }
      suplierPersonInfo && (suplierPersonInfo.mobile = this.ruleForm.checkOperatorSupplierContact)
      suplierPersonInfo && (suplierPersonInfo.signer = 0)
      corePersonInfo && (corePersonInfo.mobile = this.ruleForm.checkOperatorEnterpriseContact)
      corePersonInfo && (corePersonInfo.signer = this.ruleForm.signConfirm ? 1 : 0)
      suplierPersonInfo && acceptancePersonInfos.push(suplierPersonInfo)
      corePersonInfo && acceptancePersonInfos.push(corePersonInfo)

      var params = {
        Loading: true,
        ...this.ruleForm,
        ...this.businessInfo,
        acceptanceGoodInfos,
        fileStorageIds,
        deleteFileIds,
        acceptancePersonInfos
      }

      if (submitType === 'temp') {
        params.submitStatus = 0
        this.submit(params, submitType)
      } else if (submitType === 'submit') {
        params.submitStatus = 1
        this.$refs.ruleFormRef.validate(valid => {
          if (valid) {
            if (acceptanceGoodInfos.length === 0) {
              this.$message.warning('货物信息不能为空')
              return
            }
            if (!acceptanceFile.length) {
              this.$message.warning('请上传验收单附件')
              return
            }

            this.submit(params, submitType)
          } else {
            this.$message.warning('必填项不能为空')
          }
        })
      } else if (submitType === 'preview') {
        this.$refs.ruleFormRef.validate(valid => {
          if (valid) {
            if (acceptanceGoodInfos.length === 0) {
              this.$message.warning('货物信息不能为空')
              return
            }
            previewUpFile(params).then(res => {
              if (res.success) {
                if (res.data.length) {
                  // const fileArr = []
                  res.data.map(data => {
                    let base64Str = data.split(',')[1]
                    const base64Regex = /^[A-Za-z0-9+/]+={0,2}$/
                    if (!base64Regex.test(base64Str)) {
                      this.$message.warning('验收单生成格式有误。')
                      throw new Error('The string to be decoded is not correctly encoded.')
                    }

                    // 如果输入字符串长度不是4的倍数，添加等号'='
                    if (base64Str.length % 4 !== 0) {
                      base64Str += '='
                    }

                    const byteCharacters = atob(base64Str)
                    const byteNumbers = new Array(byteCharacters.length)
                    for (let i = 0; i < byteCharacters.length; i++) {
                      byteNumbers[i] = byteCharacters.charCodeAt(i)
                    }
                    const byteArray = new Uint8Array(byteNumbers)

                    // fileArr.push(byteArray)
                    const blob = new Blob([byteArray], { type: 'application/pdf' })
                    const newurl = URL.createObjectURL(blob)
                    exportUrl(newurl)
                  })
                  // const blob = new Blob(fileArr, { type: 'application/pdf' })
                  // const newurl = URL.createObjectURL(blob)
                  // exportUrl(newurl)
                }
              } else {
                this.$message.warning(res.msg)
              }
            })
          } else {
            this.$message.warning('必填项不能为空')
          }
        })
      }
    },
    submit(data, submitType) {
      if (this.$route.query.taskId) {
        acceptanceUpdateInfo(data).then((res) => {
          if (res.success) {
            if (submitType === 'submit') {
              this.$message.success('提交成功')
              this.closePage()
            } else {
              this.$message.success('暂存成功')
              this.closePage()
            }
          } else {
            this.$message.warning(res.msg)
          }
        })
      } else {
        delete data.taskId
        acceptanceAddInfo(data).then((res) => {
          if (res.success) {
            if (submitType === 'submit') {
              this.$message.success('提交成功')
              this.closePage()
            } else {
              this.$message.success('暂存成功')
              this.closePage()
            }
          } else {
            this.$message.warning(res.msg)
          }
        })
      }
    },

    // 货物-模板导入
    importTemplate() {
      this.$refs.fileButton.click()
    },
    importFile(e) {
      const file = e.target.files[0] || e.dataTransfer.files[0]// 用于提交
      const postData = new FormData()
      postData.append('flag', 0)
      postData.append('file', file)
      importGoodsTemplate(postData).then(res => {
        if (res.success) {
          if (res.data.length) {
            this.goodsInfoList = []
            res.data.map(item => {
              item.salesPrice = parseFloat(item.referencePrice + item.floatingPrice).toFixed(2)
              item.acceptanceDate = item.acceptanceDate.split(' ')[0]
              this.goodsInfoList.push(item)
            })
          }
        } else {
          this.$message.warning(res.msg)
        }
      })
      e.target.value = ''
    },

    // 清空货物
    clearGoods() {
      this.goodsInfoList = []
      this.countTotal = 0
      this.priceTotal = 0
    },

    // 查询完成项目-项目名称
    getPojectList() {
      getCompletedProjectList().then(({ data }) => {
        this.businessList = data || []
      })
    },

    // 项目具体信息
    selectProject(v) {
      if (this.ruleForm.businessNumber) {
        getCompletedProjectDetail({ businessNumber: v }).then((res) => {
          if (res.success) {
            const { data } = res
            for (const k in this.businessInfo) {
              if (data[k] !== '' && data[k] !== null && data[k] !== undefined) {
                this.businessInfo[k] = data[k]
              }
            }
            this.businessInfo.tradingPlatformId = data.platformId
            this.businessInfo.cProjectCoreEnterpriseId = data.coreEnterpriseId
            this.businessInfo.cSupplierInfoId = data.mainEnterpriseId
            this.getSaleNumber(this.businessInfo.mainEnterpriseName)
          }
        })
        this.getPersonCore(v)
      }
    },

    // 获取经办人（核心企业）
    getPersonCore(v) {
      const params = {
        businessNumber: v
      }
      getOperaterOfCore(params).then(({ data }) => {
        if (data.length) {
          this.corePersonList = data.filter(item => {
            return item.type === '验收经办人（核心企业）'
          })

          this.suplierPersonList = data.filter(item => {
            return item.type === '验收经办人（供应商）'
          })
        } else {
          this.corePersonList = []
          this.suplierPersonList = []
        }
      })
    },

    // 选择核心企业验收人
    chooseCorePerson(v) {
      if (v) {
        const corePersonInfo = this.corePersonList.filter(item => item.name === this.ruleForm.checkOperatorEnterprise)[0]
        if (corePersonInfo) { // 下拉选择的
          this.ruleForm.checkOperatorEnterpriseContact = corePersonInfo.mobile
        } else { // 手动输入
          this.ruleForm.checkOperatorEnterpriseContact = ''
        }
      } else {
        this.ruleForm.checkOperatorEnterpriseContact = ''
      }
    },
    // 选择供应商验收人
    chooseSuplierPerson(v) {
      if (v) {
        const suplierPersonInfo = this.suplierPersonList.filter(item => item.name === this.ruleForm.checkOperatorSupplier)[0]
        if (suplierPersonInfo) { // 下拉选择的
          this.ruleForm.checkOperatorSupplierContact = suplierPersonInfo.mobile
        } else { // 手动输入
          this.ruleForm.checkOperatorSupplierContact = ''
        }
      } else {
        this.ruleForm.checkOperatorSupplierContact = ''
      }
    },

    // 钢小二 销售单号
    getSaleNumber(v) {
      const params = {
        supplierName: v,
        // supplierName: '上海辞良实业有限公司',
        keyword: ''
      }
      getSteelBillNumber(params).then(res => {
        this.salesNumber = res.data || []
      })
    },

    // 计算货物统计信息
    countGoods() {
      let num = 0
      this.goodsInfoList.forEach(item => {
        num = parseFloat(num + item.goodsQuantity).toFixed(4)
      })
      let price = 0
      this.goodsInfoList.forEach(item => {
        price = parseFloat(price + item.salesPrice).toFixed(2)
      })
      this.countTotal = num
      this.priceTotal = price
    },

    // 货物信息
    getGoodsInfo(v) {
      if (v.length) {
        const postData = new FormData()
        postData.append('companyName', this.businessInfo.mainEnterpriseName)
        v.map((item, i) => {
          postData.append(`billNumbers[${i}]`, item)
        })
        getGoodsBySaleNumber(postData).then(res => {
          this.goodsInfoList = []
          res.data.map(item => {
            item.referencePrice = item.salesPrice
            item.floatingPrice = 0
            item.salesPrice = parseFloat(item.referencePrice + item.floatingPrice).toFixed(2)
            item.acceptanceDate = item.acceptanceDate.split(' ')[0]
            this.goodsInfoList.push(item)
          })
        })
      } else {
        this.goodsInfoList = []
      }
    },

    // 下载
    downLoadTemplate() {
      download().then((data) => {
        exportFile(data)
      })
      return
    },

    // 删除货物
    deleteGoods(index) {
      if (this.goodsInfoList.length) {
        this.goodsInfoList.splice(index, 1)
      }
    },

    closePage() {
      this.$router.push({
        name: 'MyTrade',
        query: {
          type: 'AcceptanceManagement'
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.acceptance-add {
  padding: 10px 30px;
  .statistics {
    color: #FF0000;
    margin-left: 20px;
    font-size: 14px;
  }
  .tips {
    color: #918c8c;
    font-size: 12px;
  }
  .required-item {
    .required-label:before {
      content: '*'!important;
      color: #F56C6C;
      margin-right: 4px;
    }

  }
  .table-tip-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 7px;
    line-height: 14px;
    text-align: center;
    border: 1px solid #ff0000;
    color: #ff0000;
    margin-right: 5px;
  }
}
</style>
