<template>
  <div class="productWeido pagePadding" style="padding: 0">
    <div
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <ex-table
        v-loading="false"
        :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">
              <el-col :span="24">
                <el-col :span="10">
                  <el-input
                    v-model="parmValue.type_code"
                    :size="searchSize"
                    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"
              width="80"
            ></el-table-column>
            <el-table-column
              label="仓库编码"
              prop="wsm_code"
              width="180"
            ></el-table-column>
            <el-table-column
              label="当前库存"
              prop="total_stock"
            ></el-table-column>
            <el-table-column
              label="待入库"
              prop="wait_in_stock"
            ></el-table-column>
            <el-table-column
              label="待出库"
              prop="wait_out_stock"
            ></el-table-column>
            <el-table-column
              label="可用库存"
              prop="usable_stock"
            ></el-table-column>
            <el-table-column
              label="在途库存"
              prop="intra_stock"
            ></el-table-column>
          </el-table>
        </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() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "stockCount"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      statusList: statusList,
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      //入参参数
      parmValue: {
        type_code: "", //商品属性编码
        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: "",
        size: 15,
        curr: 1,
      };
      this.searchList();
    },
    //获取列表功能
    async searchList() {
      this.loading = true;
      // { type_code: "GY202104290049" }
      console.log(this.parmValue);
      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>
   