<!--
  @description:采购立项-供应商-已完成的项目
  @Modifier:gmy,lym
  @routerPath:/proEnquiry/projectCompleted // 询价
  @routerPath:/proSinglesource/projectCompleted // 单一来源
  @routerPath:/proCompetitive/projectCompleted //竞谈
  @routerPath:/proOurtcy/projectCompleted // 竞价
  @date:2020/6/11-18:27
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />
      已完成项目（{{ $route.meta.tenderMethodText }}）
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <div :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            :inline="true"
            label-width="98px"
            label-position="left"
          >
            <el-form-item
              ref="tenderNo"
              label="采购项目编号"
              label-width="60"
              class="el-form-item--three"
              prop="tenderNo"
            >
              <el-input
                v-model.trim="searchForm.tenderNo"
                placeholder="请输入采购项目编号"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item
              ref="tenderNo"
              label="采购项目名称"
              label-width="60"
              class="el-form-item--three"
              prop="tenderNo"
            >
              <el-input
                v-model.trim="searchForm.tenderName"
                placeholder="请输入采购项目名称"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item
              ref="tenderNo"
              label="是否中标"
              label-width="84px"
              class="el-form-item--three"
              prop="tenderNo"
            >
              <el-select v-model="searchForm.resultStatus" placeholder="请选择" style="width:15vw">
                <el-option
                  v-for="item in protprojectPurchaseResultStatusList"
                  :key="item.typename"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <!--采购执行单位-->
            <el-form-item
              ref="projectBuyersName"
              label="采购执行单位"
              class="el-form-item--three"
              prop="projectBuyersName"
            >
              <el-input
                v-model.trim="searchForm.projectBuyersName"
                placeholder="请输入采购执行单位名称"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--报价单号-->
            <el-form-item
              ref="negRecordCode"
              label="报价单号"
              class="el-form-item--three"
              prop="negRecordCode"
            >
              <el-input
                v-model.trim="searchForm.negRecordCode"
                placeholder="请输入报价单号"
                style="width:15vw"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </div>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <!--响应内容-->
      <div>
        <el-table
          ref="smallTable"
          :data="tableData"
          class="tableLimit procurement_table"
          width="100%"
        >
          <el-table-column
            header-align="center"
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column header-align="center" align="left" label="采购项目编号/名称" min-width="230">
            <template slot-scope="scope">
              <p>{{ scope.row.tenderNo }}</p>
              <p>{{ scope.row.tenderName }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="projectBuyersName"
            label="采购执行单位"
            min-width="200"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                <!-- 采购单位多出省略 -->
                {{ procurementUnitOmit(scope.row.projectBuyersName) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column header-align="center" label="采购方式" width="120" align="center">
            <template slot-scope="scope">
              <p>{{ filterDictText(tendermethodList,scope.row.tenderMethod ) }}</p>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="left"
            prop="negRecordCode"
            label="报价单号"
            min-width="150"
          />
          <el-table-column header-align="center" label="是否流标" prop="isFlowStandard" align="center" width="80" />
          <el-table-column
            header-align="center"
            align="center"
            prop="purchaseProjectStatus"
            label="终止采购"
            min-width="80"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.purchaseProjectStatus === '05'">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="$route.meta.tenderMethod!=='12'"
            header-align="center"
            label="过期未接受"
            width="100"
            align="center"
          >
            <template slot-scope="scope">
              <p>{{ filterDictText(isAcceptArr,scope.row.isAccept ) }}</p>
            </template>
          </el-table-column>
          <el-table-column header-align="center" label="是否中标" align="center" width="80">
            <template
              slot-scope="scope"
            >
              {{ filterDictText(protprojectPurchaseResultStatusList,scope.row.resultStatus) }}
            </template>
          </el-table-column>
          <el-table-column header-align="center" label="操作" align="center" width="80">
            <template slot-scope="scope">
              <el-link
                :underline="false"
                size="mini"
                type="primary"
                width="120"
                @click="intoProject(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </div>
    </section>
  </div>
</template>
<script>
/* 接口*/
import { finishTheProjectPage } from '@/api/procurement/procurementProject' //  供应商报名可参与列表
/* 公用方法*/
import { filterObj, filterDictText, restoreInitialValue } from '@/assets/js/utils' // 常用方法
import { procurementUnitOmit } from '@/assets/js/procurement'

/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { initGroupMixin } from '@/mixins/initGroupMixin' // 字典信息
import { commonMxin } from '@/mixins/commonMxin' // 字典信息
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
/* 混合开发*/
import { procurementProjectGroupMixin } from '../mixins/procurementProjectGroupMixin' // 立项采购-字典
import { procurementProjectMixins } from '../mixins/procurementProjectMixins' // 立项采购-公用方法参数

export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination // 分页
  },
  mixins: [
    ListMixin,
    commonMxin,
    initGroupMixin,
    procurementProjectGroupMixin,
    procurementProjectMixins
  ],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        tenderNo: '', // 采购项目编号
        tenderName: '', // 采购名称
        tenderMethod: this.$route.meta.tenderMethod, // 采购方式
        resultStatus: '', // 是否中标
        projectBuyersName: '', // 采购执行单位
        negRecordCode: '' // 报价单号
      },
      tableData: [],
      projectBuyersName: '' // 采购单位
    }
  },
  watch: {
    // 监听路由meta中tenderMethod值的变化
    '$route.meta.tenderMethod': {
      handler(newVal, oldVal) {
        this.searchForm.tenderMethod = newVal
        this.loadData()
      },
      deep: true
    }
  },
  created() {
    // 查询项目状态
    this.inCodes()
    // 字典信息
    this.initWebTypeGroup()
    // 获取列表信息
    this.loadData()
  },
  methods: {
    filterDictText,
    procurementUnitOmit,
    // 获取数据
    loadData() {
      const params = this.getQueryParams() // 查询条件
      finishTheProjectPage(params)
        .then(response => {
          this.loading = false
          this.paginationData.total = response.data.total
          this.tableData = response.data.records
        })
        .catch(() => {})
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      restoreInitialValue(this.searchForm) // 清空表单数据
      this.searchForm.tenderMethod = this.$route.meta.tenderMethod
      // 获取列表信息
      this.loadData()
    },
    // 进入项目
    intoProject(row) {
      // 判断是否为过期未接受 isAccept字符串 01为是 00 否，仅针对采购方式为邀请类的 tenderType00 公开 01 邀请
      if (row.isAccept === '01' && row.tenderType === '01') {
        // 判断采购方式为询价和竞谈
        if (row.tenderMethod === '11' || row.tenderMethod === '13') {
          this.$router.push({
            path: '/procurement/invitation',
            query: {
              packId: row.packId, // 标段id
              tenderMethod: row.tenderMethod, // 采购方式
              typeTage: '01' // 自定义属性01代表是从已完成项目前往的查看邀请函列表
            }
          })
          return
        }
      }
      // 判断是否为过期未接受 isAccept字符串 00 代表否 可以进入驱动
      this.$router.push({
        path: '/procurement',
        name: 'procurementDriveSupplier',
        params: {
          packId: row.packId, // 标段id
          signUpId: row.signUpId, // 报名Id
          tenderMethod: row.tenderMethod, // 采购方式
          type: '01' // 已完成项目进入驱动
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
