<template>
  <div>
    <el-table
      v-loading="false"
      :data="tableData"
      border
      stripe
      :size="'mini'"
      style="width: 100%"
    >
      <el-table-column prop="spuCode" label="商品编号" min-width="155" />
      <el-table-column prop="good_name" label="商品名称" min-width="200" />
      <el-table-column prop="is_profit" label="盘盈/盘亏" min-width="100">
        <template slot-scope="scope">
          <el-tag
            :size="tablebtnSize"
            :type="scope.row.is_profit == '0' ? 'success' : 'warning'"
            v-text="
              (typeOptions.find((item) => item.id == scope.row.is_profit) || {}).label ||
              '--'
            "
          ></el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="origin_num" label="盘点前数量" min-width="110" />
      <el-table-column prop="check_num" label="盘点后数量" min-width="110" />
      <el-table-column prop="diff_num" label="差额数量" min-width="110" />
      <el-table-column prop="addtime" width="145" label="结果上传时间">
        <template slot="header" slot-scope="scope">
          <span>结果上传时间</span>
          <el-tooltip
            style="margin: 3px 0 0 0"
            effect="dark"
            class="fr"
            v-if="status == '1' && ppowers.some((i) => i == '1')"
            content="添加"
            placement="top"
          >
            <i
              class="el-icon-circle-plus-outline tb-icon"
              style="color: #6954f0; magin: 0 0 0 10px"
              @click="importshowModel = true"
            ></i>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div
      v-if="tableData && tableData.length > 0"
      class="Pagination"
      style="text-align: right; margin-top: 10px"
    >
      <el-pagination
        :current-page="parmValue.page"
        :page-size="parmValue.size"
        :size="'mini'"
        layout="total,  prev, pager, next, jumper"
        :total="pageInfo.total"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      />
    </div>
    <result-uplod-model
      :show-model="importshowModel"
      :id="id"
      @refresh="refresh"
      @cancel="importshowModel = false"
    />
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/stock/check/detail";
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import resultUplodModel from "./resultUplodModel";
import { mapGetters } from "vuex";
export default {
  name: "addEdit",
  props: ["id", "newTime", "sitem"],
  mixins: [mixinPage, resToken],
  components: {
    resultUplodModel,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "checkDetail") ||
        {};
      const { action } = tran ?? {};
      return action ?? [];
    },
    ppowers() {
      const tran =
        this.$store.getters.roleProcess.find((i) => i.process_type === "PDD") || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },

  watch: {
    newTime: function (val) {
      if (val) {
        this.restSearch();
      }
    },
  },
  data() {
    return {
      importshowModel: false,
      status: "",
      // 盘点类型
      typeOptions: [
        { id: "0", label: "盘盈" },
        { id: "1", label: "盘亏" },
      ],
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      parmValue: {
        page: 1, // 页码
        size: 15, // 每页显示条数
        check_code: "", // 盘点仓库
      },
      tableData: [],
      passwordModel: false,
      passwordModelId: 0,
      isPasswordDetail: false,
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "good_type_code",
          label: "商品属性编号",
          "min-width": "130px",
        },

        {
          prop: "good_name",
          label: "商品名称",
          "min-width": "200px",
        },
        {
          prop: "is_profit",
          label: "盘盈/盘亏",
          _slot_: "is_profit",
          "min-width": "100px",
        },
        {
          prop: "origin_num",
          label: "盘点前数量",
          "min-width": "110px",
        },

        {
          prop: "check_num",
          label: "盘点后数量",
          "min-width": "110px",
        },
        {
          prop: "diff_num",
          label: "差额数量",
          "min-width": "100px",
        },

        {
          prop: "addtime",
          label: "结果上传时间",
          width: "145px",
        },
        {
          prop: "",
          label: "操作",
          fixed: "right",
          _noset_: true,
          width: "50px",
          _slot_: "operation",
        },
      ],
    };
  },
  mounted() {
    this.restSearch();
  },

  methods: {
    restSearch() {
      this.status = this.sitem.status;
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        id: "", // 	盘点编号
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      this.searchList();
    },
    refresh() {
      this.pageInfo.curr = 1;
      this.parmValue.page = 1;
      this.searchList();
      this.$emit("refresh");
    },
    async searchList() {
      this.loading = true;
      this.parmValue.id = this.id;
      const res = await asyncRequest.checkgood(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>

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