<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-icon_personalcenter"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content" v-loading="loading">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="100px"
        label-position="right"
        :rules="rules"
      >
        <div class="rows" @click="handleOver">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">基本信息</div>
          </div>
          <i
            :class="!flexAuto ? 'el-icon-arrow-right' : 'el-icon-arrow-down'"
            style="margin-left: 10px"
          ></i>
        </div>
        <div :class="!flexAuto ? 'auto' : 'classNone'">
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item label="申请编号" prop="applicationNum">
                <el-input
                  disabled
                  v-model="parameter.applicationNum"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="编制人" prop="preparedUserName">
                <el-input
                  v-model="parameter.preparedUserName"
                  placeholder="请输入编制人"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="申请类型" prop="applicationType">
                <dict-select
                  dictCode="cgsq-sqlx"
                  :hasDefaultOption="true"
                  clearable
                  @select="changeApplicationType"
                  style="width: 100%"
                  v-model="parameter.applicationType"
                  placeholder="请选择申请类型"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="需求日期" prop="applicationDate">
                <el-date-picker
                  style="width: 100%"
                  @change="changeApplicationDate"
                  v-model="parameter.applicationDate"
                  value-format="yyyy-MM-dd"
                  type="date"
                  placeholder="选择需求日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item label="定价方式" prop="procurementMethod">
                <dict-select
                  dictCode="cgsq-djfs"
                  :hasDefaultOption="true"
                  clearable
                  style="width: 100%"
                  v-model="parameter.procurementMethod"
                  placeholder="请选择定价方式"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6"
              ><el-form-item label="是否集中采购" prop="matIfPlat">
                <dict-select
                  dictCode="cglx-ywlx"
                  :hasDefaultOption="true"
                  clearable
                  disabled
                  style="width: 100%"
                  @select="changeMatIfPlat"
                  v-model="parameter.matIfPlat"
                  placeholder="请选择是否集中采购"
                /> </el-form-item
            ></el-col>
            <el-col :span="6">
              <el-form-item label="报价方式" prop="isTax">
                <dict-select
                  dictCode="cgsq-bjfs"
                  :hasDefaultOption="true"
                  clearable
                  style="width: 100%"
                  v-model="parameter.isTax"
                  placeholder="请选择报价方式"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="付款方式" prop="payMethod">
                <dict-select
                  dictCode="cglx-fkfs"
                  :hasDefaultOption="true"
                  clearable
                  @select="changePayMethod"
                  style="width: 100%"
                  v-model="parameter.payMethod"
                  placeholder="请选择付款方式"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="6" v-if="parameter.payMethod == 2">
              <el-form-item
                label="承兑时间"
                key="1"
                class="form-flex"
                prop="acceptanceTime"
              >
                <dict-select
                  dictCode="cdsj"
                  :hasDefaultOption="true"
                  clearable
                  @select="changeAcceptanceTime"
                  style="width: 100%"
                  v-model="parameter.acceptanceTime"
                  placeholder="请选择承兑时间"
                />
                <div class="append">月</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="是否代采" prop="isAgencyProcure">
                <dict-select
                  dictCode="cgsq-sfdc"
                  :hasDefaultOption="true"
                  clearable
                  style="width: 100%"
                  @select="changeProcure"
                  v-model="parameter.isAgencyProcure"
                  placeholder="请选择是否代采"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="parameter.isAgencyProcure == 1">
              <el-form-item label="代采企业" prop="agencyProcureOrgName">
                <el-input
                  v-model="parameter.agencyProcureOrgName"
                  disabled
                  placeholder=""
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                label="是否公示"
                prop="isAnnouncement"
                v-if="this.parameter.procurementMethod == 5"
              >
                <el-select
                  v-model="parameter.isAnnouncement"
                  style="width: 100%"
                  clearable
                >
                  <el-option
                    v-for="item in announcementList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                label="挂账时间"
                class="form-flex"
                prop="pendingTime"
              >
                <div
                  slot="label"
                  style="
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;
                  "
                >
                  <span>挂账时间</span>
                  <el-tooltip
                    effect="dark"
                    content="挂账时间为0表示无时间限制"
                    placement="bottom"
                  >
                    <i style="font-size: 18px" class="el-icon-question" />
                  </el-tooltip>
                </div>
                <dict-select
                  dictCode="cdsj"
                  :hasDefaultOption="true"
                  clearable
                  style="width: 100%"
                  @select="changePendingTime"
                  v-model="parameter.pendingTime"
                  placeholder="请选择挂账时间"
                />
                <div class="append">月</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24"> </el-row>
          <div class="rows">
            <div class="rows-left">
              <div class="rows-hr"></div>
            </div>
            <div class="rows-title">
              <div class="text-overflow">相关文件</div>
            </div>
          </div>
          <div>
            <el-upload
              class="upload-demo"
              ref="upload"
              :headers="headers"
              :action="action"
              :file-list="dataList"
              :multiple="false"
              accept=".png,.jpg,.jpeg,.xlsx,.xls,.pdf,.docx,.doc,.zip,.rar"
              :show-file-list="false"
              :on-success="handleSuccess"
            >
              <el-button
                icon="el-icon-upload"
                slot="trigger"
                size="small"
                type="primary"
                >上传文件</el-button
              >
              <span>（请上传相关技术文件、招标文件）</span>
            </el-upload>
          </div>
          <el-table
            class="down"
            :data="dataList"
            border
            stripe
            style="width: 100%; margin-top: 20px"
          >
            <el-table-column prop="name" label="文件名称"></el-table-column>
            <el-table-column prop="size" label="文件大小">
              <template slot-scope="scope">
                <span>{{ scope.row.fileSize }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="createTime" label="上传时间">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.createTime }}
                </div>
              </template>
            </el-table-column>
            <el-table-column width="150px" label="操作">
              <template slot-scope="scope">
                <el-button size="small" type="text">
                  <a
                    target="_blank"
                    @click="downloadFile(scope.row.name, scope.row.url)"
                    >下载</a
                  >
                </el-button>
                <el-button
                  size="small"
                  type="text"
                  @click="deleteHandle(scope.$index)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title" style="display: flex; align-items: center">
            <div class="text-overflow">物料信息</div>
            <!-- <el-button
              @click="openDialog"
              type="primary"
              style="margin-left: 10px"
              size="small"
              icon="el-icon-plus"
              >添加</el-button
            >
            <import-file
              :importData="importData"
              @load="load"
              
            ></import-file> -->
          </div>
        </div>
        <div class="common-table-content btn-pagenation" ref="tableContent">
          <el-table
            ref="singleTable"
            class="table"
            :data="parameter.detailsList"
            style="width: 100%"
            :max-height="tableHeight"
            highlight-current-row
            :cell-style="{'text-align': 'center'}"
            :header-cell-style="{'text-align': 'center'}"
          >
            <el-table-column fixed type="index" width="55" label="序号" />

            <el-table-column
              label="企业物料编号"
              min-width="120"
              show-overflow-tooltip
              prop="matCode"
            >
            </el-table-column>
            <el-table-column
              label="平台物料编号"
              min-width="120"
              show-overflow-tooltip
              prop="matPlatcode"
            >
            </el-table-column>
            <el-table-column label="物料名称" min-width="110" prop="matName">
            </el-table-column>
            <el-table-column
              label="物料牌号"
              min-width="110"
              prop="matMaterial"
            >
            </el-table-column>
            <el-table-column
              label="数量"
              min-width="110"
              prop="matNum"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="最高限价(元)"
              min-width="120"
              prop="maximumPriceLimit"
            >
              <template slot="header">
                <!-- 表头名称 -->
                <div style="display: flex; align-items: center">
                  <span>最高限价(元)</span>
                  <el-tooltip class="item" effect="dark" placement="top">
                    <i class="el-icon-question" style="font-size: 16px"></i>
                    <!-- 悬停提示内容 -->
                    <div slot="content">
                      <div>单价最高限价，为0表示不限价</div>
                    </div>
                  </el-tooltip>
                </div>
              </template>
              <template slot-scope="scope">
                <el-input
                  type="Number"
                  v-model="scope.row.maximumPriceLimit"
                  placeholder="最高限价"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="需求日期" min-width="130" prop="demandDate">
            </el-table-column>
            <el-table-column label="计划编号" min-width="160" prop="planCode">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.planCode"
                  placeholder="计划编号"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column
              label="送货地址"
              min-width="180"
              prop="unloadAddress"
            >
              <template slot="header">
                <span class="required">*</span>送货地址
              </template>
              <template slot-scope="scope">
                <el-form-item
                  :prop="`detailsList.${scope.$index}.unloadAddress`"
                  :rules="rules.unloadAddress"
                  label-width="0px"
                  style="margin-bottom: 0px"
                >
                  <el-input
                    v-model="scope.row.unloadAddress"
                    @focus="openAddress(scope.$index)"
                    placeholder="请选择送货地址"
                    clearable
                    prefix-icon="el-icon-search"
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column
              label="企业补充说明"
              min-width="180"
              prop="remarks"
            >
              <template slot-scope="scope">
                <el-tooltip
                  width="250"
                  placement="top-start"
                  effect="light"
                  :content="scope.row.remarks"
                >
                  <el-input
                    clearable
                    :title="scope.row.remarks"
                    v-model="scope.row.remarks"
                    placeholder="请输入企业补充说明"
                  ></el-input>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column label="规格型号" min-width="130" prop="matSpec">
            </el-table-column>
            <el-table-column label="计量单位" min-width="80" prop="matUnit">
            </el-table-column>
            <el-table-column label="品牌/产地" min-width="100" prop="matBrand">
            </el-table-column>
            <el-table-column label="基础扩展" min-width="140" prop="matBaseExt">
            </el-table-column>
            <el-table-column
              label="其他扩展"
              min-width="140"
              prop="matOtherExt"
            >
            </el-table-column>
            <el-table-column label="税率" min-width="80" prop="taxRate">
            </el-table-column>

            <el-table-column
              label="挂账时间"
              min-width="100"
              prop="pendingTime"
            >
            </el-table-column>
            <el-table-column
              v-if="parameter.payMethod == 2"
              label="承兑时间"
              min-width="100"
              prop="acceptanceTime"
            >
            </el-table-column>
          </el-table>
        </div>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
      <el-button type="primary" :loading="saveing" @click="handleSave">{{
        $t('domestic.save')
      }}</el-button>
    </div>
    <!-- 物料明细 -->
    <purchaseMaterial
      @addDetail="addDetail"
      :useOrgList="methodUnitsList"
      ref="troubleshooting"
    />
    <!-- 地址弹窗 -->
    <addressDialog ref="address" @emit="getEmit"></addressDialog>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import purchaseMaterial from './purchaseMaterial.vue'
