<!--
  @description:采购立项-供应商-正在参与项目
  @Modifier:gmy
  @routerPath:/proEnquiry/projectPaticipating // 询价
  @routerPath:/proSinglesource/projectPaticipating // 单一来源
  @routerPath:/proCompetitive/projectPaticipating //竞谈
  @routerPath:/proOurtcy/projectPaticipating // 竞价
  @date:2020/8/10-14:21
-->
<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="采购项目编号"
              class="el-form-item--three"
              prop="tenderNo"
            >
              <el-input
                v-model.trim="searchForm.tenderNo"
                placeholder="请输入采购项目编号"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item
              ref="tenderNo"
              label="采购项目名称"
              class="el-form-item--three"
              prop="tenderNo"
            >
              <el-input
                v-model.trim="searchForm.tenderName"
                placeholder="请输入采购项目名称"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--采购执行单位-->
            <el-form-item
              ref="projectBuyersName"
              label="采购执行单位"
              class="el-form-item--three"
              prop="projectBuyersName"
            >
              <el-input
                v-model.trim="searchForm.projectBuyersName"
                placeholder="请输入采购执行单位名称"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!--报价单号-->
            <!--            <el-form-item-->
            <!--              ref="negRecordCode"-->
            <!--              label="报价单号"-->
            <!--              class="el-form-item&#45;&#45;three"-->
            <!--              prop="negRecordCode"-->
            <!--            >-->
            <!--              <el-input-->
            <!--                v-model.trim="searchForm.negRecordCode"-->
            <!--                placeholder="请输入报价单号"-->
            <!--                style="width:15vw"-->
            <!--                @keyup.enter.native="onSearch"-->
            <!--              />-->
            <!--            </el-form-item>-->
            <!--报价截止时间-->
            <el-form-item
              label="报价截止时间"
            >
              <el-date-picker
                v-model="searchForm.quoteEndTimeBegin"
                :format="elValueFormatDate"
                :value-format="elValueFormatDate"
                type="date"
                placeholder="开始日期"
                style="width:15vw"
              />
              至
              <el-date-picker
                v-model="searchForm.quoteEndTimeEnd"
                :format="elValueFormatDate"
                :value-format="elValueFormatDate"
                type="date"
                placeholder="结束日期"
                style="width:15vw"
              />
            </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
            label="采购执行单位"
            min-width="180"
            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"
            label="报价截止日期"
            align="center"
            width="180"
          >
            <template slot-scope="scope">
              <p v-if="scope.row.quoteEndTime">
                {{ $Moment(scope.row.quoteEndTime).format(momentDateTime) }}
              </p>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="left"
            prop="negRecordCode"
            label="报价单号"
            min-width="180"
          />
          <!-- 仅在单一来源和竞谈是出现报价轮次字段 -->
          <el-table-column
            v-if="searchForm.tenderMethod==='12'||searchForm.tenderMethod==='13'"
            header-align="center"
            align="right"
            prop="stageNo"
            label="报价轮次"
            min-width="80"
          >
            <template slot-scope="scope">
              {{ scope.row.isLast === "01" && searchForm.tenderMethod !== "11" ? "最终轮" : scope.row.stageNo }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="报价状态"
            align="center"
            width="100"
          >
            <!-- offerStatus项目报价状态00 未报价 02 已报价可修改 01 查看报价 03 报价时间截止未报价 04 保存报价但是还未提交报价 05 新轮次淘汰 06 已报价不可修改  -->
            <template slot-scope="scope">
              <!-- <p>{{ filterDictText(quotationStatusList,scope.row.offerStatus) }}</p> -->
              <p>
                {{ scope.row.offerStatusStr }}
              </p>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            min-width="100"
          >
            <!-- showStartOffer 00 隐藏 01 显示开始报价  showSeeOffer 00 隐藏 01 显示查看报价 showModifyOffer00 隐藏 01 显示修改报价 -->
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.showStartOffer==='01'"
                :underline="false"
                size="mini"
                type="primary"
                width="120"
                @click="intoProject(scope.row)"
              >
                [开始报价]
              </el-link>
              <el-link
                v-if="scope.row.showSeeOffer==='01'"
                :underline="false"
                size="mini"
                type="primary"
                width="120"
                @click="intoProject(scope.row)"
              >
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.showModifyOffer==='01'"
                :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 { beingeInTheProjectPage } from '@/api/procurement/procurementProject' //  供应商报名可参与列表
import { getTime } from '@api/common/tools.js' // 获取服务器时间
import { updateIsFee } from '@/api/procurement/procurementSignup'
/* 公用方法*/
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 { procurementProjectGroupMixin } from '@/views/procurement/procurementProject/mixins/procurementProjectGroupMixin' // 立项采购-字典
import { procurementProjectMixins } from '@/views/procurement/procurementProject/mixins/procurementProjectMixins' // 立项采购-公用方法参数
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页

export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination // 分页
  },
  mixins: [
    ListMixin,
    commonMxin,
    initGroupMixin,
    procurementProjectGroupMixin,
    procurementProjectMixins
  ],
  data() {
    return {
      childenData: {
        dialog: false
      },
      loading: true,
      date: '',
      // 弹窗-展示/隐藏状态 true 展示/false 隐藏
      dialogData: {
        consignContractVisible: false // 供货范围
      },
      value: '',
      // 搜索
      searchForm: {
        tenderNo: '', // 采购项目编号
        tenderName: '', // 采购名称
        projectBuyersName: '', // 采购执行单位名称
        tenderMethod: this.$route.meta.tenderMethod, // 采购方式
        quoteEndTimeBegin: '', // 报价开始时间
        quoteEndTimeEnd: '', // 报价结束时间
        negRecordCode: '' // 报价单号
      },
      tableData: [],
      multipleSelection: [],
      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() // 查询条件
      beingeInTheProjectPage(params)
        .then(response => {
          this.loading = false
          this.tableData = response.data.results
          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.quoteEndTimeBegin = ''
      this.searchForm.quoteEndTimeEnd = ''
      this.searchForm.tenderMethod = this.$route.meta.tenderMethod // 清空采购方式
      // 获取列表信息
      this.loadData()
    },
    updateIsFee(val) {
      if (val) {
        // 获取列表信息
        this.loadData()
      }
    },
    // 进入项目
    intoProject(row) {
      // 获取当前时间
      // this.getCurrentTime()
      // const qouteEndTime = this.$Moment(row.quoteEndTime).format(this.momentSaveFormat) // 获取报价截止时间 转换到秒
      // this.currentTimes 当前时间 是否小于 qouteEndTime报价结束时间 返回 布尔值
      // const days = this.$Moment(this.currentTimes).isBefore(qouteEndTime)
      // tenderOrgMethod === '01' 委托采购（集采） 开始报价 未同意缴费
      if (row.tenderOrgMethod === '01' && row.showStartOffer === '01' && row.isFee !== '01') {
        this.patFeeData(row)
      } else {
        // 调用跳转路由方法
        this.routerPath(row)
      }
    },
    // 缴费弹框
    patFeeData(row) {
      this.$confirm(`各报价供应商:<p padding-left:5px">${row.feeDescription}</p>`, '收费声明', {
        confirmButtonText: '同意缴费',
        cancelButtonText: '不同意缴费',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        dangerouslyUseHTMLString: true,
        type: 'warning'
      }).then(() => {
        // 判断是否收取过缴费isFee 01 代表同意缴费 02不同意
        this.updateIsFeeData('01', row)
      }).catch(() => {
        // 判断是否收取过缴费isFee 01 代表同意缴费 02不同意
        this.updateIsFeeData('02', row)
      })
    },
    // 封装跳转路由方法
    routerPath(row) {
      const data = {
        tenderId: row.id, // 项目id
        packId: row.packId, // 标段id
        signUpId: row.signUpId, // 报名Id
        tenderMethod: row.tenderMethod // 采购方式 11 询价 12 单一来源 13竞争性谈判 14竞价
      }
      this.$router.push({
        path: '/procurement',
        name: 'procurementDriveSupplier',
        params: data
      })
    },
    // 进入项目方法
    updateIsFeeData(isFee, row) {
      const data = {
        isFee: isFee,
        signUpId: row.signUpId
      }
      updateIsFee(data).then(res => {
        if (isFee === '02') {
          this.$emit('updateIsFee', true)
        } else {
          this.routerPath(row)
        }
      }).catch(() => {})
    },
    // 获取当前时间
    getCurrentTime() {
      getTime().then(res => {
        this.currentTimes = res.data.time
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
