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

    width="70%"
  >
    <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>
    </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/purchasingManage/purchasePlanManage';
import searchQuotation from './planSearch.vue';

export default {
  components: {
    searchQuotation
  },
  props: {
    planDialogFlag: {
      type: Boolean,
      default: false
    },
    generatedType: {
      type: String,
      default: ''
    },
  },

  data() {
    return {
      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: 'planName',
          slot: 'planName',
          label: '采购计划名称',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'planCode',
          slot: 'planCode',
          label: '采购计划编码',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'requirementCode',
          label: '采购需求编码',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'sourceTypeName',
          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: '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
      //     );
      //   }
      // }
    },
    /* 表格数据源 */
    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.$emit('update:planDialogFlag', false);
    },
    async selected() {
      if (!this.current) {
        return this.$message.warning('请至少选择一条数据');
      }
      this.$emit('changeParent', 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>
