<template>
  <div id="stocktakingReportLoss_index">
    <el-card shadow="never" v-loading="loading">
      <reportloss-search @search="reload"> </reportloss-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:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit()"
          >
            新建
          </el-button>
        </template>
        <template v-slot:action="{ row }">
          <el-link
            v-if="row.status == 0"
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="openEdit(row)"
          >
            修改
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 新建或编辑弹窗 -->
    <AddReportDialog
      ref="addInventoryDialogRef"
      :dialogTile="dialogTitle"
      :id="inventoryId"
      @refreshList="reload"
      :isBindPlan="isBindPlan"
    />
  </div>
</template>

<script>
  import ReportlossSearch from './components/reportloss-search.vue';
  import AddReportDialog from './components/addReportDialog.vue';
  import { getReportsList } from '@/api/inventory';
  export default {
    components: {
      ReportlossSearch,
      AddReportDialog
    },
    data() {
      return {
        // 0待审核,1=审核中，2=已审核
        statusOptions: [
          {
            value: 0,
            label: '待审核'
          },
          {
            value: 1,
            label: '审核中'
          },
          {
            value: 2,
            label: '已审核'
          }
        ],
        dialogTitle: '',
        inventoryId: '',
        isBindPlan: false,
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            slot: 'code',
            prop: 'code',
            label: '单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'name',
            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: 'createTime',
            label: '报损时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            formatter: (row) => {
              return this.statusOptions.filter(
                (item) => item.value == row.status
              )[0].label;
            }
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 80,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 加载状态
        loading: false
      };
    },
    computed: {},
    methods: {
      openEdit(row) {
        if (row) {
          this.dialogTitle = '修改报损报溢';
          this.inventoryId = row.id;
        } else {
          this.dialogTitle = '新增报损报溢';
          this.inventoryId = '';
        }
        this.isBindPlan = false;
        this.$refs.addInventoryDialogRef.dialogVisible = true;
      },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getReportsList({ 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.dialogTitle = '报损报溢详情';
        this.inventoryId = row.id;
        this.isBindPlan = true;
        this.$refs.addInventoryDialogRef.dialogVisible = true;
      },

      // 新增
      addClick() {
        this.$router.push({
          path: '/warehouseManagement/stocktaking/reportLoss/add'
          // query: {
          //   id
          // }
        });
      },

      // 撤回
      editRow(row) {}
    }
  };
</script>

<style lang="scss" scoped>
  #stocktakingReportLoss_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>
