<template>
  <div class="othOrderModifyAddressLog pagePadding">
    <div v-if="powers && powers.length > 0 && powers.some((item) => item == '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: 293px">
                <period-date-picker
                  :type="1"
                  :width="'135px'"
                  :size="searchSize"
                  :start="parmValue.start_date"
                  :end="parmValue.end_date"
                  @timeReturned="handleTime"
                />
              </el-col>
              <el-col :span="4" style="width: 380px; padding: 0 0 0 10px">
                <el-input
                  :size="searchSize"
                  v-model="parmValue.tid"
                  :maxlength="40"
                  @blur="
                    pageInfo.curr = 1;
                    parmValue.page = 1;
                    searchList();
                  "
                  placeholder="平台订单号"
                />
              </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 #type="{ scope }">
          <el-tag
            :size="tablebtnSize"
            :type="''"
            v-text="
              (type_list.find((item) => item.value == scope.row.type + '') || {}).label ||
              '--'
            "
          ></el-tag>
        </template>
        <template #is_del="{ scope }">
          <el-tag
            :size="tablebtnSize"
            :type="
              (is_del_list.find((item) => item.value == scope.row.is_del + '') || {})
                .type || '--'
            "
            v-text="
              (is_del_list.find((item) => item.value == scope.row.is_del + '') || {})
                .label || '--'
            "
          ></el-tag>
        </template>
      </ex-table>
    </div>
    <no-auth v-else></no-auth>
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/youzan/othOrderModifyAddressLog";
import mixinPage from "@/mixins/elPaginationHandle";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import { columns, type_list, is_del_list } from "./columns";
export default {
  name: "othOrderModifyAddressLog",
  mixins: [mixinPage, resToken],

  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "othOrderModifyAddressLog"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      loading: false,
      sitem: {},
      showRateModel: false,
      modelRateId: "000",
      sitemRate: {},
      select: "1",
      sinput: "",
      parmValue: {
        page: 1, // 页码
        size: 15, // 每页显示条数
        tid: "",
        start_date: "",
        end_date: "",
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns,
      type_list,
      is_del_list,
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    restSearch() {
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        page: 1, // 页码
        size: 15, // 每页显示条数
        tid: "",
        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();
      }
    },
    //点击详情
    getRouter(toRouter, queryId) {
      if (toRouter && queryId) {
        let model = {
          id: queryId,
          type: "view",
        };

        //有多选框的条件
        this.parmValue.select = this.select;
        // this.parmValue.sselect = this.sselect ;
        this.parmValue.sinput = this.sinput;
        //
        console.log(this.parmValue);
        let routerModel = {
          options: JSON.parse(JSON.stringify(this.parmValue)),
          router: this.$route.path,
        };
        model.preModel = JSON.stringify(routerModel);

        this.routeGoto(toRouter, model);
      } else {
        this.$message.warning("暂未找到相关流程！");
      }
    },
    // 刷新表格
    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 ?? {};

        let arr = list ?? [];
        arr.map((e) => {
          for (let key in e.data) {
            e[`key_${key}`] = e.data[key];
          }
          return e;
        });
        this.tableData = arr;
        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>
.othOrderModifyAddressLog {
  .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>
