<template>
  <ele-modal
    title="选择工艺路线"
    custom-class="ele-dialog-form long-dialog-form"
    :visible.sync="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
    :maxable="true"
  >
    <el-card shadow="never">
      <route-search @search="reload"></route-search>

      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        height="calc(100vh - 460px)"
        class="dict-table"
        @cell-click="cellClick"
      >
        <template v-slot:action="{ row }">
          <el-radio class="radio" v-model="radio" :label="row.id"
            ><i></i
          ></el-radio>
        </template>
      </ele-pro-table>
    </el-card>
    <div slot="footer">
      <el-button type="primary" size="small" @click="selected">选择</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </ele-modal>
</template>

<script>
  import { routeList } from '@/api/saleOrder';
  import { reviewStatus } from '@/enum/dict';
  import routeSearch from './routeSearch.vue'
  export default {
    components: {
        routeSearch
    },
    props: {},
    data() {
      return {
        visible: false,
        columns: [
          {
            action: 'action',
            slot: 'action',
            align: 'center',
            label: '选择'
          },
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '工艺路线编码',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110,
            slot: 'code'
          },
          {
            prop: 'name',
            label: '工艺路线名称',
            showOverflowTooltip: true,
            align: 'center',
            minWidth: 110
          },

          {
            prop: 'version',
            label: '工艺路线版本',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            slot: 'status',
            showOverflowTooltip: true,
            minWidth: 110,
            // filters: [
            //   { text: '草稿', value: -1 },
            //   { text: '失效', value: 0 },
            //   { text: '生效', value: 1 }
            // ],
            filterMultiple: false,
            columnKey: 'status',
            formatter:(row)=>{
              if(row.status == -1){
                return '草稿'
              }else if(row.status == 0){
                return '失效'
              }else{
                return '生效'
              }
            }
          },
          {
            prop: 'approvalStatus',
            label: '审核状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 100,
            formatter: (_row, _column, cellValue) => {
              return reviewStatus[_row.approvalStatus];
            }
          },
          {
            prop: 'factoriesName',
            label: '所属工厂',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            align: 'center',
            prop: 'createTime',
            label: '创建时间',
            showOverflowTooltip: true,
            minWidth: 110
          },
        ],

        radio: null
      };
    },

    watch: {},
    methods: {
      open(item) {
        if (item) {
          this.radio = item.id;
        }
        this.visible = true;
      },

      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return routeList({
          pageNum: page,
          size: limit,
          ...where
        });
      },

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

      handleNodeClick(data, node) {
        this.curNodeData = data;
        this.reload({ categoryId: data.id });
      },

      // 单击获取id
      cellClick(row) {
        this.current = row;
        this.radio = row.id;
      },
      handleClose() {
        this.visible = false;
        this.current = null;
        this.radio = '';
      },

      selected() {
        if (!this.current) {
          return this.$message.warning('请选择工艺路线');
        }
        this.$emit('changeParent', this.current);
        this.handleClose();
      }
    }
  };
</script>

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