<template>
  <div class="pagePadding">
    <div class="box" 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-left: 80px">
              <el-col :span="5" style="width: 230px; float: left;">
                <el-input
                  v-model="parmValue.code"
                  :size="'mini'"
                  style="width: 100%"
                  placeholder="销售单编号"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                />
              </el-col>

              <el-col :span="5" style="width: 155px; float: left; margin-left: 10px">
                <el-select
                  size="mini"
                  v-model="parmValue.status"
                  placeholder="状态"
                  clearable
                  @change="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                >
                  <el-option
                    v-for="opt in statusOptions"
                    :key="opt.value"
                    :label="opt.label"
                    :value="opt.value"
                  />
                </el-select>
              </el-col>

              <el-col :span="3" style="width: 66px; float: right">
                <el-button
                  type="primary"
                  :size="searchSize"
                  style="float: right"
                  @click="searchList"
                >刷新</el-button>
              </el-col>

              <el-col :span="3" style="width: 66px; float: right">
                <el-button
                  type="warning"
                  :size="searchSize"
                  style="float: right"
                  @click="restSearch"
                >重置</el-button>
              </el-col>

              <el-col
                :span="3"
                class="fr"
                style="width: 66px; padding: 0 0 0 10px"
                v-if="powers.some((i) => i == '003')"
              >
                <el-button
                  :size="searchSize"
                  type="success"
                  style="float: right"
                  @click="routeGoto('customerCorrectionDetail', {
                    mode:'create'
                  })"
                >添加</el-button>
              </el-col>
            </el-row>
          </div>
        </template>

        <template #status="{scope}">
          <el-tag
            :size="'mini'"
            :type="scope.row.status == '1' ? 'warning' : ''"
            v-text="
            (statusOptions.find((i)=> i.value == scope.row.status) || {})
              .label || '--'
          "
          ></el-tag>
        </template>

        <template #before="{scope}">
          <el-tooltip :content="'客户公司编码 : ' + scope.row.before.customer_code" placement="top">
            <i class="el-icon-warning-outline" style="margin-right:2px;cursor:pointer" />
          </el-tooltip>
          {{scope.row.before.customerName}}
        </template>

        <template #after="{scope}">
          <el-tooltip :content="'客户公司编码 : ' + scope.row.after.customer_code" placement="top">
            <i class="el-icon-warning-outline" style="margin-right:2px;cursor:pointer" />
          </el-tooltip>
          {{scope.row.after.customerName}}
        </template>
        <!--  -->
        <template #operation="{ scope }">
          <el-tooltip effect="dark" content="详情" placement="top" v-if="powers.some((i) => i == '007')">
            <i
              class="el-icon-view tb-icon"
              @click="routeGoto('customerCorrectionDetail', {
                id: scope.row.id,
                mode: 'update'
              })"
            ></i>
          </el-tooltip>
        </template>
      </ex-table>
    </div>

    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>

<script>
import asyncRequest from "@/apis/service/dataCorrection/order";
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import { columns } from "./columns";
import { mapGetters } from "vuex";

export default {
  mixins: [mixinPage, resToken],
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const { btnList } = this.$store.getters;
      const tran =
        btnList.find(i => i.menu_route == "customerCorrection") || {};
      const { action } = tran ?? {};
      return action ?? [];
    }
  },
  data() {
    return {
      loading: false,
      statusOptions: [
        { value: "1", label: "待审核" },
        { value: "2", label: "审核通过" },
        { value: "3", label: "审核驳回" }
      ],
      parmValue: {
        code: "",
        status: "",
        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: {
    async searchList() {
      this.loading = true;
      const res = await asyncRequest.cgdgetchangesupplierlist({
        ...this.parmValue,
        type: "2"
      });
      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;
    },
    //重置
    restSearch() {
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0
      };
      this.parmValue = {
        code: "",
        status: "",
        page: 1, // 页码
        size: 15 // 每页显示条数
      };
      this.searchList();
    },
    async handleTime(e) {
      this.parmValue.start = e.startTime || "";
      this.parmValue.end = e.endTime || "";
      if (
        (this.parmValue.start !== "" && this.parmValue.end !== "") ||
        (this.parmValue.start === "" && this.parmValue.end === "")
      ) {
        this.pageInfo.curr = 1;
        this.parmValue.page = 1;
        await this.searchList();
      }
    }
  }
};
</script>

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