<template>
  <div class="common-page-shadow">
    <div class="common-search-container" ref="contentPanel">
      <el-form
        ref="form"
        label-position="right "
        :inline="true"
        type="flex"
        justify="left"
      >
        <el-form-item label="项目名称">
          <el-input
            size="small"
            v-model="querys[3].value"
            clearable
            placeholder="请输入项目名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="定标状态">
          <dict-select
            dictCode="dbgl-dbzt"
            :hasDefaultOption="true"
            clearable
            size="small"
            v-model="querys[2].value"
            placeholder="请选择定标状态"
          />
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
            size="small"
            v-model="querys[4].value"
            type="datetimerange"
            start-placeholder="开始日期"
            @change="changeTime"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="container-btn">
        <el-button
          size="small"
          icon="el-icon-search"
          type="danger"
          class="btn btn-plus"
          @click="handleSearch"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          icon="el-icon-refresh-right"
          class="btn btn-plus"
          @click="clearSearchForm"
        >
          重置
        </el-button>
      </div>
    </div>
    <el-row
      class="common-table-container flex searchPanel"
      :style="SearchPanel"
    >
      <el-col :span="24" class="common-table-wrapper">
        <div class="common-btn-group">
          <el-button
            size="small"
            icon="el-icon-thumb"
            type="primary"
            :disabled="!currentDataDel.length"
            class="btn btn-plus"
            :loading="loading"
            v-if="querys[2].value == 0"
            @click="handleCalibration"
          >
            定标
          </el-button>
        </div>
        <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
        <div class="common-table-content btn-pagenation">
          <el-table
            :border="true"
            stripe
            fit
            size="mini"
            v-loading="tableLoading"
            height="100%"
            ref="multipleSelection"
            :data="tableData"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              min-width="50px"
              align="center"
            ></el-table-column>
            <el-table-column
              type="index"
              width="55"
              align="center"
              label="序号"
            >
            </el-table-column>
            <el-table-column
              prop="noticeCode"
              min-width="100px"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeTitle"
              show-overflow-tooltip
              min-width="130px"
              align="center"
              label="项目名称"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="procureOrgName"
              show-overflow-tooltip
              min-width="130px"
              align="center"
              label="采购单位"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="procureType"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="采购类型"
              resizable
            >
              <template v-slot="{row}">
                <div v-if="row.procureType != 6">
                  {{ getDictName('cglx-cglx', row.procureType) }}
                </div>
                <div v-else>谈判采购（多轮）</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="evaluationMethod"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="评标方法"
              resizable
            >
            <template slot-scope="scope">
                <span v-if="scope.row.evaluationMethod == 2"
                  >综合评标法</span
                >
                <span v-if="scope.row.evaluationMethod == 1"
                  >最低评标法</span
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="biddingStartTime"
              show-overflow-tooltip
              min-width="130px"
              align="center"
              label="投标开始时间"
              resizable
            >
            </el-table-column>
            
            <el-table-column
              prop="calibraStatus"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="定标状态"
              resizable
            >
              <template slot-scope="scope">
                <el-tag v-if="scope.row.calibraStatus == 2" type="success"
                  >已定标</el-tag
                >
                <el-tag v-if="scope.row.calibraStatus == 1" type=""
                  >审核中</el-tag
                >
                <el-tag v-if="scope.row.calibraStatus == 0" type="info"
                  >未定标</el-tag
                >
              </template>
            </el-table-column>
            <el-table-column min-width="120px" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    type="primary"
                    plain
                    icon="el-icon-view"
                    size="small"
                    @click="quoteConfirm(row)"
                    >评标查看</el-button
                  >
                </template>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="common-pagenation">
          <el-pagination
            ref="paginationPanel"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryParam.pageBean.page"
            :page-sizes="[20, 30, 40, 50]"
            :page-size="queryParam.pageBean.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="queryParam.pageBean.total"
          >
          </el-pagination>
        </div>
      </el-col>
    </el-row>
    <!-- 流程弹窗 -->
    <purchaseDialog ref="flowDialog" @reload="loadData()"></purchaseDialog>
  </div>
</template>

<script>
import pagination from '@/components/pagination'
import {TableMixin} from '@/mixins/tableMixin'
import purchaseDialog from '../module/flowDialog.vue'
import req from '@/request.js'
import utils from '@/utils.js'

