<template>
  <div>
    <!-- 数据表格 -->
    <item-search @search="reload" ref="refSeavch" @handledime="handledime">
    </item-search>
    <ele-pro-table
      ref="table"
      :initLoad="false"
      :columns="columns"
      :datasource="datasource"
      height="calc(100vh - 265px)"
      full-height="calc(100vh - 116px)"
      tool-class="ele-toolbar-form"
      cache-key="systemOrgUserTable"
    >
      <!-- 表头工具栏 -->
      <template v-slot:toolbar> </template>
      <!-- 操作列 -->
      <template v-slot:action="{ row }">
        <el-link
          type="primary"
          :underline="false"
          icon="el-icon-edit"
          @click="details(row)"
        >
          详情
        </el-link>
      </template>
    </ele-pro-table>
  </div>
</template>

<script>
  import ItemSearch from './item-search.vue';
  // import {
  //   getUserPage,
  //   removePersonnel,
  //   unbindLoginName
  // } from '@/api/system/organization';
  import {
    pageeLedgerMain,
    removeItem,
    getWarehouseList
  } from '@/api/classifyManage/itemInformation';

  import ouint from '@/api/warehouseManagement/outin';

  export default {
    components: { ItemSearch },
    props: {
      // 机构id
      organizationId: [Number, String],
      // 全部机构
      organizationList: Array,
      current: {
        type: Object,
        default: () => ({})
      }
    },
    data() {
      return {
        searchForm: {
          dimension: 1
        },
        isShow: false
      };
    },
    computed: {
      // 表格列配置
      columns() {
        let obj = [
          {
            columnKey: 'index',
            type: 'index',
            width: 50,
            align: 'center',
            label: '序号',
            showOverflowTooltip: true,
            fixed: 'left'
          },

          {
            prop: 'code',
            label: '编码',
            showOverflowTooltip: true
          },
          {
            prop: 'name',
            label: '名称',
            showOverflowTooltip: true
          },
          {
            prop: 'brandNum',
            label: '牌号',
            showOverflowTooltip: true
          },
          {
            prop: 'modelType',
            label: '型号',
            showOverflowTooltip: true
          },
          {
            prop: 'availableCountBase',
            label: '实时库存',
            sortable: 'custom',
            showOverflowTooltip: true
          },
          {
            prop: 'measuringUnit',
            label: '计量单位',
            align: 'center'
          },
          {
            prop: 'weightUnit',
            label: '重量单位',
            showOverflowTooltip: true
          },
          {
            prop: 'minUnit',
            label: '包装单位',
            showOverflowTooltip: true
          },
          // {
          //   prop: '',
          //   label: '安全库存',
          //   showOverflowTooltip: true
          // },
          // {
          //   prop: '',
          //   label: '质保期',
          //   showOverflowTooltip: true
          // },
          {
            columnKey: 'action',
            label: '操作',
            width: 100,
            align: 'left',
            resizable: false,
            slot: 'action'
          }
        ];
        if (this.isShow) {
          obj.splice(1, 0, {
            prop: 'batchNo',
            label: '批次号',
            showOverflowTooltip: true
          });
        }
        return obj;
      }
    },
    methods: {
      handledime(val) {
        this.$set(this, 'isShow', val == 2);
      },
      /* 表格数据源 */
      datasource({ page, limit, where }) {
        console.log();
        const dimension = this.$refs.refSeavch.dimension;
        return ouint.getRealTimeInventory({
          ...where,
          pageNum: page,
          size: limit,
          dimension: dimension
        });
      },
      /* 刷新表格 */
      reload(where) {
        this.$nextTick(() => {
          this.$refs.table.reload({
            pageNum: 1,
            where: {
              ...where,
              categoryLevelId: this.current?.data?.id || this.current?.id
            }
          });
        });
      },

      details(row) {
        const key = Date.now();
        this.$store.commit('stockManagement/CLEAR_BASEINFO');
        this.$store.commit('stockManagement/CHANGE_BASEINFO', {
          key,
          value: row
        });

        const url =
          this.$refs.refSeavch.dimension == 1
            ? '/warehouseManagement/stockLedger/allBatchDetails'
            : '/warehouseManagement/stockLedger/batchDetails';

        this.$router.push({
          path: url,
          query: {
            key,
            dimension: this.$refs.refSeavch.dimension,
            id: row.id,
            assetId: row.assetId
          }
        });
      }
    },

    watch: {
      // 监听机构id变化
      current: {
        handler() {
          this.reload();
        }
      }
    }
  };
</script>

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