<template>
  <div id="stocktakingWork_index">
    <el-card shadow="never" v-loading="loading">
      <work-search @search="reload"> </work-search>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        height="calc(100vh-300px)"
        :pageSize="20"
        :datasource="datasource"
      >
        <template v-slot:code="{ row }">
          <el-link type="primary" @click="goDetail(row)">
            {{ row.code }}
          </el-link>
        </template>
        <template v-slot:action="{ row }">
          <el-link
            v-if="row.status == 0"
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="control(row)"
          >
            报工
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
    <DisposeDialog ref="disposeDialogRef" @flushed="reload"></DisposeDialog>
  </div>
</template>

<script>
  import DisposeDialog from './components/disposeDialog.vue';
  import WorkSearch from './components/work-search.vue';
  import { getPlanOrderList } from '@/api/inventory';
  export default {
    components: {
      WorkSearch,
      DisposeDialog
    },
    data() {
      return {
        visibleDialog: false,
        // 	0-待处理,1-执行中,2-已完成
        statusObj: {
          0: '待处理',
          1: '执行中',
          2: '已完成'
        },
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            slot: 'code',
            prop: 'code',
            label: '盘点单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            slot: 'status',
            minWidth: 110,
            formatter: (row) => {
              return this.statusObj[Number(row.status)];
            }
          },
          {
            prop: 'planCode',
            label: '计划单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'planName',
            label: '计划名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'warehouseName',
            label: '盘点仓库',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'executeGroupName',
            label: '盘点部门',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'executorName',
            label: '盘点人员',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'startTime',
            label: '计划开始时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'endTime',
            label: '计划结束时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 80,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 加载状态
        loading: false,
        planOrderId: ''
      };
    },
    methods: {
      control(row) {
        this.$refs.disposeDialogRef.open(row.id);
      },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getPlanOrderList({ pageNum: page, size: limit, ...where });
      },
      async changeEnable(row) {
        const res = await putRoles(row);
        if (res.code == 0) {
          this.$message({
            type: 'success',
            message: '修改成功',
            customClass: 'ele-message-border'
          });
          this.reload();
        }
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where });
      },
      // 详情
      goDetail(row) {
        this.$router.push({
          path: '/warehouseManagement/stocktaking/work/details',
          query: {
            id: row.id,
            planId: row.planId
          }
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  #stocktakingWork_index {
    height: calc(100vh - 96px);
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    // element-ui样式穿透
    :deep(.el-card) {
      height: 100%;
      .el-card__body {
        height: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        .ele-pro-table {
          flex: 1;
          display: flex;
          flex-direction: column;
          .el-table {
            flex: 1;
            // display: flex;
            // flex-direction: column;
            // .el-table__body-wrapper {
            //   flex: 1;
            // }
          }
        }
      }
      .el-form-item {
        margin-bottom: 5px !important;
      }
    }
  }
</style>
