<template>
  <div class="recovery pagePadding">
    <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 10px 80px">
              <el-col :span="6" style="width: 200px">
                <el-input
                  clearable
                  placeholder="任务单号"
                  v-model="parmValue.infoNo"
                  maxlength="40"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                </el-input>
              </el-col>
              <el-col :span="6" style="width: 400px; padding: 0 0 0 10px">
                <el-input
                  clearable
                  placeholder="商品名称"
                  v-model="parmValue.good_name"
                  maxlength="40"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                </el-input>
              </el-col>
              <!-- <el-col :span="6" style="width: 150px; padding: 0 0 0 10px">
                <el-input
                  clearable
                  placeholder="供应商负责人部门"
                  v-model="parmValue.company_name"
                  maxlength="40"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                </el-input>
              </el-col> -->

              <el-col :span="4" style="width: 66px; float: right">
                <el-button
                  type="warning"
                  class="fr"
                  :size="searchSize"
                  @click="restSearch"
                >
                  重置
                </el-button>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6" style="width: 280px">
                <el-input
                  clearable
                  placeholder="反馈商品编号"
                  v-model="parmValue.bidNo"
                  maxlength="40"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                </el-input>
              </el-col>
              <el-col :span="6" style="width: 400px; padding: 0 0 0 10px">
                <el-input
                  clearable
                  placeholder="供应商名称"
                  v-model="parmValue.supplierName"
                  maxlength="40"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                </el-input>
              </el-col>
              <!-- <el-col :span="6" style="width: 150px; padding: 0 0 0 10px">
                <el-input
                  clearable
                  placeholder="供应商负责人部门"
                  v-model="parmValue.company_name"
                  maxlength="40"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                </el-input>
              </el-col> -->
              <el-col :span="3" style="width: 66px; float: right">
                <el-button
                  :size="searchSize"
                  type="primary"
                  style="float: right; margin-left: 5px"
                  @click="searchList"
                >
                  刷新
                </el-button>
              </el-col>
            </el-row>
          </div>
        </template>
        <template #good_name="{ scope }">
          <!-- <img
            style="width: 20px; height: 20px"
            class="hover fl"
            v-viewer
            :src="scope.row.good_img"
            alt=""
            v-if="scope.row.good_img"
          /> -->
          <span>{{ scope.row.good_name }}</span>
          <span v-for="(si, i) in scope.row.specinfo" :key="si.spec_id + i">
            {{ i === 0 ? "__" : "--" }}{{ si.spec_name }}[{{ si.spec_value_name }}]
          </span>
        </template>
        <template #can="{ scope }">
          <span v-for="(si, i) in scope.row.can" :key="si.id + i">
            {{ i === 0 ? "" : "_" }}{{ si.name }}
          </span>
        </template>

        <template #operation="{ scope }">
          <el-tooltip effect="dark" content="详情" placement="top">
            <i
              class="el-icon-view tb-icon"
              @click="
                (modelId = scope.row.bidNo), (infoNo = scope.row.infoNo);
                showModel = true;
              "
            ></i>
          </el-tooltip>
        </template>
      </ex-table>
      <show-data
        :showModel="showModel"
        :infoNo="infoNo"
        :bidNo="modelId"
        @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/purchaseIn/recovery";
import { columns } from "./columns";
import { mapGetters } from "vuex";
import showData from "./showData";
export default {
  name: "recovery",
  mixins: [mixinPage, resToken],
  components: {
    showData,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "recovery") || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      // 状态
      loading: false,
      showModel: false,
      isDetail: false,
      modelId: 0,
      infoNo: 0,
      parmValue: {
        infoNo: "",
        bidNo: "",
        is_own: "1",
        company_name: "", //部门
        supplierName: "",
        good_name: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      tableData: [],
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: columns,
    };
  },
  mounted() {
    this.searchList();
  },

  methods: {
    restSearch() {
      this.parmValue = {
        infoNo: "",
        bidNo: "",
        is_own: "1",
        company_name: "", //部门
        supplierName: "",
        good_name: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      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>
<style lang="scss" scoped>
.recovery {
  // text-align: right;
}
</style>
