<template>
  <div class="app-container">
    <search-filter :search-datas.sync="searchDatas" :selectedId="selectedId" :commodityTypeLists="commodityTypeLists" showadd @search="btn_search" @delorders="btn_search"></search-filter>
    <el-table v-loading="loading" :data="dataLists" border stripe @selection-change="changeSelects">
      <el-table-column prop="F_ClassName" label="商品分类" align="center" fixed width=""></el-table-column>
      <el-table-column prop="F_ProductName" label="商品名称" align="center" fixed width=""></el-table-column>
      <el-table-column prop="F_Stock" label="商品数量（山西仓）" align="center" fixed width=""></el-table-column>
      <el-table-column prop="F_Stock1" label="商品数量（新乡仓）" align="center" fixed width=""></el-table-column>
      <el-table-column prop="F_OnSaleBegin" label="上架时间" align="center" fixed width=""></el-table-column>
      <el-table-column prop="F_OnSaleEnd" label="下架时间" align="center" fixed width=""></el-table-column>
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList" />
  </div>
</template>

<script>

import { getCommodityList, deleteCommodityList } from '@/api/commodityManagement/commodityList'
import { getCommodityType } from '@/api/commodityManagement/commodityType'
import SearchFilter from './components/searchFilter'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'CommodityStock',
  components: {
    Pagination,
    SearchFilter,
  },
  data() {
    return {
      loading: false,
      label_name: '',//标签名
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      searchDatas: {
        productId: '', //商品id
        classId: '', //商品类型id
        className: '', //商品类型
        productName: '', //商品名称
        pinyinShort: '', //拼音缩写
        productNumber: '', //商品编码
        productShortName: '', //商品副标题
        tag: '', //商品标签
      },
      multipleSelection: [], // 选中的数据
      selectedId: [], //选中的id
      commodityTypeLists: [], //商品类型下拉
    }
  },
  created() {
    this.getList()
    this.getCommodityTypeSelect()
    document.onkeyup = (e) => {
      if (e.keyCode === 13) {
        this.getList()
      }
    }
  },
  methods: {
    getList() {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // int 第几页,
          pagesize: this.pageParams.pagesize, // int 每页几条信息,
          ProductId: this.searchDatas.productId == '' ? '' : this.searchDatas.productId,
          ClassId: this.searchDatas.classId == '' ? 0 : this.searchDatas.classId,
          ClassName: this.searchDatas.className,
          ProductName: this.searchDatas.productName,
          PinyinShort: this.searchDatas.pinyinShort,
          ProductNumber: this.searchDatas.productNumber,
          ProductShortName: this.searchDatas.productShortName,
          tag: this.searchDatas.tag,
          issale: -1,
          Stock: 1, //是否显示库存 0-不显示 1-显示
        }
        getCommodityList(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.pageParams.total = response.data.Totals
            this.dataLists = response.data.Rows
          }
        })
        resolve()
      })
    },
    btn_search() {
      this.pageParams.pageindex = 1
      this.getList()
    },
    changeSelects(selection) {
      const ids = []
      this.multipleSelection = selection
      for (let i=0; i<this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].id)
      }
      this.selectedId = ids;
    },
    getCommodityTypeSelect() {
      this.loading = true
      return new Promise(resolve => {
        const data = {
          pageindex: 1, // int 第几页
          pagesize: 300, // int 每页几条信息
          ParentId: 0,
        }
        getCommodityType(data).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.commodityTypeLists = response.data
          }
        })
        resolve()
      })
    },
  }
}
</script>

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

</style>
