"use strict";
const common_vendor = require("../../../common/vendor.js");
const components_request = require("../../../components/request.js");
const components_formatDate = require("../../../components/formatDate.js");
const _sfc_main = {
  data() {
    return {
      triggered: false,
      // 下拉刷新状态
      current: 1,
      // 初始激活状态
      buttonWidth: 238.55,
      // 按钮宽度
      gap: 0,
      // 按钮间距
      slidetext: "我发布的PK",
      // 导航栏文字
      pkmyRecordlist: [],
      // PK记录列表
      pkInvitationRecordlist: [],
      // PK记录列表
      pkRecordlist: [],
      // PK记录列表
      userinfo: {},
      // 用户信息
      page: 0
      // 页码
    };
  },
  onLoad() {
    common_vendor.index.getStorage({
      key: "userinfo",
      success: (res) => {
        this.userinfo = res.data;
        this.getPkRecordList(1);
        this.getPkRecordList(2);
      }
    });
  },
  computed: {
    sliderPosition() {
      const { current, buttonWidth, gap } = this;
      const containerPadding = 0;
      const offset = (buttonWidth + gap) * (current - 1);
      return containerPadding + offset + 375;
    }
  },
  methods: {
    onRefresherRefresh() {
      this.pkRecordlist = [];
      this.triggered = true;
      this.page = 0;
      if (this.current === 1) {
        this.pkmyRecordlist = [];
      } else {
        this.pkInvitationRecordlist = [];
      }
      this.getPkRecordList(this.current);
    },
    onScrollToLower() {
      this.page++;
      this.getPkRecordList(this.current);
    },
    onItemClick(item) {
      common_vendor.index.navigateTo({
        url: "/pages/Mine/minecomponents/DetailsPKRecords/DetailsPKRecords",
        success: (res) => {
          res.eventChannel.emit("itemDetail", {
            item
          });
        }
      });
    },
    onBack() {
      common_vendor.index.navigateBack(
        {
          delta: 1
        }
      );
    },
    formatDate: components_formatDate.formatDate,
    //获取我发布的PK记录列表
    getPkRecordList(type) {
      components_request.request({
        url: "user/handlePkInfo",
        method: "POST",
        data: {
          type,
          userId: this.userinfo.id,
          page: this.page,
          size: 10
        },
        userInfo: true
      }).then((res) => {
        if (res.code === 200) {
          this.triggered = false;
          if (type === 1) {
            this.pkmyRecordlist.push(...res.data);
            if (this.current === 1) {
              this.pkRecordlist = this.pkmyRecordlist;
            }
          } else {
            this.pkInvitationRecordlist.push(...res.data);
            if (this.current === 2) {
              this.pkRecordlist = this.pkInvitationRecordlist;
            }
          }
        } else {
          common_vendor.index.__f__("log", "at pages/Mine/minecomponents/pkRecord.vue:192", res.msg);
        }
      });
    },
    //按钮点击
    toggleActive(val) {
      this.current = val;
      this.slidetext = val === 1 ? "我发布的PK" : "我邀请的PK";
      if (val === 1) {
        this.pkRecordlist = this.pkmyRecordlist;
      } else {
        this.pkRecordlist = this.pkInvitationRecordlist;
      }
    }
  }
};
if (!Array) {
  const _component_uni_card = common_vendor.resolveComponent("uni-card");
  _component_uni_card();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.o$1((...args) => $options.onBack && $options.onBack(...args)),
    b: common_vendor.o$1(($event) => $options.toggleActive(1)),
    c: $data.current === 1 ? 1 : "",
    d: common_vendor.o$1(($event) => $options.toggleActive(2)),
    e: $data.current === 2 ? 1 : "",
    f: common_vendor.t($data.slidetext),
    g: $options.sliderPosition + "rpx",
    h: $data.pkRecordlist.length !== 0
  }, $data.pkRecordlist.length !== 0 ? {
    i: common_vendor.f($data.pkRecordlist, (item, index, i0) => {
      return common_vendor.e({
        a: item.anchorIconA,
        b: item.winnerAnchorId == item.anchorIdA
      }, item.winnerAnchorId == item.anchorIdA ? {} : {}, {
        c: common_vendor.t(item.anchorIdA),
        d: common_vendor.t($options.formatDate(item.pkTime)),
        e: item.userACoins !== null
      }, item.userACoins !== null ? {
        f: common_vendor.t(item.userACoins)
      } : {}, {
        g: common_vendor.t(item.anchorIdB),
        h: common_vendor.t($options.formatDate(item.pkTime)),
        i: item.userBCoins !== null
      }, item.userBCoins !== null ? {
        j: common_vendor.t(item.userBCoins)
      } : {}, {
        k: item.anchorIconB,
        l: item.winnerAnchorId == item.anchorIdB
      }, item.winnerAnchorId == item.anchorIdB ? {} : {}, {
        m: common_vendor.o$1(($event) => $options.onItemClick(item), index),
        n: index,
        o: "6fa696de-0-" + i0
      });
    }),
    j: common_vendor.o$1((...args) => $options.onRefresherRefresh && $options.onRefresherRefresh(...args)),
    k: common_vendor.o$1((...args) => $options.onScrollToLower && $options.onScrollToLower(...args)),
    l: $data.triggered
  } : {}, {
    m: $data.pkRecordlist.length === 0
  }, $data.pkRecordlist.length === 0 ? {} : {});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6fa696de"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/Mine/minecomponents/pkRecord.js.map
