<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <user-search @search="reload" />
      <!-- 数据表格 -->
      <ele-pro-table ref="table" :columns="columns" :datasource="datasource" :selection.sync="selection" row-key="id">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>

          <el-button size="small" type="primary" icon="el-icon-plus" class="ele-btn-icon"
            @click="openEdit(null)">新增</el-button>

          <el-button size="small" type="primary" icon="el-icon-refresh-left" class="ele-btn-icon" :loading="loading"
            @click="toRefresh()">
            刷新
          </el-button>
        </template>

        <!-- 状态列 -->
        <!--     <template v-slot:status="{ row }">
          {{ checkStatus(row) }}
        </template> -->

        <!-- 操作列 -->
        <template v-slot:action="{ row }">

          <el-link type="primary" :underline="false" icon="el-icon-edit" @click="openEdit(row)">
            修改
          </el-link>

          <el-link type="primary" :underline="false" @click="btnView(row)">
            查看
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>



    <!-- 编辑弹窗 -->
    <user-edit :visible.sync="showEdit" :data="current" @done="reload" ref="userEdit" />


  </div>
</template>

<script>
import UserSearch from './components/user-search.vue';
import UserEdit from './components/user-edit.vue';
import { pageList, syncVersion } from '@/api/technology/version/version.js';
export default {
  name: 'technologyVersion',
  components: {
    UserSearch,
    UserEdit
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          prop: 'categoryCode',
          label: '产品编码',
          showOverflowTooltip: true,
          align: 'center',
          minWidth: 110
        },
        {
          prop: 'categoryName',
          label: '产品名称',
          showOverflowTooltip: true,
          align: 'center',
          minWidth: 110
        },
        {
          align: 'center',
          prop: 'code',
          label: '版本号',
          showOverflowTooltip: true,
          minWidth: 110
        },
        {
          prop: 'name',
          label: '版本名称',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },
        {
          prop: 'routingCode',
          label: '工艺路线编码',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },
        {
          prop: 'routingVersion',
          label: '工艺版本号',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },

        {
          columnKey: 'action',
          label: '操作',
          width: 220,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true
        }
      ],
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      // 是否显示导入弹窗
      showImport: false,
      statusList: [
        { label: '草稿', value: -1 },
        { label: '失效', value: 0 },
        { label: '生效', value: 1 }
      ],
      loading: false
    };
  },
  methods: {
    /* 表格数据源 */
    datasource({ page, limit, where, order }) {
      return pageList({ pageNum: page, size: limit, ...where });
    },
    // async datasource({ page, limit, where, order }) {
    //   const res = await pageList({
    //     ...where,
    //     ...order,
    //     pageNum: page,
    //     size: limit
    //   });
    //   return res;
    // },
    /* 点击刷新 */
    toRefresh() {
      this.loading = true;
      syncVersion().then(res => {
        if (res == '0') {
          this.loading = false;
          this.$message.success('数据刷新成功！')
          this.reload()
        }
      })
        .catch((e) => {
          this.loading = false;
        });
    },
    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({ page: 1, where: where });
    },

    /* 打开编辑弹窗 */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
      this.$refs.userEdit.$refs.form &&
        this.$refs.userEdit.$refs.form.clearValidate();
    },

    /* 查看详情 */
    btnView({ id }) {
      this.$router.push({
        path: '/technology/version/details',
        query: { id }
      })
    }
  }
};
</script>
