<template>
  <template-page
    ref="pageRef"
    :get-list="getList"
    :export-list="exportList"
    :options-evens-group="optionsEvensGroup"
    :column-parsing="columnParsing"
    :no-use="true"
    :field-beans-hook="fieldBeansHook"
  />
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import add_callback_mixin from '@/components/template/add_callback_mixin.js'
import { getStockListV2, getWarehouseList, exportStockListV2 } from '@/api/stock'
import { getCategoryList, getSmallList } from '@/api/common'
export default {
  components: { TemplatePage },
  mixins: [import_mixin, add_callback_mixin],
  data() {
    return {
      visible: false,
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      }, // 关闭新增弹窗

      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      dataList: null, // 列表数据
      listLoading: false, // 列表加载loading
      screenForm: {
        // 筛选表单数据
        warehouse: [],
        position: '',
        goodsName: '',
        goodsNum: '',
        goodsCode: '',
        model: '',
        type: '',
        categoryId: []
      },
      warehouseList: [],
      positionList: [],
      typeList: [],
      smallList: []
    }
  },
  methods: {
    fieldBeansHook(List) {
      return [
        ...List,
        {
          adminUserId: null,
          colName: 'scp.correspond_id',
          enumMap: '{}',
          frontCode: 'STOCK_NO',
          hide: false,
          isCopy: false,
          isQuery: true,
          isShow: false,
          isTotal: false,
          jname: 'correspondId',
          label: '仓库名称',
          multiple: true,
          pk: false,
          sortNum: 0,
          tbName: '',
          type: 'select',
          isExport: false
        }
      ]
    },
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getStockListV2(...p)
    },
    // 列表导出函数
    exportList: exportStockListV2,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return (h, { row, index, column }) => {
        return (
          <div class="operation-btns">
            {/* <el-button
              size="mini"
              type="text"
              onClick={ () => {
                this.visible = true
                this.detailsId = row.id
              }}
            >
              查看
            </el-button> */}
          </div>
        )
      }
    },
    handleClose() {
      this.addOff(() => {
        this.visible = false
      })()
    },
    // 获取仓库列表
    getWarehouseList() {
      getWarehouseList({
        pageNum: 1,
        pageSize: -1
      }).then(res => {
        this.warehouseList = res.data.records
      })
    },

    // 获取产品大类列表
    getCategoryList() {
      getCategoryList({
        pageNum: 1,
        pageSize: -1
      }).then(res => {
        this.typeList = res.data.records
      })
    },

    // 获取产品小类列表
    getSmallList() {
      getSmallList({ id: this.screenForm.type }).then(res => {
        this.smallList = res.data
      })
    }
  }
}
</script>

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