<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-anjuan"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="auto"
        v-loading="loading"
        label-position="left"
      >
        <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="projectNumber">
                <el-input
                  readonly
                  v-model="parameter.projectNumber"
                  placeholder="请输入项目编号"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="项目标题" prop="noticeTitle">
                <el-input
                  readonly
                  v-model="parameter.noticeTitle"
                  placeholder="请输入项目标题"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="组织单位" prop="affiliatedOrgName">
                <el-input
                  readonly
                  v-model="parameter.affiliatedOrgName"
                  placeholder="请输入组织单位"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="采购单位" prop="procureOrgName">
                <el-input
                  readonly
                  v-model="parameter.procureOrgName"
                  placeholder="请选择采购单位"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item label="申请单号" prop="applicationNum">
                <el-tooltip
                  width="250"
                  placement="top-start"
                  effect="light"
                  :content="parameter.applicationNum"
                >
                <el-input
                  readonly
                  v-model="parameter.applicationNum"
                  placeholder="申请单号"
                >
                </el-input>
              </el-tooltip>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="是否集中采购" prop="matIfPlat">
                <dict-select
                  dictCode="cglx-ywlx"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.matIfPlat"
                  placeholder="请选择是否集中采购"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="采购类型" prop="procureType">
                <dict-select
                  dictCode="cglx-cglx"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.procureType"
                  placeholder="请选择采购类型"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="是否含税价" prop="isTax">
                <dict-select
                  dictCode="cglx-jjfs"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.isTax"
                  placeholder="请选择是否含税价"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24" style="display: flex; flex-wrap: wrap">
            <el-col :span="6">
              <el-form-item label="发布方式" prop="releaseMethod">
                <dict-select
                  dictCode="cglx-fbfs"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.releaseMethod"
                  placeholder="请选择发布方式"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6" key="2" v-if="parameter.releaseMethod == 2">
              <el-form-item
                label="供应商"
                prop="vendorName"
                class="input-select-item"
              >
              <el-tooltip
                  width="250"
                  placement="top-start"
                  effect="light"
                  :content="parameter.vendorName"
                >
                <el-input
                  readonly
                  v-model="parameter.vendorName"
                  placeholder="请选择供应商"
                >
                </el-input>
              </el-tooltip>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报价方式" prop="quotationMethod">
                <dict-select
                  dictCode="cglx-fkfs"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.quotationMethod"
                  placeholder="请选择报价方式"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                class="form-flex"
                label="挂账时间"
                prop="pendingTime"
              >
                <dict-select
                  dictCode="cdsj"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.pendingTime"
                  placeholder="请选择挂账时间"
                />
                <div class="append">月</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="有无保证金" prop="hasBond">
                <dict-select
                  dictCode="cglx-ywbzj"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.hasBond"
                  placeholder="请选择有无保证金"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="parameter.quotationMethod == 2">
              <el-form-item
                class="form-flex"
                label="承兑时间"
                prop="acceptanceTime"
              >
                <dict-select
                  dictCode="cdsj"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.acceptanceTime"
                  placeholder="请选择承兑时间"
                />
                <div class="append">月</div>
              </el-form-item>
            </el-col>

            <el-col :span="6" v-if="parameter.hasBond == 1">
              <el-form-item label="保证金（元）" prop="bond">
                <el-input
                  readonly
                  v-model="parameter.bond"
                  placeholder="请输入保证金"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                label="投标文件是否必传"
                prop="isBidDocumentsUpload"
              >
                <dict-select
                  dictCode="sfsctbwj"
                  :hasDefaultOption="true"
                  style="width: 100%"
                  v-model="parameter.isBidDocumentsUpload"
                  placeholder="请选择投标文件是否必传"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报价轮次" prop="quotationRounds">
                <el-input
                  readonly
                  v-model="parameter.quotationRounds"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报价模板" prop="quotationTemplateName">
                <el-input
                  readonly
                  v-model="parameter.quotationTemplateName"
                  placeholder="请选择报价模板"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="中标结果有效期（天）" prop="winBidValidity">
                <el-input
                  readonly
                  v-model="parameter.winBidValidity"
                  placeholder="请输入中标结果有效期（天）"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="立项联系人" prop="affiliatedUserName">
                <el-input
                  readonly
                  v-model="parameter.affiliatedUserName"
                  placeholder="请输入联系人"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="联系方式" prop="contactsPhone">
                <el-input
                  readonly
                  v-model="parameter.contactsPhone"
                  placeholder="请输入联系方式"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="this.parameter.procureType != 3">
              <el-form-item label="评标方式" prop="evaluationMode">
                <dict-select
                  dictCode="cglx-pbfs"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.evaluationMode"
                  placeholder="请选择评标方式"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="评标办法" prop="evaluationMethod">
                <dict-select
                  dictCode="cglx-pbff"
                  :hasDefaultOption="true"
                  readonly
                  style="width: 100%"
                  v-model="parameter.evaluationMethod"
                  placeholder="请选择评标方法"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="parameter.evaluationMethod == 2">
              <el-form-item label="评标人" prop="expertList">
                <el-input
                  readonly
                  type="areatext"
                  v-model="parameter.expertList"
                  placeholder="请选择评标人"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="投标开始时间" prop="biddingStartTime">
                <el-date-picker
                  readonly
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%"
                  v-model="parameter.biddingStartTime"
                  placeholder="请选择投标开始时间"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="投标结束时间" prop="biddingEndTime">
                <el-date-picker
                  readonly
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%"
                  v-model="parameter.biddingEndTime"
                  placeholder="请选择投标结束时间"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                label="澄清补遗截止时间"
                prop="clarificationSupplementDeadlineTime"
              >
                <el-date-picker
                  readonly
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%"
                  v-model="parameter.clarificationSupplementDeadlineTime"
                  placeholder="请选择澄清补遗截止时间"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                label="供货商提出问题的截止时间"
                prop="raisingQuestionsDeadlineTime"
              >
                <el-date-picker
                  readonly
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%"
                  v-model="parameter.raisingQuestionsDeadlineTime"
                  placeholder="请选择供货商提出问题的截止时间"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="响应截止时间" prop="responseTimeDeadline">
                <el-date-picker
                  readonly
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%"
                  v-model="parameter.responseTimeDeadline"
                  placeholder="请选择响应截止时间"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="项目内容" prop="establishmentName">
                <quill-editor
                  v-model="parameter.establishmentName"
                  style="height: 120px"
                  ref="myQuillEditor"
                  readonly
                >
                </quill-editor>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="rows" style="margin-top: 70px;margin-bottom: 0px;">
            <div class="rows-left">
              <div class="rows-hr"></div>
            </div>
            <div class="rows-title">
              <div class="text-overflow">
                <el-tabs v-model="activeName" @tab-click="handleClick">
                  <el-tab-pane label="招标文件" name="1"> </el-tab-pane>
                  <el-tab-pane label="评标信息" name="2" v-if="parameter.evaluationMethod==2"> </el-tab-pane>
                </el-tabs>
              </div>
            </div>
          </div>
          <div v-if="activeName == 1">
            <el-table
              class="down"
              :data="dataList"
              border
              stripe
              style="width: 100%"
            >
              <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>
          <div v-if="activeName == 2 && parameter.evaluationMethod == 2">
            <el-table
              :border="true"
              stripe
              fit
              size="mini"
              :key="activeName == 2"
              row-key="id"
              default-expand-all
              :data="scoreData"
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
            >
              <el-table-column
                prop="evaluationItemPname"
                min-width="100px"
                label="评分大项"
                class-name="el-table-lable-box"
                align="center"
                resizable
              >
                <template slot-scope="scope">
                  <div v-if="scope.row.children">
                    {{ scope.row.evaluationItemPname }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                label="评分细项"
                min-width="180"
                align="center"
                prop="evaluationItemCode"
              >
              </el-table-column>
              <el-table-column
                label="评分标准"
                min-width="180"
                align="center"
                prop="evaluationStandard"
              >
              </el-table-column>
              <el-table-column
                align="center"
                label="分值"
                min-width="140"
                prop="evaluationScore"
              >
              </el-table-column>
            </el-table>
          </div>
        </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>
            <!-- <import-file
              :importData="importData"
              @load="load"
              
            ></import-file> -->
          </div>
        </div>
        <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>
      </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'
import {quillEditor} from 'vue-quill-editor' //调用编辑器
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import {mapState} from 'vuex'
import basicData from '@/api/basicData'
import 'quill/dist/quill.bubble.css'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb, quillEditor},
  data() {
    return {
      saveing: false,
      bidList: [],
      activeList: [
        {
          value: 1,
          name: '招标文件',
        },
        {
          value: 2,
          name: '评分信息',
        },
      ],
      activeName: 1,
      centralizedData: [
        {name: '是', id: 1},
        {name: '否', id: 0},
      ],
      breadcrumbOpt: [{breadcrumbName: '采购立项'}, {breadcrumbName: '详情'}],
      expertList: [],
      dataList: [],
      fileList: [],
      loading: false,
      flexAuto: true,
      parameter: {
        detailsList: [],
      },
      addressList: [],
      scoreData:[]
    }
  },
  created() {
    this.selectTree()
    this.parameter = this.$route.query.detailRows
    this.detail(this.parameter.id)
    this.getAddress()
  },
  mounted() {},
  methods: {
    downloadFile(name, url) {
      var a = document.createElement('a')
      var event = new MouseEvent('click')
      a.download = name
      a.target = '_blank'
      a.href = url
      a.dispatchEvent(event)
    },
    // 获取送货地址分页
    getAddress() {
      let params = {
        pageBean: {
          pageSize: -1,
          page: -1,
        },
      }
      this.$http
        .post('${portal}/bizDeliveryAddress/v1/queryByPageOrg', params)
        .then((res) => {
          this.addressList = res.data.rows
        })
    },
    // 关闭//面包屑点击
    handleClose() {
      if (this.$route.query.type == 1) {
        this.$router.push({
          name: 'approvalProcurement',
          params: {
            tabsActiveName: 'collectiveApprovalProcurement',
          },
        })
      }
      if (this.$route.query.type == 0) {
        this.$router.push({
          name: 'approvalProcurement',
          params: {
            tabsActiveName: 'selfApprovalProcurement',
          },
        })
      }
      this.parameter = {}
    },
    //查询评标分类树结构
    selectTree() {
      basicData.bizEvaluationItemSelectTree().then((res) => {
        this.scoreData = res.value[0].children
        this.scoreData.forEach((item) => {
          item.evaluationItemPname = item.subjectName
        })
      })
    },
    handleOver() {
      this.flexAuto = !this.flexAuto
    },
    handleClick() {},
    getSqData(id){
      let params={
        pageBean:{
          page:-1,
          pageSize:-1
        },
        querys:[]
      }
      params.querys.push({
          group: 'main',
          operation: 'IN',
          parentGroup: '',
          property: 'id',
          relation: 'AND',
          value: id.split(','),
      })
      this.$http.post('${portal}/purchasingApplication/v1/curUserData',params).then(res=>{
        if(res.data.state){
          this.parameter.applicationNum = res.data.value.rows.map(item=>{
            return item.applicationNum
          }).join(',')
          this.$forceUpdate()
        }
      })
    },
    //详情
    detail(val) {
      this.loading = true
      procurementManagement.bizProjectApprovalSelectOne(val).then((res) => {
        this.loading = false
        this.parameter = res.value
        this.parameter.detailsList = res.value.detailsList
        if (this.parameter.zbDocument != undefined) {
          delete this.parameter.zbDocument.id
          this.dataList = this.parameter.zbDocument.accessoryList
        }
        this.parameter.expertList = []
        this.parameter.applicationNum = ''
        if (this.parameter.projectEvaluationExpertList) {
          this.parameter.expertList = this.parameter.projectEvaluationExpertList
            .map((item) => {
              return item.fullname
            })
            .join(',')
        }
        this.scoreData.forEach((item) => {
          item.evaluationItemPname = item.subjectName
          this.parameter.evaTemplate.descriptionList.forEach((val) => {
            if (item.id == val.evaluationItemPid) {
              item.children.push(val)
            }
          })
        })
        this.parameter.vendorName = this.parameter.approvalInviteVendorList
          .map((item) => {
            return item.vendorName
          })
          .join(',')
        this.addressList.forEach((item) => {
          this.parameter.detailsList.forEach((val) => {
            if (item.code == val.unloadAddress) {
              val.unloadAddress = item.enterpriseContactAddress
            }
          })
        })
        this.getSqData(this.parameter.purchasingApplicationId)
        this.$forceUpdate()
        if (this.parameter.byDocument != undefined) {
          let arr = []
          delete this.parameter.byDocument.id
          this.parameter.byDocument.forEach((item, index) => {
            if (item.accessoryList.length != 0) {
              item.accessoryList.forEach((val) => {
                val['describe'] = item.describe
                arr.push(val)
              })
            }
          })
          this.fileList = arr
        }
      })
    },
  },
}
</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;
}
/deep/.el-table-lable-box .cell{
  display: flex;
  justify-content: center;
}
::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;
    }
  }
}
.rows:first-of-type {
  cursor: pointer;
}
.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;
}
/deep/.el-tabs__header {
  padding: 0px;
}
</style>
