<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"
      >
        <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="applicationType">
                <dict-select
                  dictCode="cgsq-sqlx"
                  :hasDefaultOption="true"
                  clearable
                  disabled
                  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%"
                  v-model="parameter.applicationDate"
                  value-format="yyyy-MM-dd"
                  type="date"
                  disabled
                  placeholder="选择需求日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="定价方式" prop="procurementMethod">
                <dict-select
                  dictCode="cgsq-djfs"
                  :hasDefaultOption="true"
                  clearable
                  disabled
                  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%"
                  v-model="parameter.matIfPlat"
                  placeholder="请选择是否集中采购"
                /> </el-form-item
            ></el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item label="报价方式" prop="isTax">
                <dict-select
                  dictCode="cgsq-bjfs"
                  :hasDefaultOption="true"
                  clearable
                  disabled
                  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
                  disabled
                  style="width: 100%"
                  v-model="parameter.payMethod"
                  placeholder="请选择付款方式"
                />
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item
                label="挂账时间"
                class="form-flex"
                prop="pendingTime"
              >
                <dict-select
                  dictCode="cdsj"
                  :hasDefaultOption="true"
                  clearable
                  disabled
                  style="width: 100%"
                  v-model="parameter.pendingTime"
                  placeholder="请选择挂账时间"
                />
                <div class="append">月</div>
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="parameter.payMethod == 2">
              <el-form-item
                label="承兑时间"
                class="form-flex"
                prop="acceptanceTime"
              >
                <dict-select
                  dictCode="cdsj"
                  :hasDefaultOption="true"
                  clearable
                  disabled
                  style="width: 100%"
                  v-model="parameter.acceptanceTime"
                  placeholder="请选择承兑时间"
                />
                <div class="append">月</div>
              </el-form-item>
            </el-col>
          </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>
          <el-table
            class="down"
            :data="parameter.accessoryList"
            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>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <el-form ref="formInfo" class="form-content1" :model="parameter">
        <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>
          </div>
        </div>
        <div class="common-table-content btn-pagenation" ref="tableContent">
          <el-table
            ref="singleTable"
            class="table"
            :data="parameter.detailsList"
            style="width: 100%"
            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="110"
              prop="maximumPriceLimit"
            >
            </el-table-column>
            <el-table-column label="需求日期" min-width="130" prop="demandDate">
            </el-table-column>
            <el-table-column label="计划编号" min-width="100" prop="planCode">
            </el-table-column>
            <el-table-column
              label="送货地址"
              min-width="180"
              prop="unloadAddress"
            >
            </el-table-column>
            <el-table-column
              label="企业补充说明"
              min-width="180"
              prop="remarks"
            >
            </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>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import procurementManagement from '@/api/procurementManagement'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb},
  data() {
    return {
      breadcrumbOpt: [{breadcrumbName: '采购申请'}, {breadcrumbName: '详情'}],
      parameter: {},
      flexAuto: true,
      loading: false,
      applicationSourceList: [
        {
          label: '手工录入',
          value: '1',
        },
        {
          label: '数据集成',
          value: '2',
        },
      ],
      addressList: [],
    }
  },
  created() {
    this.parameter = this.$route.query.detailRows
    this.detail(this.parameter.id)
    this.getAddress()
  },
  mounted() {},
  methods: {
    // 关闭//面包屑点击
    handleClose() {
      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 = {}
    },
    handleOver() {
      this.flexAuto = !this.flexAuto
    },
    getAddress() {
      let params = {
        pageBean: {
          pageSize: -1,
          page: -1,
        },
      }
      this.$http
        .post('${portal}/bizDeliveryAddress/v1/queryByPageOrg', params)
        .then((res) => {
          this.addressList = res.data.rows
        })
    },
    //详情
    detail(val) {
      this.loading = true
      procurementManagement
        .bizPurchasingApplicationSelectOne(val)
        .then((res) => {
          res.value.applicationSource = this.applicationSourceList.filter(
            (item) => item.value == res.value.applicationSource
          )[0].label
          this.parameter = res.value
          this.loading = false
          this.addressList.forEach((item) => {
            this.parameter.detailsList.forEach((val) => {
              if (item.code == val.unloadAddress) {
                val.unloadAddress = item.enterpriseContactAddress
              }
            })
          })
        })
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep .el-form-item__label {
  width: 120px;
  font-size: 14px;
  color: #828282;
  font-weight: 500;
}

::v-deep .el-form-item__content span {
  font-size: 14px;
  color: #000;
  font-weight: 500;
}

::v-deep .el-form-item {
  margin-bottom: 10px;
}
.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;
    }
  }
}
.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;
}
.auto {
  display: none;
}
.classNone {
  display: block;
}
</style>
