<template>
  <div class="productWeido pagePadding" style="padding: 0">
    <div
      v-if=" powers.some((i) => i == '001')"
    >
      <ex-table
        v-loading="loading"
        :table="table"
        :data="tableData"
        :columns="columns"
        :page="pageInfo"
        :size="size"
        @page-curr-change="handlePageChange"
        @page-size-change="handleSizeChange"
        @screen-reset="
          pageInfo.curr = 1;
          parmValue.page = 1;
          searchList();
        "
        @screen-submit="
          pageInfo.curr = 1;
          parmValue.page = 1;
          searchList();
        "
      >
        <template #table-header="{}">
          <div style="width: 100%">
            <el-row style="padding: 0 0 0 80px" gutter="10">
              <el-col :span="24">
                <el-col :span="7">
                  <el-input
                    v-model="parmValue.type_code"
                    :size="searchSize"
                    maxlength="40"
                    placeholder="sku编码"
                  />
                </el-col>
                <el-col :span="7">
                  <el-input
                    v-model="parmValue.good_name"
                    :size="searchSize"
                    maxlength="40"
                    placeholder="商品名称"
                  />
                </el-col>
                <!-- 搜索 -->
                <el-col :span="4" style="width: 54px">
                  <el-button
                    :size="searchSize"
                    type="primary"
                    class="fr"
                    icon="el-icon-search"
                    label=""
                    @click="searchList"
                  ></el-button>
                </el-col>
                <!-- 重置 -->
                <el-col
                  :span="4"
                  style="width: 56px; margin-left: 10px"
                  class="mr5"
                >
                  <el-button
                    :size="searchSize"
                    class="fr"
                    type="warning"
                    @click="restSearch"
                    >重置</el-button
                  >
                </el-col>
              </el-col>
            </el-row>
          </div>
        </template>
        <template #expand="{ scope }">
          <el-table
            :data="scope.row.child"
            style="width: 100%; paddind: 20px"
            border
            size="small"
          >
            <el-table-column
              label="仓库名称"
              prop="wsm_name"
              show-overflow-tooltip
              width="150"
            ></el-table-column>
            <el-table-column
              label="仓库编码"
              prop="wsm_code"
              show-overflow-tooltip
              width="170"
            ></el-table-column>
             <el-table-column
              label="仓库所在公司名称"
              prop="supplierName"
              show-overflow-tooltip
              width="150"
            ></el-table-column>
            <el-table-column
              label="仓库所在公司编码"
              prop="supplierNo"
              show-overflow-tooltip
              width="160"
            ></el-table-column>
             <el-table-column
              label="仓库业务公司名称"
              prop="company"
              show-overflow-tooltip
              width="150"
            ></el-table-column>
            <el-table-column
              label="仓库业务公司编码"
              prop="companyNo"
              show-overflow-tooltip
              width="160"
            ></el-table-column>
            <el-table-column
              label="当前库存"
              width="100"
              show-overflow-tooltip
              prop="total_stock"
            ></el-table-column>
            <el-table-column
              label="待入库"
              width="100"
              show-overflow-tooltip
              prop="wait_in_stock"
            ></el-table-column>
            <el-table-column
              label="待出库"
              width="100"
              show-overflow-tooltip
              prop="wait_out_stock"
            ></el-table-column>
            <el-table-column
              label="可用库存"
              width="100"
              show-overflow-tooltip
              prop="usable_stock"
            ></el-table-column>
            <el-table-column
              label="在途库存"
              width="100"
              show-overflow-tooltip
              prop="intra_stock"
            ></el-table-column>
          </el-table>
        </template>
        <template #specinfo="{ scope }">
          <span
            v-for="(si, sii) in scope.row.specinfo"
            :key="sii + si.spec_value_id"
            >{{ sii === 0 ? "" : "-" }}{{ si.spec_name }}[{{
              si.spec_value
            }}]</span
          >
        </template>
      </ex-table>
      <add-edit
        :id="modelId"
        :sitem="sitem"
        :show-model="showModel"
        :is-detail="isDetail"
        @refresh="searchList"
        @cancel="showModel = false"
      />
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
   <script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import { statusList } from "@/assets/js/statusList";
import asyncRequest from "@/apis/service/stock/productWeido";
import { mapGetters } from "vuex";
import columns from "./columns";
export default {
  name: "productWeido",
  mixins: [mixinPage, resToken],
  components: {},
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "stockCount"
        ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      statusList: statusList,
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      //入参参数
      parmValue: {
        type_code: "", //商品属性编码
        good_name:"", //商品名称
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      tableData: [], //渲染表格数据
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: columns,
    };
  },
  mounted() {
    this.searchList();
  },

  methods: {
    //重置参数
    restSearch() {
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        type_code: "",
        good_name:"", //商品名称
        size: 15,
        curr: 1,
      };
      this.searchList();
    },
    //获取列表功能
    async searchList() {
      this.loading = true;
      const res = await asyncRequest.list(this.parmValue);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        this.pageInfo.total = Number(res.data.count);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
  },
};
</script>
   