<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      title="选择评标办法"
      :visible.sync="showTroubleshooting"
      width="60%"
      :close-on-press-escape="false"
      :before-close="handleClose"
      top="10vh"
    >
      <template>
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="综合评标法" name="综合评标法">
            <div class="bbsl-table-search">
              <el-form v-model="queryParam" :inline="true">
                <el-form-item label="使用单位">
                  <el-input
                    size="small"
                    v-model="querys[1].value"
                    clearable
                    placeholder="请输入使用单位"
                  ></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button
                    size="small"
                    type="danger"
                    icon="el-icon-search"
                    @click="handleSearch"
                    >搜索</el-button
                  >
                  <el-button
                    size="small"
                    icon="el-icon-refresh"
                    @click="handleReset"
                    >重置</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <el-table
              ref="multipleSelection"
              v-loading="loading"
              border
              size="mini"
              :data="tableData"
              :style="{width: '100%'}"
              :max-height="tableMaxHeight"
              :cell-style="{'text-align': 'center'}"
              :header-cell-style="{'text-align': 'center'}"
              @selection-change="handleSelectionChange"
              v-if="activeName === '综合评标法'"
            >
              <el-table-column type="selection" width="55" />
              <el-table-column
                prop="code"
                min-width="10%"
                label="编号"
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="preparedOrgName"
                min-width="10%"
                label="编制单位"
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="orgs"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="使用单位"
                resizable
              >
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="评标方式"
                resizable
              >
                <template v-slot="{row}">
                  {{
                    row.evaluatingMethods == 1 ? '综合评标法' : '最低价评标法'
                  }}
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="最低价评标法" name="最低价评标法">
            <div class="bbsl-table-search">
              <el-form v-model="queryParam" :inline="true">
                <el-form-item label="使用单位">
                  <el-input
                    size="small"
                    v-model="querys[1].value"
                    clearable
                    placeholder="请输入使用单位"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    size="small"
                    type="danger"
                    icon="el-icon-search"
                    @click="handleSearch"
                    >搜索</el-button
                  >
                  <el-button
                    size="small"
                    icon="el-icon-refresh"
                    @click="handleReset"
                    >重置</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <el-table
              ref="multipleSelection"
              v-loading="loading"
              border
              size="mini"
              :data="tableData"
              :style="{width: '100%'}"
              :max-height="tableMaxHeight"
              :cell-style="{'text-align': 'center'}"
              :header-cell-style="{'text-align': 'center'}"
              @selection-change="handleSelectionChange"
              v-if="activeName === '最低价评标法'"
            >
              <el-table-column type="selection" width="55" />
              <el-table-column
                prop="code"
                min-width="10%"
                label="编号"
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="preparedOrgName"
                min-width="10%"
                label="编制单位"
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="orgs"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="使用单位"
                resizable
              >
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="评标方式"
                resizable
              >
                <template v-slot="{row}">
                  {{
                    row.evaluatingMethods == 1 ? '综合评标法' : '最低价评标法'
                  }}
                </template>
              </el-table-column>
              <el-table-column
                prop="description"
                show-overflow-tooltip
                min-width="15%"
                align="center"
                label="评标说明"
                resizable
              >
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSave">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {TableMixin} from '@/mixins/tableMixin'
// import nineLittlePlaceApi from '@/views/Manage/saftyDanger/api/nineLittlePlaceApi'
export default {
  name: 'CmgtSaftyDangerCheckplanFormDialogTroubleshooting', // 排查计划明细
  props: {
    // echoValue: {
    //   type: Object,
    //   default: ''
    // }
  },
  data() {
    return {
      tableMaxHeight: 400,
      showTroubleshooting: false, // 控制弹层显示与隐藏
      activeName: '综合评标法',
      tableData: [],
      loading:false,
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'useOrgId',
          relation: 'AND',
          value: ''
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'small_place_area_',
          relation: 'AND',
          value: ''
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'EVALUATING_METHODS_',
          relation: 'AND',
          value: '1'
        }
      ],
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20
        }
      },
      checkedGh: '',
      sorter: [
        {
          direction: 'DESC',
          property: 'createTime'
        }
      ] // 排序数据
    }
  },
  mixins: [TableMixin],
  created() {},
  methods: {
    // 单选框选中数据
    handleSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.multipleSelection.clearSelection()
        this.$refs.multipleSelection.toggleRowSelection(selection.pop())
      }
      this.multipleSelection = selection
    },
    loadData() {},
    //搜索
    handleSearch() {
      this.getData()
    },
    //重置
    handleReset() {
      this.getData()
    },
    //显示弹框
    add(row) {
      console.log(row,11111111);
      this.showTroubleshooting = true
      this.querys[0].value = row
      // if (this.echoValue.id) {
      //   this.$nextTick(function() {
      //     this.$refs.multipleSelection.toggleRowSelection(this.echoValue)
      //   })
      // }
      this.getData()
    },
    // 切换tab选项
    handleClick(tab, event) {
      this.activeName = event.target.innerText
      // if (this.echoValue.id) {
      //   this.$nextTick(function() {
      //     this.$refs.multipleSelection.toggleRowSelection(this.echoValue)
      //   })
      // }
      // this.querys = this.$options.data().querys
      this.getData()
    },
    // 获取list
    getData(page) {
      if (page) {
        this.queryParam.pageBean.page = page
      }
      // 不分页
      this.queryParam.pageBean.pageSize = -1
      this.loading = true
      this.tableData = []
      this.queryParam.querys = []
      this.queryParam.sorter = this.sorter
      if (this.activeName === '综合评标法') {
        if (this.querys[0].value) {
          this.queryParam.querys.push(this.querys[0])
        }
        if (this.querys[1].value) {
          this.queryParam.querys.push(this.querys[1])
        }
        this.querys[2].value = 1
        this.queryParam.querys.push(this.querys[2])
      } else if (this.activeName === '最低价评标法') {
        if (this.querys[0].value) {
          this.queryParam.querys.push(this.querys[0])
        }
        this.querys[2].value = 2
        this.queryParam.querys.push(this.querys[2])
      }
      this.$http
        .post('${portal}/bizEvaluationSystem/v1/pageByUseOrg', this.queryParam)
        .then(res => {
          console.log(res, 'resssss')
          this.total = res.data.value.total
          this.tableData = res.data.value.rows
          this.tableData.forEach(item => {
            item.orgs = item.orgs
              .map(item => {
                return item.name
              })
              .join(',')
          })
          // this.tableData.forEach(item => {
          //   this.jxcspqList.forEach(val => {
          //     if (item.smallPlaceArea == val.value) {
          //       item['smallPlaceAreaName'] = val.name
          //     }
          //   })
          // })
          this.loading = false
          this.$set(this.tableData)
        })
    },
    // 重置
    clearQuerys() {
      this.querys[0].value = ''
      this.querys[1].value = ''
    },
    // 点击关闭按钮
    handleClose() {
      this.$refs.multipleSelection.clearSelection()
      this.showTroubleshooting = false
    },
    // 保存按钮
    handleSave() {
      this.$emit('addDetail', this.multipleSelection[0])
      this.handleClose()
    }
  }
}
</script>

<style scoped lang="scss"></style>
