"use strict";
const common_vendor = require("../../../../common/vendor.js");
const components_request = require("../../../../components/request.js");
const components_TimeFormatting = require("../../../../components/TimeFormatting.js");
const components_goEasyTool_tool = require("../../../../components/goEasyTool/tool.js");
const _sfc_main = {
  props: {
    oppositeId: {
      type: String,
      required: true
    },
    myId: {
      type: String,
      required: true
    },
    nickname: {
      type: String,
      required: true
    },
    avatar: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      select: null,
      // 选择主播对象（1:对方主播，0：自己主播）
      mylist: [],
      // 自己主播列表
      oppositlist: [],
      // 对方主播列表
      selectedId: null,
      // 选择的主播id
      selectIndex: null,
      // 选择的主播索引
      myselect: null,
      // 自己选择的主播对象
      oppositselect: null,
      // 对方选择的主播对象
      list: []
      // 渲染的主播列表
    };
  },
  created() {
    this.getAnchorList(this.oppositeId);
    this.getAnchorList(this.myId);
  },
  methods: {
    //发送pk消息
    send() {
      components_request.request({
        url: "pk/createPkRecord",
        method: "POST",
        data: {
          pkIdA: this.oppositselect.id,
          pkIdB: this.myselect.id,
          userIdA: this.oppositeId,
          userIdB: this.myId,
          pkTime: this.oppositselect.pkTime,
          pkNumber: this.oppositselect.pkNumber,
          anchorIdA: this.oppositselect.anchorId,
          anchorIdB: this.myselect.anchorId,
          anchorIconA: this.oppositselect.anchorIcon,
          anchorIconB: this.myselect.anchorIcon,
          piIdA: this.oppositselect.id,
          piIdB: this.myselect.id
        },
        userInfo: true
      }).then((res) => {
        if (res.code == 200) {
          const customData = {
            id: res.data.id,
            pkIdA: this.oppositselect.id,
            pkIdB: this.myselect.id
          };
          let order = {
            customData,
            link: "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/pk.png",
            text: "PK邀请消息"
          };
          let type = "pk";
          components_goEasyTool_tool.sendCustomMessage(
            this.$goeasy,
            type,
            this.oppositeId,
            order,
            this.avatar,
            this.nickname
          ).then((res2) => {
            this.$emit("refreshMessage", { message: res2 });
          });
          this.$refs.confirmpopup.close();
          this.$refs.oppositepopup.close();
          this.myselect = null;
          this.oppositselect = null;
          common_vendor.index.showToast({
            title: "发送成功",
            icon: "none"
          });
        } else {
          common_vendor.index.showToast({
            title: res.msg,
            icon: "none"
          });
        }
      });
    },
    confirmClose() {
      this.$refs.confirmpopup.close();
    },
    //发送pk消息
    sendMessage() {
      if (this.myselect && this.oppositselect) {
        this.$refs.confirmpopup.open("center");
      } else {
        common_vendor.index.showToast({
          title: "请选择相应的主播",
          icon: "none"
        });
      }
    },
    //选中
    Select(id, index) {
      if (this.selectedId === id) {
        this.selectedId = null;
        this.selectIndex = null;
      } else {
        this.selectedId = this.selectedId === id ? null : id;
        this.selectIndex = index;
      }
    },
    //取消
    close() {
      this.$refs.oppositepopup.close();
    },
    //确定
    invite() {
      if (this.selectedId) {
        if (this.select == 1) {
          this.oppositselect = this.oppositlist[this.selectIndex];
          this.selectedId = null;
          this.selectIndex = null;
        } else {
          this.myselect = this.mylist[this.selectIndex];
          this.selectedId = null;
          this.selectIndex = null;
        }
      } else {
        common_vendor.index.showToast({
          title: "请选择主播",
          icon: "none"
        });
      }
      this.$refs.oppositepopup.close();
    },
    TimeFormatting: components_TimeFormatting.TimeFormatting,
    //获取主播列表
    getAnchorList(id) {
      components_request.request({
        url: "pk/listUninvitedPublishedAnchorsByUserId",
        method: "POST",
        data: {
          userId: id
        },
        userInfo: false
      }).then((res) => {
        if (res.code == 200) {
          if (id == this.myId) {
            this.mylist = res.data;
            common_vendor.index.__f__("log", "at pages/index/chat/moreMessageComponents/InvitationComponents.vue:325", "mylist", this.mylist);
          } else {
            this.oppositlist = res.data;
            common_vendor.index.__f__("log", "at pages/index/chat/moreMessageComponents/InvitationComponents.vue:328", "oppositlist", this.oppositlist);
          }
        } else {
          common_vendor.index.showToast({
            title: res.msg,
            icon: "none"
          });
        }
      });
    },
    showPopup(select) {
      if (select == 1) {
        this.list = this.oppositlist;
      } else {
        this.list = this.mylist;
      }
      this.select = select;
      this.$refs.oppositepopup.open("center");
    }
  }
};
if (!Array) {
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  _easycom_uni_popup2();
}
const _easycom_uni_popup = () => "../../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  _easycom_uni_popup();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.oppositselect != null
  }, $data.oppositselect != null ? {
    b: $data.oppositselect.anchorIcon,
    c: common_vendor.t($data.oppositselect.anchorId),
    d: common_vendor.t($options.TimeFormatting($data.oppositselect.pkTime)),
    e: common_vendor.t($data.oppositselect.coin)
  } : {}, {
    f: $data.oppositselect == null
  }, $data.oppositselect == null ? {} : {}, {
    g: common_vendor.o(($event) => $options.showPopup(1)),
    h: $data.myselect != null
  }, $data.myselect != null ? {
    i: $data.myselect.anchorIcon,
    j: common_vendor.t($data.myselect.anchorId),
    k: common_vendor.t($options.TimeFormatting($data.myselect.pkTime)),
    l: common_vendor.t($data.myselect.coin)
  } : {}, {
    m: $data.myselect == null
  }, $data.myselect == null ? {} : {}, {
    n: common_vendor.o(($event) => $options.showPopup(0)),
    o: common_vendor.o(($event) => $options.sendMessage()),
    p: common_vendor.o(() => {
    }),
    q: common_vendor.t($data.select == 1 ? "点击选择您要参与PK的对方主播" : "点击选择您要参与的主播"),
    r: $data.list.length > 0
  }, $data.list.length > 0 ? {
    s: common_vendor.f($data.list, (item, index, i0) => {
      return {
        a: item.anchorIcon,
        b: common_vendor.t(item.anchorId),
        c: common_vendor.t($options.TimeFormatting(item.pkTime)),
        d: common_vendor.t(item.coin),
        e: common_vendor.o(($event) => $options.Select(item.id, index), index),
        f: $data.selectedId === item.id ? "#b8ff8c74" : "#ffffff",
        g: index
      };
    })
  } : {}, {
    t: $data.list.length == 0
  }, $data.list.length == 0 ? {
    v: common_vendor.t($data.select == 1 ? "对方还没有发布过pk" : "您还没有发布过pk")
  } : {}, {
    w: common_vendor.o(($event) => $options.invite()),
    x: common_vendor.o(($event) => $options.close()),
    y: common_vendor.sr("oppositepopup", "a505124c-0"),
    z: common_vendor.o(_ctx.change),
    A: common_vendor.p({
      ["background-color"]: "#fff",
      ["border-radius"]: "30px"
    }),
    B: common_vendor.o(($event) => $options.send()),
    C: common_vendor.o(($event) => $options.confirmClose()),
    D: common_vendor.sr("confirmpopup", "a505124c-1"),
    E: common_vendor.o(_ctx.change),
    F: common_vendor.p({
      ["background-color"]: "#fff",
      ["border-radius"]: "30px"
    })
  });
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a505124c"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/pages/index/chat/moreMessageComponents/InvitationComponents.js.map
