<template>
  <div class="dataWeido pagePadding" style="padding: 0">
    <div
      v-if="powers && powers.length > 0 && powers.some((item) => item == '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">
              <el-col :span="24">
                <el-col :span="12" style="width: 300px; padding: 0">
                  <search-supplier
                    :size="searchSize"
                    :placeholder="'供应商公司'"
                    :value="parmValue.supplier_code"
                    @searchChange="selectSupplier"
                  />
                </el-col>
                <el-col :span="12" style="width: 200px; padding-left: 10px">
                  <search-stock
                    :isDetail="true"
                    :size="searchSize"
                    :value="parmValue.stock_code"
                    :disabled="isDisabled"
                    :placeholder="'出库仓库'"
                    :isRelation="true"
                    :companyCode="supplier_code"
                    :names="''"
                    @searchChange="selectStock"
                  />
                </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: 54px; 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="good_code"
              width="150"
            ></el-table-column>
                       
            <el-table-column
              label="属性编码"
              prop="good_type_code"
              width="130"
            ></el-table-column>
                       
            <el-table-column
              label="商品名称"
              prop="good_name"
              min-width="150"
              :show-overflow-tooltip="true"
            ></el-table-column>
                       
            <el-table-column
              label="商品属性"
              prop="attribute"
              min-width="120"
              :show-overflow-tooltip="true"
            ></el-table-column>
                       
            <el-table-column
              label="分类"
              prop="sort_f"
              width="100"
            ></el-table-column>
                       
            <el-table-column
              label="可用库存"
              prop="usable_stock"
              width="80"
            ></el-table-column>
                       
            <el-table-column
              label="在途库存"
              prop="intra_stock"
              width="80"
            ></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 asyncRequest from "@/apis/service/stock/dataWeido";
import columns from "./columns";
import { mapGetters } from "vuex";

export default {
  name: "dataWeido",
  mixins: [mixinPage, resToken],

  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 {
      loading:false,
      stock_code: "",
      supplier_code: "",
      parmValue: {
        supplier_code: [],
        stock_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: {
    // 选择供应商仓库
    selectStock(e) {
      if (e && e.id) {
        this.parmValue.stock_code = [e.code];
        this.stock_code = e.code;
      } else {
        this.parmValue.stock_code = [];
        this.stock_code = "";
      }
      if (this.parmValue.stock_code) {
        this.searchList();
      }
    },
    // 选择供应商
    selectSupplier(e) {
      if (e && e.id) {
        this.parmValue.supplier_code = [e.code];
        this.supplier_code = e.code;
        this.isDisabled = false;
      } else {
        this.parmValue.stock_code = [];
        this.parmValue.supplier_code = [];
        this.stock_code = "";
        this.supplier_code = "";
        this.isDisabled = true;
      }
      if (this.parmValue.supplier_code) {
        this.searchList();
      }
    },
    restSearch() {
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        supplier_code: [],
        stock_code: [], //仓库编码
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      this.searchList();
    },
    async searchList() {
      this.loading = true;
      let { page, size, stock_code, supplier_code } = this.parmValue;
      let model = {
        page,
        size,
        wsm_code: stock_code != [] ? stock_code.toString() : "",
        supplier_code: supplier_code != "" ? supplier_code.toString() : "",
      };
      const res = await asyncRequest.list(model);
      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>

   