<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%; height: 70px">
            <el-row style="padding-left: 80px">
              <el-col :span="7" style="width: 293px">
                <period-date-picker
                  :type="1"
                  :width="'135px'"
                  :size="searchSize"
                  :start="parmValue.start"
                  :end="parmValue.end"
                  @timeReturned="handleTime"
                />
              </el-col>
              <el-col :span="5" style="width: 230px; float: left; margin-left: 10px">
                <el-input
                  v-model="parmValue.cgdNo"
                  :size="'mini'"
                  style="width: 100%"
                  placeholder="采购单编号"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                ></el-input>
              </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"
                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('cgMessage', {})"
                >
                  添加
                </el-button>
              </el-col>
            </el-row>
            <el-row style="padding-top: 10px">
              <el-col :span="5" style="width: 155px; float: left; margin-left: 0px">
                <el-input
                  v-model="parmValue.creater"
                  :size="'mini'"
                  style="width: 100%"
                  placeholder="创建人"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                ></el-input>
              </el-col>
              <el-col :span="5" style="width: 155px; float: left; margin-left: 10px">
                <el-input
                  v-model="parmValue.company_name"
                  :size="'mini'"
                  style="width: 100%"
                  placeholder="创建人部门"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                ></el-input>
              </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-row>
          </div>
        </template>
      </ex-table>
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>

<script>
import asyncRequest from "@/apis/service/dataCorrection/cgMessage";

import mixinPage from "@/mixins/elPaginationHandle";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import { columns } from "./columns";
export default {
  mixins: [mixinPage, resToken],
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find((i) => i.menu_route == "cgMessageList") || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      loading: false,
      parmValue: {
        cgdNo: "",
        creater: "",
        start: "",
        end: "",
        company_name: "", //创建人部门
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: columns,
    };
  },
  mounted() {
    // const { back } = this.$route.query;
    // if (back) {
    //   this.parmValue = JSON.parse(back);
    //   const {page,size}=this.parmValue
    //    this.pageInfo= {
    //     size: size,
    //     curr: page,
    //     total: 0,
    //   }
    // }
    this.searchList();
  },
  methods: {
    async searchList() {
      this.loading = true;
      const res = await asyncRequest.cgdgetchangesupplierlist(this.parmValue);
      if (res && res.code === 0 && res.data) {
        console.log("aaaaaaaa", res);
        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 = {
        cgdNo: "",
        company_name: "", //创建人部门
        creater: "",
        start: "",
        end: "",
        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>