import procurementManagement from '@/api/procurementManagement'
import addressDialog from '@/components/dialog/addressDialog.vue'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb, purchaseMaterial, addressDialog},
  props: {
    editData: Object,
  },
  data() {
    return {
      importData: {
        title: '物料导入',
        templateName: '物料导入模板.xls',
        downloadUrl: '/../fvue/static/excel/采购制单明细导入.xlsx',
        importUrl:
          window.context.portal +
          '/bizPurchasingApplicationDetails/v1/excelToData',
        header: '物料导入',
      },
      tableHeight: 400,
      flexAuto: true,
      breadcrumbOpt: [{breadcrumbName: '采购制单'}, {breadcrumbName: '新增'}],
      saveing: false,
      dataList: [], //资质附件
      methodUnitsList: [],
      qualificationList: [],
      announcementList: [
        {
          label: '否',
          value: 0,
        },
        {
          label: '是',
          value: 1,
        },
      ],
      rules: {
        acceptanceTime: [
          {
            required: true,
            message: '请选择承兑时间',
            trigger: 'blur',
          },
        ],
        matNum: [
          {
            required: true,
            message: '请输入数量',
            trigger: 'blur',
          },
        ],
        isAnnouncement: [
          {
            required: true,
            message: '请选择是否公示',
            trigger: 'blur',
          },
        ],
        unloadAddress: [
          {
            required: true,
            message: '请选择送货地址',
            trigger: 'blur',
          },
        ],
        preparedOrgName: [
          {
            required: true,
            message: '请输入申请单位',
            trigger: 'blur',
          },
        ],
        preparedUserName: [
          {
            required: true,
            message: '请输入申请人',
            trigger: 'blur',
          },
        ],
        applicationDate: [
          {
            required: true,
            message: '请选择需求日期',
            trigger: 'blur',
          },
        ],
        applicationType: [
          {
            required: true,
            message: '请选择申请类型',
            trigger: 'blur',
          },
        ],
        procurementMethod: [
          {
            required: true,
            message: '请选择定价方式',
            trigger: 'blur',
          },
        ],
        matIfPlat: [
          {
            required: true,
            message: '请选择是否集中采购',
            trigger: 'blur',
          },
        ],
        isTax: [
          {
            required: true,
            message: '请选择报价方式',
            trigger: 'blur',
          },
        ],
        payMethod: [
          {
            required: true,
            message: '请选择付款方式',
            trigger: 'blur',
          },
        ],
        isAgencyProcure: [
          {
            required: true,
            message: '请选择是否代采',
            trigger: 'blur',
          },
        ],
        agencyProcureOrgName: [
          {
            required: true,
            message: '请选择代采企业',
            trigger: 'blur',
          },
        ],
      },
      procurementMethod: '',
      dateTime: '',
      loading: false,
      parameter: {
        preparedOrgName: '',
        preparedUserName: '',
        applicationDate: '',
        applicationType: '1',
        preparedUserId: '',
        isAnnouncement: 0,
        acceptanceTime: 6,
        planType: '',
        isTax: '1',
        isAgencyProcure: 0,
        agencyProcureOrgName: '',
        applicationNum: '',
        procurementMethod: '1',
        applicationSource: '1',
        pendingTime: 1,
        applicationSource: 1,
        remarks: '',
        detailsList: [],
        payMethod: '1',
        matIfPlat: '0',
        status: '1',
        qualificationList: [],
      },
      addressList: [],
      index: '',
    }
  },
  computed: {
    ...mapState({
      headers: (state) => {
        return {Authorization: `Bearer ${state.login.currentUser.token}`}
      },
      action: function () {
        return window.context.portal + '/biz/universal/v1/minioUpload'
      },
    }),
  },
  created() {
    this.addModifyBtn()
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    this.parameter.preparedOrgName = this.currentUser.org[0].orgName
    this.parameter.preparedOrgCode = this.currentUser.org[0].orgCode
    this.parameter.preparedUserId = this.currentUser.user.userId
    this.parameter.preparedOrgId = this.currentUser.org[0].orgId
    let moment = require('moment')
    this.parameter.applicationDate = moment().format('YYYY-MM-DD')
    this.dateTime = moment().format('YYYY-MM-DD')
    this.parameter.preparedDate = moment().format('YYYY-MM-DD')
    this.parameter.matIfPlat = this.$route.query.type
    this.getAddress()
  },
  mounted() {},
  methods: {
    getCode() {
      this.$http
        .get('${portal}/sys/identity/v1/getNextIdByAlias?alias=cgsq_sqdbh')
        .then((res) => {
          if (res.data.state) {
            this.parameter.applicationNum = res.data.value
          }
        })
    },
    getAddress() {
      let params = {
        pageBean: {
          pageSize: -1,
          page: -1,
        },
      }
      this.$http
        .post('${portal}/bizDeliveryAddress/v1/queryByPageOrg', params)
        .then((res) => {
          this.addressList = res.data.rows
        })
    },
    // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用,function(file, fileList)
    handleSuccess(res, file, fileList) {
      console.log(res, fileList)
      this.dataList.push(res.value)
    },
    //下载按钮回调
    downloadFile(name, url) {
      console.log(name, 'name')
      var a = document.createElement('a')
      var event = new MouseEvent('click')
      a.download = name
      a.target = '_blank'
      a.href = url
      a.dispatchEvent(event)
    },
    // 删除
    deleteHandle(index) {
      this.$confirm('是否确认删除该附件', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.dataList.splice(index, 1)
      })
    },
    // 打开资质标签弹窗
    handleOpen() {
      this.$refs.visible.add()
    },
    // 打开物料弹窗
    openDialog() {
      this.$refs.troubleshooting.add(this.parameter.matIfPlat)
    },
    changeZZ(val) {
      this.parameter.hasQualification = val
    },
    // 修改需求日期
    changeApplicationDate(val) {
      this.parameter.applicationDate = val
      if (this.parameter.detailsList.length != 0) {
        this.parameter.detailsList.forEach((item) => {
          item.demandDate = this.parameter.applicationDate
        })
      }
    },
    changePayMethod(val) {
      this.parameter.payMethod = val
    },
    changeAcceptanceTime(val) {
      this.parameter.acceptanceTime = val
      this.parameter.detailsList.forEach((item) => {
        item.acceptanceTime = val
      })
    },
    changeApplicationType(val) {
      this.parameter.applicationType = val
    },
    addDetail(list) {
      if (this.parameter.detailsList.length == 1) {
        this.parameter.detailsList = list
        this.parameter.detailsList.forEach((item, index) => {
          item['matId'] = item.id
          item.demandDate = this.parameter.applicationDate
          item['pendingTime'] = this.parameter.pendingTime
          item['acceptanceTime'] = this.parameter.acceptanceTime
          item.preparedDate = this.dateTime
          item['maximumPriceLimit'] = 0
          item['matIfPlat'] = this.parameter.matIfPlat
          item['unloadAddress'] = ''
          item.planCode = this.parameter.applicationNum + '-' + (index + 1)
        })
      } else {
        list.forEach((item, index) => {
          this.parameter.detailsList.push({
            matName: item.matName,
            matCode: item.matCode,
            matCode: item.matCode,
            matMaterial: item.matMaterial,
            matSpec: item.matSpec,
            matNum: item.matNum,
            matUnit: item.matUnit,
            procurementMethod: item.procurementMethod,
            matBrand: item.matBrand,
            preparedDate: this.dateTime,
            demandDate: this.parameter.applicationDate,
            matBaseExt: item.matBaseExt,
            matOtherExt: item.matOtherExt,
            planCode: this.parameter.applicationNum + '-' + (index + 1),
            id: item.id,
            matPlatcode: item.matPlatcode,
            acceptanceTime: this.parameter.acceptanceTime,
            taxRate: item.matTaxrate,
            matId: item.id,
            matIfPlat: this.parameter.matIfPlat,
            maximumPriceLimit: 0,
            unloadAddress: '',
            pendingTime: this.parameter.pendingTime,
            key: new Date(),
          })
        })
      }
      if (this.parameter.applicationType == 2) {
        this.parameter.detailsList.forEach((item) => {
          item.matNum = 1
        })
      }
      this.addressList.forEach((item) => {
        if (item.defaultStatus == 1) {
          this.parameter.detailsList.map((val) => {
            return (val.unloadAddress = item.enterpriseContactAddress)
          })
        }
      })
      this.methodUnitsList = this.parameter.detailsList
    },
    //列表删除行
    addTable() {
      this.parameter.detailsList.push({
        matName: '',
        matCode: '',
        matCode: '',
        matMaterial: '',
        matSpec: '',
        matNum: '',
        matUnit: '',
        procurementMethod: '',
        matBrand: '',
        demandDate: this.parameter.applicationDate,
        matBaseExt: '',
        preparedDate: this.dateTime,
        matOtherExt: '',
        id: '',
        taxRate: '',
        matId: '',
        key: new Date(),
      })
    },
    //列表删除行
    delTable(index, row) {
      this.parameter.detailsList.splice(index, 1)
    },
    handleOver() {
      this.flexAuto = !this.flexAuto
    },

    changeMatIfPlat(val) {
      this.parameter.matIfPlat = val
      this.parameter.detailsList.forEach((item) => {
        item['matIfPlat'] = val
      })
    },
    // 选择采购方式
    changeMethod(val) {
      this.procurementMethod = val
    },
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
        this.modifychoData(this.$route.query.editRows)
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
        this.getCode()
      }
    },
    //获取修改回显数据
    modifychoData(val) {
      this.loading = true
      procurementManagement
        .bizPurchasingApplicationSelectOne(val.id)
        .then((res) => {
          this.parameter = res.value
          this.dataList = this.parameter.accessoryList
          this.loading = false
          if (this.parameter.pendingTime == undefined) {
            this.parameter.pendingTime = ''
          }
        })
    },
    // 关闭//面包屑点击
    handleClose() {
      console.log(this.$route)
      if (this.$route.query.type == 1) {
        this.$router.push({
          name: 'procurementIntegration',
          params: {
            tabsActiveName: 'jcIntegration',
          },
        })
      } else {
        this.$router.push({
          name: 'procurementIntegration',
          params: {
            tabsActiveName: 'zcIntegration',
          },
        })
      }
      this.parameter = {}
    },
    // 保存
    handleSave() {
      this.parameter.accessoryList = this.dataList
      this.parameter.detailsList.forEach((item) => {
        item.procurementMethod = this.parameter.procurementMethod
        item['matCompanyName'] = this.parameter.preparedOrgName
        delete item.id
      })
      if(this.parameter.status == 8){
        this.parameter.status = '1'
      }
      this.$refs['formInfo'].validate((valid) => {
        if (valid) {
          this.saveing = true
          procurementManagement
            .bizPurchasingApplicationSaveOrUpdate(this.parameter)
            .then((res) => {
              this.saveing = false
              if (res.state) {
                this.$message.success(res.message)
                this.handleClose()
              }
            })
        }
      })
    },
    changeProcure(val) {
      if (val == 0) {
        this.parameter.agencyProcureOrgName = ''
        this.parameter.agencyProcureOrgCode = ''
        this.parameter.agencyProcureOrgId = ''
      }
      if (val == 1) {
        this.parameter.agencyProcureOrgName = '盛普物资有限公司'
        this.parameter.agencyProcureOrgCode = '00001513'
        this.parameter.agencyProcureOrgId = '1575018828683939840'
      }
    },
    changePendingTime(val) {
      this.parameter.pendingTime = val
      this.parameter.detailsList.forEach((item) => {
        item.pendingTime = this.parameter.pendingTime
      })
      this.$forceUpdate()
    },
    load(data) {
      console.log(data, '1')
      if (this.parameter.detailsList.length == 0) {
        this.parameter.detailsList = data
        this.parameter.detailsList.forEach((item) => {
          item.acceptanceTime = this.parameter.acceptanceTime
          item.pendingTime = this.parameter.pendingTime
          item.matIfPlat = this.parameter.matIfPlat
        })
      } else {
        data.forEach((item) => {
          this.parameter.detailsList.push({
            matName: item.matName,
            matCode: item.matCode,
            matCode: item.matCode,
            matMaterial: item.matMaterial,
            matSpec: item.matSpec,
            matNum: item.matNum,
            matUnit: item.matUnit,
            procurementMethod: item.procurementMethod,
            matBrand: item.matBrand,
            preparedDate: item.demandDateValue,
            demandDate: item.demandDate,
            matBaseExt: item.matBaseExt,
            matOtherExt: item.matOtherExt,
            id: item.id,
            matPlatcode: item.matPlatcode,
            remarks: item.remarks,
            acceptanceTime: this.parameter.acceptanceTime,
            taxRate: item.taxRate,
            matId: item.matId,
            matIfPlat: this.parameter.matIfPlat,
            maximumPriceLimit: item.maximumPriceLimit,
            unloadAddress: item.unloadAddress,
            pendingTime: this.parameter.pendingTime,
            key: new Date(),
          })
        })
      }
      this.addressList.forEach((item) => {
        this.parameter.detailsList.forEach((val) => {
          if (item.code == val.unloadAddress) {
            val.unloadAddress = item.enterpriseContactAddress
          }
        })
      })
    },
    openAddress(index) {
      this.index = index
      this.$refs.address.open()
    },
    getEmit(data) {
      console.log(data)
      if (data[0].sort == 1) {
        this.parameter.detailsList.forEach((item, index) => {
          if (this.index == index) {
            item.unloadAddress = data[0].enterpriseContactAddress
            return
          }
        })
      }
      if (data[0].sort == 2) {
        this.parameter.detailsList.forEach((item) => {
          item.unloadAddress = data[0].enterpriseContactAddress
        })
      }
      console.log(this.$refs.formInfo,1111111111111);
      delete this.$refs.formInfo.rules.unloadAddress
      this.$forceUpdate()
    },
  },
}
</script>

<style lang="scss" scoped>
.form-content {
  height: 100%;
}
.form-content1 {
  height: 400px !important;
}
.rows:first-of-type {
  cursor: pointer;
}
.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
.required {
  color: red;
  font-size: 14px;
  margin-right: 3px;
}

.row-flex {
  display: flex;
  flex-wrap: wrap;
}
.form-flex {
  /deep/.el-form-item__content {
    display: flex;
    align-items: center;
  }
}
.append {
  width: 10%;
  background-color: #f5f7fa;
  color: #909399;
  vertical-align: middle;
  display: table-cell;
  position: relative;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  padding: 0 10px;
  white-space: nowrap;
  text-align: center;
}
.table {
  /deep/.el-table .el-table__cell {
    padding: 0px;
  }
}
.auto {
  display: none;
}
.classNone {
  display: block;
}
/deep/.el-dialog {
  .el-dialog__headerbtn {
    .el-dialog__close {
      .el-icon {
        .el-icon-close {
          color: red !important;
        }
      }
    }
  }
}
.required {
  color: red;
  font-size: 14px;
  margin-right: 3px;
}
</style>
