"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_js_net_UserApi = require("../../../common/js/net/UserApi.js");
const common_js_net_projectApi = require("../../../common/js/net/projectApi.js");
const common_js_util = require("../../../common/js/util.js");
const common_js_data = require("../../../common/js/data.js");
const common_assets = require("../../../common/assets.js");
const _sfc_main = {
  data() {
    return {
      contentHeight: 100,
      totalHeight: 50,
      statusBarHeight: 24,
      allCount: 0,
      materialCount: 0,
      accountInfo: {},
      animationData: {},
      animation: null,
      alertMsg: "",
      //alertDialog提示内容
      menuList: common_js_data.menuList,
      msgType: "info",
      msgTxt: "",
      allPrice: 0,
      //全托管价格
      materialPrice: 0,
      //写材料价格
      urgent: 0
      //加急价格
    };
  },
  onLoad() {
    const animation = common_vendor.index.createAnimation({
      duration: 1e3,
      timingFunction: "ease"
    });
    this.animation = animation;
    this.doGetPrice();
    this.countBarHeight();
  },
  onReady() {
    this.calculateRemainingHeight();
  },
  onShow() {
    this.getMineAccount();
    this.getMinePackageCount();
  },
  onPullDownRefresh() {
    this.getMineAccount();
    this.getMinePackageCount();
    common_vendor.index.stopPullDownRefresh();
  },
  methods: {
    //计算状态栏等高度
    countBarHeight() {
      const deviceInfo = common_vendor.index.getSystemInfoSync();
      this.statusBarHeight = deviceInfo.statusBarHeight;
      this.totalHeight = deviceInfo.osName.toLowerCase() == "ios" ? 48 : 50;
      common_vendor.index.__f__("log", "at pages/mine/mineIndex/mineIndex.vue:132", "手机平台", deviceInfo.osName);
    },
    //计算高度
    calculateRemainingHeight() {
      const systemInfo = common_vendor.index.getSystemInfoSync();
      const windowHeight = systemInfo.windowHeight;
      const screenWidth = systemInfo.screenWidth;
      const screenHeight = systemInfo.screenHeight;
      common_vendor.index.__f__("log", "at pages/mine/mineIndex/mineIndex.vue:142", windowHeight);
      const query = common_vendor.index.createSelectorQuery().in(this);
      query.select("#func-box").boundingClientRect((data) => {
        if (data) {
          const occupiedHeight = data.height;
          let tabbarHeight = screenHeight - windowHeight;
          this.contentHeight = windowHeight - occupiedHeight - tabbarHeight - 20;
          let coverHeight = common_js_util.pxToRpx(this.contentHeight, screenWidth);
          this.contentHeight = coverHeight;
        } else {
          common_vendor.index.__f__("log", "at pages/mine/mineIndex/mineIndex.vue:161", "未获取到高度");
        }
      }).exec();
    },
    //刷新账户
    doRefresh() {
      const _self = this;
      _self.playAnimation();
      _self.getMineAccount();
      _self.getMinePackageCount();
      _self.doGetPrice();
    },
    //跳转支付
    doPay() {
      common_vendor.index.navigateTo({
        url: "/pages/pay/payment/payment"
      });
    },
    //跳转创建
    openCreate(e) {
      common_vendor.index.navigateTo({
        url: "/pages/mine/mineAccount/minePackageRecord/minePackageRecord"
      });
    },
    //跳转优惠卷
    doCoupons() {
      common_vendor.index.navigateTo({
        url: "/pages/mine/mineAccount/mineCoupons/mineCoupons"
      });
    },
    //跳转页面
    itemClick(e) {
      const path = e.currentTarget.dataset.path;
      e.currentTarget.dataset.title;
      common_vendor.index.navigateTo({
        url: path
      });
    },
    //获取单价
    doGetPrice() {
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const _self = this;
      common_js_net_projectApi.ProApi.doGetPrice().then((res) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/mine/mineIndex/mineIndex.vue:218", res);
        res.projTypes.forEach((el) => {
          if (el.type == "ALL") {
            _self.allPrice = el.price;
          } else if (el.type == "MATERIAL") {
            _self.materialPrice = el.price;
          }
        });
        _self.urgent = res.additional.urgent;
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = "网络错误,请刷新页面";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    //播放刷新动画
    playAnimation() {
      const _self = this;
      _self.animation.scale(1, 1).rotate(0).step({
        duration: 0
      });
      _self.animationData = _self.animation.export();
      _self.animation.scale(0.8, 0.8).rotate(180).step();
      _self.animation.scale(1, 1).rotate(360).step();
      _self.animationData = _self.animation.export();
      setTimeout(() => {
        _self.animationData = {};
      }, 1100);
    },
    //获取账户余额
    getMineAccount() {
      const _self = this;
      common_js_net_UserApi.UserApi.doGetMineAccount().then((res) => {
        _self.accountInfo = res;
      }).catch((err) => {
        _self.msgType = "error";
        _self.msgTxt = err.msg ? err.msg : "网络信号开小差啦，请您稍后再试，给您添麻烦～";
        _self.$refs.msg.open();
      });
    },
    //获取账户余额
    getMinePackageCount() {
      const _self = this;
      common_js_net_UserApi.UserApi.doGetMinePackageCount().then((res) => {
        _self.allCount = res.ALL;
        _self.materialCount = res.MATERIAL;
      }).catch((err) => {
        common_vendor.index.__f__("log", "at pages/mine/mineIndex/mineIndex.vue:273", err);
        _self.allCount = 0;
        _self.materialCount = 0;
        _self.msgType = "error";
        _self.msgTxt = err.msg ? err.msg : "网络信号开小差啦，请您稍后再试，给您添麻烦～";
        _self.$refs.msg.open();
      });
    },
    //获取套餐包详情
    doGetPackage(type) {
      const _self = this;
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      const data = {
        page: 1,
        rows: 10,
        packageType: type,
        keyong: 1
      };
      common_js_net_projectApi.ProApi.doGetPackageList(data).then((res) => {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("log", "at pages/mine/mineIndex/mineIndex.vue:296", res.rows);
        if (res.rows && res.rows.length > 0) {
          const packageId = res.rows[0].packageInfoId;
          const price = type == "ALL" ? _self.allPrice : _self.materialPrice;
          common_vendor.index.navigateTo({
            url: `/pages/copyright/createProjectInfo/createProjectInfo?type=${type}&price=${price}&isUrgent=false&pId=${packageId}`
          });
        } else {
          _self.msgTxt = "您的账户当前无套餐包，为正常使用请及时充值。";
          _self.msgType = "error";
          _self.$refs.msg.open();
        }
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = "获取套餐包失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    }
  }
};
if (!Array) {
  const _easycom_uni_popup_dialog2 = common_vendor.resolveComponent("uni-popup-dialog");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  (_easycom_uni_popup_dialog2 + _easycom_uni_popup2 + _easycom_uni_popup_message2)();
}
const _easycom_uni_popup_dialog = () => "../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.js";
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
const _easycom_uni_popup_message = () => "../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
if (!Math) {
  (_easycom_uni_popup_dialog + _easycom_uni_popup + _easycom_uni_popup_message)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_assets._imports_0$1,
    b: $data.totalHeight + "px",
    c: $data.statusBarHeight + "px",
    d: common_vendor.t($data.accountInfo.accountMoney / 100),
    e: $data.animationData,
    f: common_vendor.o((...args) => $options.doRefresh && $options.doRefresh(...args)),
    g: common_vendor.o((...args) => $options.doPay && $options.doPay(...args)),
    h: common_vendor.t($data.allCount),
    i: common_vendor.o((...args) => $options.openCreate && $options.openCreate(...args)),
    j: common_vendor.t($data.materialCount),
    k: common_vendor.o((...args) => $options.openCreate && $options.openCreate(...args)),
    l: common_vendor.o((...args) => $options.doCoupons && $options.doCoupons(...args)),
    m: common_vendor.f($data.menuList, (item, index, i0) => {
      return {
        a: index,
        b: common_vendor.n(item.icon),
        c: common_vendor.t(item.title),
        d: item.path
      };
    }),
    n: common_vendor.o((...args) => $options.itemClick && $options.itemClick(...args)),
    o: $data.contentHeight + "rpx",
    p: $data.contentHeight + "rpx",
    q: common_vendor.p({
      type: "info",
      ["show-close"]: false,
      confirmText: "关闭",
      title: "提示",
      content: $data.alertMsg
    }),
    r: common_vendor.sr("alertDialog", "34c18462-0"),
    s: common_vendor.p({
      type: "dialog"
    }),
    t: common_vendor.p({
      isTop: false,
      type: $data.msgType,
      message: $data.msgTxt,
      duration: 2e3
    }),
    v: common_vendor.sr("msg", "34c18462-2"),
    w: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-34c18462"]]);
swan.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-baidu/pages/mine/mineIndex/mineIndex.js.map