const portal = window.context.portal
export default {
  name: 'DemandEntry',
  components: {
    pagination,
    purchaseDialog,
  },
  mixins: [TableMixin],
  data() {
    return {
      currentPage: 1,
      tableMaxHeight: 400,
      loading: false,
      tableLoading: false,
      tableData: [],
      multipleSelection: [],
      querys: [
        {
          group: 'mains',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'bidStatus',
          relation: 'AND',
          value: '6',
        },
        {
          group: 'mains',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'bidStatus',
          relation: 'OR',
          value: '10',
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'calibraStatus',
          relation: 'AND',
          value: '0',
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'noticeTitle',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'BETWEEN',
          parentGroup: '',
          property: 'biddingEndTime',
          relation: 'AND',
          value: '',
        },
      ],
      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
      },
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
      },
      fileList: [], // 文件上传
      currentDataDel: [], // 删除时排查是否有在审核的数据\
      showApproval: false,
    }
  },
  mounted() {},
  created() {
    this.loadData()
    this.getAlias()
  },
  methods: {
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    //评标确认
    quoteConfirm(rows) {
      if (rows.evaluationMethod == 1 || rows.evaluationMethod == 2) {
        this.$router.push({
          path: `/procurementProjectConfirm/${rows.id}`,
          query: {evaluationMethod: rows.evaluationMethod, rows},
        })
      }
      if (rows.evaluationMethod == 2 && rows.evaluationMode == 2) {
        this.$router.push({
          path: `/procurementProjectBid/${rows.id}`,
          query: {rows},
        })
      }
    },
    //获取数据
    loadData() {
      this.tableLoading = true
      this.queryParam.querys = []
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }
      if (this.querys[1].value) {
        this.queryParam.querys.push(this.querys[1])
      }
      if (this.querys[2].value) {
        this.queryParam.querys.push(this.querys[2])
      }
      if (this.querys[3].value) {
        this.queryParam.querys.push(this.querys[3])
      }
      if (this.querys[4].value) {
        this.queryParam.querys.push(this.querys[4])
      }
      this.queryParam.sorter = [
        {
          direction: 'DESC',
          property: 'create_time_',
        },
      ]
      this.$http
        .post('${portal}/projectApproval/v1/pageCurUser', this.queryParam)
        .then((res) => {
          console.log(res, 'resss')
          this.tableLoading = false
          if (res.data.state) {
            this.tableData = res.data.value.rows || []
            this.queryParam.pageBean = {
              page: res.data.value.page,
              pageSize: res.data.value.pageSize,
              total: res.data.value.total,
            }
          }
        })
    },
    getAlias() {
      let params = {
        pageBean: {
          page: -1,
          pageSize: -1,
        },
        querys: [],
      }
      params.querys.push({
        group: 'main',
        operation: 'EQUAL',
        parentGroup: '',
        property: 'a.APPROVAL_MENU_ALIAS_',
        relation: 'AND',
        value: this.$route.matched[1].instances.default.aliasPath[0].alias,
      })
      this.$http
        .post('${portal}/purchasingRulesDetail/v1/pageAllByOrg', params)
        .then((res) => {
          if (res.data.state) {
            let data = res.data.value.rows
            if (data.length != 0) {
              this.showApproval = true
            } else {
              this.showApproval = false
            }
          }
        })
    },
    // 定标
    handleCalibration() {
      if (this.showApproval == true) {
        this.$confirm('是否定标选中数据？', '提示', {
          confirmButtonText: '确 定',
          cancelButtonText: '取 消',
          type: 'warning',
        }).then(() => {
          this.loading = true
          this.$http
            .post(
              '${portal}/projectApproval/v1/modifyCalibraStatus?ids=' +
                this.currentDataDel[0].id +
                '&status=2'
            )
            .then((res) => {
              console.log(res)
              this.loading = false
              if (res.data.state) {
                this.$message.success(res.data.message)
                this.loadData()
              }
            })
        })
      } else {
        this.$refs.flowDialog.handleOpen(this.currentDataDel)
      }
    },
    // 顶部搜索
    handleSearch() {
      this.loadData()
    },
    // 重置
    clearSearchForm() {
      this.querys[0].value = '6'
      this.querys[1].value = '10'
      this.querys[2].value = '0'
      this.querys[3].value = ''
      this.querys[4].value = ''
      this.loadData()
    },
    handleSelectionChange(currentData) {
      this.currentDataDel = currentData
      if (this.currentDataDel.length > 1) {
        this.$refs.multipleSelection.toggleRowSelection(
          this.currentDataDel[0],
          false
        )
      }
    },
    handleCurrentChange(page) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, page}
      this.loadData()
    },
    handleSizeChange(pageSize) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
      this.loadData()
    },
    changeTime(val) {
      this.querys[4].value = val
    },
  },
  computed: {
    SearchPanel() {
      return {
        '--searchPanel': this.searchPanel + 'px',
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.common-table-content.btn-pagenation {
  height: calc(100% - 100px);
}
.cloumn-btn {
  border: 1px solid #2761ff;
  padding: 3px 10px;
  border-radius: 5px;
  &:nth-child(1) {
    margin-right: 5px;
  }
  &:nth-child(2) {
    margin-right: 5px;
  }
  &:nth-child(1):hover {
    background-color: #2761ff;
    color: #fff;
  }
  &:nth-child(2):hover {
    background-color: #2761ff;
    color: #fff;
  }
  // &:nth-child(2):hover {
  //   background-color: #f56c6c;
  //   color: #fff;
  //   border-color: #f56c6c;
  // }
  /deep/ i,
  span {
    font-size: 16px;
  }
}

/deep/ .el-tree-node__content {
  padding: 5px 0;
}

/deep/ .el-table thead tr th {
  background-color: #eee !important;
  border-right: 1px solid #dfe2e8 !important;
}
/deep/ .el-table {
  border-collapse: collapse !important;
}
</style>
