<template>
  <el-dialog
    title="选择"
    :visible.sync="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body

    width="80%"
  >
    <search-quotation @search="reload"> </search-quotation>
    <ele-pro-table
      ref="table"
      :columns="columns"
      :datasource="datasource"
      row-key="id"
      height="calc(100vh - 350px)"
      @cell-click="cellClick"

      class="dict-table"
    >
      <!-- 表头工具栏 -->
      <template v-slot:action="{ row }">
        <el-radio class="radio" v-model="radio" :label="row.planCode"
          ><i></i
        ></el-radio>
      </template>
      <!-- 状态 -->
      <template v-slot:status="{ row }">
        {{ getStatus(row.status) }}
      </template>
    </ele-pro-table>

    <div class="btns">
      <el-button type="primary" size="small" @click="selected">选择</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { getTableList } from '@/api/bpm/components/purchasingManage/purchasePlanManage';
  import searchQuotation from './searchQuotation.vue';
  export default {
    components: {
      searchQuotation
    },

    data() {
      return {
        visible: false,
        currentIndex: null,
        list: [],
        columns: [
          {
            action: 'action',
            slot: 'action',
            align: 'center',
            label: '选择'
          },
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'planCode',
            slot: 'planCode',

            label: '采购计划编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'requirementCode',
            label: '采购需求编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'requireDeptName',
            label: '需求部门',
            align: 'center',
            slot: 'requireDeptName',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'requireUserName',
            label: '需求人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'responsibleName',
            label: '负责人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'detailCount',
            label: '明细条数',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },

          {
            prop: 'finishDate',
            label: '完成日期',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 140
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 180
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            slot: 'status',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'remark',
            label: '备注',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 170
          }
        ],

        radio: null
      };
    },
    watch: {},
    methods: {
      open(planCode) {
        //数据回显
        if (planCode) {
          this.radio = planCode;
          if (this.list.length > 0) {
            this.current = this.list.find(
              (item) => item.planCode == this.radio
            );
          }
        }
        this.visible = true;
      },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getTableList({
          pageNum: page,
          size: limit,
          status: 2,
          ...where
        }).then((res) => {
          this.current = res.list.find((item) => item.planCode == this.radio);
          this.list = res.list;

          return res;
        });
      },

      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ pageNum: 1, where: where });
      },

      handleNodeClick(data, node) {
        this.curNodeData = data;
        this.reload({ categoryLevelId: data.planCode });
      },

      // 单击获取id
      cellClick(row) {
        this.current = row;
        this.radio = row.planCode;
      },
      handleClose() {
        this.visible = false;
        this.current = null;
        this.radio = '';
      },
      //获取状态
      getStatus(status) {
        return status == 0
          ? '未提交'
          : status == 1
          ? '审核中'
          : status == 2
          ? '审核通过'
          : status == 3
          ? '审核不通过'
          : '';
      },
      selected() {
        if (!this.current) {
          return this.$message.warning('请至少选择一条数据');
        }
        this.$emit('changeInquiryManageList', this.current);
        this.handleClose();
      }
    }
  };
</script>

<style lang="scss" scoped>
  .tree_col {
    border: 1px solid #eee;
    padding: 10px 0;
    box-sizing: border-box;
    height: 500px;
    overflow: auto;
  }

  .table_col {
    padding-left: 10px;

    ::v-deep .el-table th.el-table__cell {
      background: #f2f2f2;
    }
  }

  .pagination {
    text-align: right;
    padding: 10px 0;
  }

  .btns {
    text-align: center;
    padding: 10px 0;
  }

  .topsearch {
    margin-bottom: 15px;
  }
</style>
