<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <inventory-search @search="reload"> </inventory-search>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        cache-key="systemRoleTable14"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit()"
          >
            新建
          </el-button>
          <el-button
            size="small"
            type="primary"
            class="ele-btn-icon"
            @click="goDetail()"
          >
            详情
          </el-button>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="openEdit(row)"
          >
            修改
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除此角色吗？"
            @confirm="remove(row)"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>

    <!-- 新建或编辑弹窗 -->
    <AddInventoryDialog
      ref="addInventoryDialogRef"
      :dialogTile="dialogTitle"
      @refreshList="resetForm"
      :isBindPlan="isBindPlan"
    />
  </div>
</template>

<script>
  import InventorySearch from './components/inventory-search.vue';
  import AddInventoryDialog from './components/addInventoryDialog.vue';
  import { pageRoles } from '@/api/system/role';
  export default {
    components: {
      InventorySearch,
      AddInventoryDialog
    },
    data () {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '计划单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'groupId',
            label: '盘点名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'enable',
            label: '盘点仓库',
            align: 'center',
            showOverflowTooltip: true,
            slot: 'enable',
            minWidth: 110
          },
          {
            prop: 'name',
            label: '盘点部门',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'type',
            label: '资产分类',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'cycle',
            label: '规则名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'auto',
            label: '自动派单',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'creater',
            label: '创建人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row, _column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 150,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 加载状态
        loading: false,
        pageType: 'add',
        dialogTitle: '',
        isBindPlan: false
      };
    },
    computed: {},
    methods: {
      // 重置
      resetForm () {
        this.$refs.configFormRef.resetFields();
        // this.searchForm()
      },
      /* 表格数据源 */
      datasource ({ page, limit, where, order }) {
        return pageRoles({ pageNum: page, size: limit, ...where });
      },
      /* 刷新表格 */
      reload (where) {
        this.$refs.table.reload({ page: 1, where });
      },

      openEdit (row) {
        this.isBindPlan = false;
        this.dialogTitle = '新增盘点计划配置';
        this.$refs.addInventoryDialogRef.dialogVisible = true;
        // this.$store.dispatch('planRules/setAddOrUpdate', 'add')
      },
      goDetail () {
        this.$router.push({
          path: '/rulesManagement/planRules/detail'
          // query: {
          //   id
          // }
        });
      }
    }
  };
</script>

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