<template>
  <div class="spaceCount 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%" class="min">
            <el-row style="padding: 0 0 0 80px">
              <el-col :span="24">
                <!-- 请选择仓库 -->
                <!-- <el-col :span="5" style="width: 250px">
                  <el-cascader
                    placeholder="请选择仓库"
                    filterable
                    clearable
                    :size="searchSize"
                    v-model="value"
                    :options="options"
                    style="width: 100%"
                    @change="
                      pageInfo.curr = 1;
                      parmValue.page = 1;
                      searchList();
                    "
                  ></el-cascader>
                </el-col> -->

                <!-- <el-col :span="4" style="width: 160px; padding-left: 10px">
                  <el-select
                    v-model="value"
                    :size="searchSize"
                    filterable
                    placeholder="请选择商品"
                  >
                    <el-option
                      v-for="item in product"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-col> -->

                <el-col :span="8" style="width: 500px">
                  <el-input
                    :size="searchSize"
                    placeholder="请输入内容"
                    v-model="content"
                    class="input-with-select"
                  >
                    <el-select
                      style="width: 100px"
                      v-model="select"
                      slot="prepend"
                      placeholder="请选择"
                    >
                      <el-option label="商品" value="product"></el-option>
                      <el-option label="仓库" value="stock"></el-option>
                    </el-select>
                    <el-button
                      slot="append"
                      icon="el-icon-search"
                      type="primary"
                    ></el-button>
                  </el-input>
                </el-col>

                <el-col :span="6" style="width: 303px; padding: 0 0 0 10px">
                  <PeriodDatePicker
                    :start="parmValue.total_low"
                    :end="parmValue.total_up"
                    :type="1"
                    :width="'135px'"
                    :title="'开始时间'"
                    :size="searchSize"
                    @numReturned="numReturned($event, 0)"
                  />
                </el-col>

                <!-- 重置 -->

                <el-col
                  :span="4"
                  style="width: 74px; margin-left: 10px"
                  class="mr5"
                >
                  <el-button
                    :size="searchSize"
                    class="fl"
                    type="warning"
                    @click="searchList"
                    >重置</el-button
                  >
                </el-col>
              </el-col>
            </el-row>
          </div>
          <!-- 刷新 -->
          <el-col :span="4" style="width: 74px; margin-left: 10px">
            <el-button
              :size="searchSize"
              type="primary"
              class="fr"
              label=""
              @click="searchList"
              >刷新</el-button
            >
          </el-col>
        </template>
        <template #status="{ scope }">
          <el-tag
            :size="tablebtnSize"
            :type="scope.row.status == '0' ? 'warning' : ''"
            v-text="
              (statusOptions.find((item) => item.id == scope.row.status) || {})
                .label || '--'
            "
          ></el-tag>
        </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/spaceCount";
import asyncRequest from "@/mock/service/stock/spaceCount";

import addEdit from "./addEdit";
import { mapGetters } from "vuex";
export default {
  name: "spaceCount",
  mixins: [mixinPage, resToken],
  components: {
    addEdit,
  },
  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 {
      select: "",
      product: "",
      stock: "",
      content: "",
      options: [],
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      tableData: [],
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "nickname",
          label: "仓库编码",
        },
        {
          prop: "role_name",
          label: "仓库",
        },
        {
          prop: "mobile",
          label: "商品编码",
        },
        {
          prop: "email",
          label: "商品名称",
        },
        {
          prop: "status",
          label: "分类",
          // _slot_: "status",
          // width: "80px",
        },
        {
          prop: "addtime",
          label: "单位",
          // sortable: true,
        },
        {
          prop: "addtime",
          label: "已入库",
          // sortable: true,
        },
        {
          prop: "addtime",
          label: "已出库",
          // sortable: true,
        },
        {
          prop: "addtime",
          label: "待入库",
          // sortable: true,
        },
        {
          prop: "addtime",
          label: "待出库",
          // sortable: true,
        },
      ],
      // sitem: null,
      // // 状态
      // statusOptions: [
      //   { id: "0", label: "禁用" },
      //   { id: "1", label: "启用" },
      // ],
      // passwordModel: false,
      // passwordModelId: 0,
      // isPasswordDetail: false,
      // statusList: statusList,
      parmValue: {},
    };
  },
  mounted() {
    this.searchList();
    this.stockName();
  },

  methods: {
    restSearch() {
      this.parmValue = {};
      this.searchList();
    },

    openModal(id, isDetail, sitem) {
      this.showModel = true;
      this.modelId = id;
      this.isDetail = isDetail;
      this.sitem = sitem;
    },
    async deleteById(id, status) {
      // await this.$confirm("确定要删除？", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(async () => {
      //     const model = {
      //       id: id,
      //       status: status === "1" ? "0" : "1",
      //     };
      //     const res = await asyncRequest.status(model);
      //     if (res && res.code === 0) {
      //       this.$notify.success({
      //         title: "删除成功",
      //         message: "",
      //       });
      //       this.searchList();
      //     } else if (res && res.code >= 100 && res.code <= 104) {
      //       await this.logout();
      //     } else {
      //       this.$message.warning(res.message);
      //     }
      //   })
      //   .catch(() => {
      //     console.log("取消");
      //   });
    },
    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;
    },

    async statusConfirm(id, status) {
      // let str = status === "1" ? "禁用" : "启用";
      // await this.$confirm("确定要改为" + str + "?", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(async () => {
      //     this.loading = true;
      //     const model = {
      //       id: id,
      //       status: status === "1" ? "0" : "1",
      //     };
      //     const res = await asyncRequest.status(model);
      //     if (res && res.code === 0) {
      //       this.loading = false;
      //       this.$notify.success({
      //         title: "状态修改成功！",
      //         message: "",
      //       });
      //       await this.searchList();
      //     } else if (res && res.code >= 100 && res.code <= 104) {
      //       await this.logout();
      //     } else {
      //       this.$message.warning(res.message);
      //     }
      //   })
      //   .catch(() => {
      //     console.log("取消");
      //   });
    },
    async stockName() {
      //获取多级仓库名称的方法
      const res = await asyncRequest.listAll(this.parmValue);
      // console.log(res.data);
      // this.options = res.data;
      // console.log(this.options);
      let arr = res.data;
      // console.log(arr);
      arr.forEach((ele) => {
        let item = {
          value: ele.id,
          label: ele.name,
          children: [],
        };
        ele.child.forEach((elem) => {
          let model = {
            value: elem.id,
            label: elem.name,
          };
          item.children.push(model);
        });
        this.options.push(item);
      });
      // console.log(this.options);
      // console.log(this.pageInfo.total);
    },
  },
};
</script>
<style lang="scss" scoped>
@media screen and (max-width: 1200px) {
  .mr5 {
    margin-top: 10px;
  }
}
</style>
   