"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_net_UserApi = require("../../../../common/js/net/UserApi.js");
const ContainerLoading = () => "../../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  setup() {
  },
  data() {
    return {
      currentStatus: "",
      msgList: [],
      //订单列表
      pageData: {
        page: 1,
        rows: 10,
        isRead: ""
        //默认已读
      },
      //检索参数
      loadingState: "loading",
      //加载状态
      listRefreshTrig: false,
      //list刷新状态
      isLoadMore: false,
      //加载更多的状态
      hasMore: "more",
      //是否有更多数据
      keywords: "",
      //搜索关键字
      msgType: "info",
      msgHint: ""
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "消息通知"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "easeIn"
      }
    });
    this.doRefreshList();
  },
  methods: {
    doChangeStatus(e) {
      this.currentStatus = e.currentTarget.dataset.value;
      this.doRefreshList();
    },
    doGetMineMsgList(isRefresh) {
      const _self = this;
      _self.msgList = isRefresh ? [] : _self.msgList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_UserApi.UserApi.doGetMineMsgNotice(_self.pageData).then((res) => {
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.msgList = _self.msgList.concat(res.rows);
        _self.isLoadMore = false;
        _self.hasMore = _self.msgList.length < res.total ? "more" : "noMore";
      }).catch((err) => {
        _self.loadingState = "error";
        _self.isLoadMore = false;
        _self.hasMore = "more";
      });
    },
    //下拉刷新
    doRefreshList() {
      const _self = this;
      _self.loadingState = "loading";
      _self.hasMore = "more";
      _self.pageData.page = 1;
      _self.pageData.isRead = _self.currentStatus;
      _self.isLoadMore = false;
      _self.doGetMineMsgList(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.hasMore == "noMore") {
        return;
      }
      _self.isLoadMore = true;
      _self.hasMore = "loading";
      _self.pageData.page = ++_self.pageData.page;
      _self.pageData.isRead = _self.currentStatus;
      _self.doGetMineMsgList(false);
    },
    readItem(e) {
      const item = e.currentTarget.dataset.value;
      if (item.isRead == 1) {
        return;
      }
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const _self = this;
      const ids = {
        ids: [item.userMsgId]
      };
      common_js_net_UserApi.UserApi.doReadMineMsgNotice(ids).then((res) => {
        common_vendor.index.hideLoading();
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgHint = err.msg ? err.msg : "操作失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    deleteItem(e) {
      const item = e.currentTarget.dataset.value;
      const _self = this;
      common_vendor.index.showModal({
        title: "警告",
        content: "您确定要删除该消息吗?",
        success: (res) => {
          if (res.confirm) {
            _self.doDeleteItem(item);
          }
        }
      });
    },
    //删除信息
    doDeleteItem(item) {
      const _self = this;
      common_vendor.index.showLoading({
        title: "删除中..."
      });
      common_js_net_UserApi.UserApi.doDeleteMineMsgNotice(item.userMsgId).then((res) => {
        common_vendor.index.hideLoading();
        _self.msgHint = "删除成功";
        _self.msgType = "success";
        _self.$refs.msg.open();
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgHint = err.msg ? err.msg : "删除失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    }
  },
  onPullDownRefresh() {
    this.doRefreshList();
    common_vendor.index.stopPullDownRefresh();
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
const _easycom_uni_load_more = () => "../../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_uni_popup_message = () => "../../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
const _easycom_uni_popup = () => "../../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_load_more + _easycom_uni_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.n($data.currentStatus == "" ? "border-select" : "border-normal"),
    b: common_vendor.o((...args) => $options.doChangeStatus && $options.doChangeStatus(...args)),
    c: common_vendor.n($data.currentStatus == "" ? "btn-select" : "btn-normal"),
    d: common_vendor.n($data.currentStatus == "0" ? "border-select" : "border-normal"),
    e: common_vendor.o((...args) => $options.doChangeStatus && $options.doChangeStatus(...args)),
    f: common_vendor.n($data.currentStatus == "0" ? "btn-select" : "btn-normal"),
    g: common_vendor.n($data.currentStatus == "1" ? "border-select" : "border-normal"),
    h: common_vendor.o((...args) => $options.doChangeStatus && $options.doChangeStatus(...args)),
    i: common_vendor.n($data.currentStatus == "1" ? "btn-select" : "btn-normal"),
    j: common_vendor.f($data.msgList, (item, index, i0) => {
      return {
        a: common_vendor.t(item.title),
        b: common_vendor.n(item.isRead == 0 ? "text-noread" : "text-read"),
        c: common_vendor.t(item.gmtCreate),
        d: item,
        e: common_vendor.t(item.content),
        f: common_vendor.n(item.isRead == 0 ? "text-noread" : "text-read"),
        g: item,
        h: item,
        i: index
      };
    }),
    k: common_vendor.o((...args) => $options.readItem && $options.readItem(...args)),
    l: common_vendor.o((...args) => $options.readItem && $options.readItem(...args)),
    m: common_vendor.o((...args) => $options.deleteItem && $options.deleteItem(...args)),
    n: common_vendor.p({
      status: $data.hasMore
    }),
    o: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    p: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    q: common_vendor.p({
      type: $data.msgType,
      message: $data.msgHint,
      duration: 2e3
    }),
    r: common_vendor.sr("msg", "2cd547e2-2"),
    s: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2cd547e2"]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-toutiao/pages/mine/mineAccount/mineMsgNotice/mineMsgNotice.js.map
