<template>
  <div class="sort 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 0 80px">
              <el-col :span="6" style="width: 303px; padding: 0 0 0 10px">
                <period-date-picker
                  :type="1"
                  :width="'135px'"
                  :size="searchSize"
                  :start="parmValue.start_date"
                  :end="parmValue.end_date"
                  @timeReturned="handleTime"
                />
              </el-col>
              <el-col :span="6" style="width: 230px; padding: 0 0 0 10px">
                <el-input
                  placeholder="上线商品编号"
                  v-model="parmValue.skuCode"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                  clearable
                >
                </el-input>
              </el-col>
              <el-col :span="6" style="width: 160px; padding: 0 0 0 10px">
                <el-input
                  placeholder="修改人"
                  :size="searchSize"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                  v-model="parmValue.creater"
                  clearable
                >
                </el-input>
              </el-col>
              <el-col :span="3" class="fr" style="width: 66px; padding: 0 0 0 10px">
                <el-button type="primary" :size="searchSize" @click="searchList">
                  刷新
                </el-button>
              </el-col>
              <el-col :span="3" class="fr" style="width: 66px; padding: 0 0 0 10px">
                <el-button type="warning" :size="searchSize" @click="restSearch">
                  重置
                </el-button>
              </el-col>
            </el-row>
          </div></template
        >
        <template #operation="{ scope }">
          <el-tooltip effect="dark" content="详情" placement="top">
            <i class="el-icon-view tb-icon" @click="handleEdit(scope.$index)"></i>
          </el-tooltip>
        </template>
      </ex-table>
      <add-edit
        :sitem="sitem"
        :show-model="showModel"
        @refresh="(showModel = false), searchList()"
        @cancel="showModel = false"
      />
    </div>
    <no-auth v-else></no-auth>
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/youzan/othGoodFieldLog";
import mixinPage from "@/mixins/elPaginationHandle";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import addEdit from "./addEdit";
export default {
  name: "othGoodFieldLog",
  mixins: [mixinPage, resToken],
  components: {
    addEdit,
  },
  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "othGoodFieldLog"
        ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      loading: false,
      showModel: false,
      sitem: null,
      parmValue: {
        page: 1, // 页码
        size: 15, // 每页显示条数
        skuCode: "",
        creater: "",
        start_date: "",
        end_date: "",
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "id",
          label: "记录ID",
        },
        {
          prop: "skuCode",
          label: "上线商品编号",
        },
        {
          prop: "item_id",
          label: "有赞商品ID",
        },
        {
          prop: "creater",
          label: "修改人", //商品编码，商家可以自定义参数，支持英文和数字组合
        },
        {
          prop: "addtime",
          label: "修改时间",
        },
        {
          prop: "",
          label: "操作",
          fixed: "right",
          _noset_: true,
          width: "60px",
          _slot_: "operation",
        },
      ],
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    handleEdit(index) {
      this.sitem = JSON.parse(JSON.stringify(this.tableData[index]));
      this.showModel = true;
    },
    restSearch() {
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        page: 1, // 页码
        size: 15, // 每页显示条数
        skuCode: "",
        creater: "",
        start_date: "",
        end_date: "",
      };
      this.searchList();
    },
    async handleTime(e) {
      this.parmValue.start_date = e.startTime || "";
      this.parmValue.end_date = e.endTime || "";
      if (
        (this.parmValue.start_date !== "" && this.parmValue.end_date !== "") ||
        (this.parmValue.start_date === "" && this.parmValue.end_date === "")
      ) {
        this.pageInfo.curr = 1;
        this.parmValue.page = 1;
        await this.searchList();
      }
    },
    // 刷新表格
    async searchList() {
      if (this.loading) return;
      if (
        (this.parmValue.start !== "" && this.parmValue.end === "") ||
        (this.parmValue.start === "" && this.parmValue.end !== "")
      ) {
        this.$message.warning("时间区间不完整！");
        return;
      }
      this.loading = true;
      const { code, data } = await asyncRequest.list(this.parmValue);
      if (code === 0) {
        const { list, count } = data ?? {};
        this.tableData = list ?? [];
        this.pageInfo.total = count ?? 0;
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.sort {
  .my-breadcrumb {
    .my-breadcrumb-item {
      float: left;
      span {
        height: 32px;
        line-height: 32px;
      }
      .label {
        padding: 0 5px 0 0;
        color: 010101;
      }
      .separator {
        color: #787878;
        font-size: 13px;
        padding: 0 5px 0 0;
      }
      &:last-child {
        .label {
          color: #787878;
        }
      }
      &:hover {
        cursor: pointer;
      }
      &:last-child {
        cursor: default;
      }
      &:only-child {
        cursor: pointer;
      }
      // &.chover {
      //   cursor: pointer;
      // }
    }
  }
}
</style>
