index.js 3.44 KB
Newer Older
李嘉林 committed
1
const app = getApp();
张卓 committed
2
const { $themeToLink, processEnv, globalData, concatUrl } = app;
李嘉林 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true
  },
  behaviors: [],
  properties: {},
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
    showPop: false,
    custom: {
      textShow: 1,
      itemList: [1, 1, 1],
      itemListInfo: [],
      href: "",
      toPage: "", //跳转的页面
      callback: "", //回调函数
      extends: {} //额外参数
    },
    distributorVal: "",
    type: 0,
    phone: "",
    href: "",
    posterId: -1,
    spokesmanGroupId: "",
    spokesmanShopId: "",
    spokesmanRelId: "",
    hasInvitationStatus: 0,
    nickname: "",
    shareGoodsInfo: {},

    giftIsSend: false,
    miniProgram: 0,
    flag: false,
    productId: "",
李嘉林 committed
39
    copyLink: ""
李嘉林 committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
  },
  // 数据监听器
  observers: {},
  // 组件方法
  methods: {
    init() {
      let _this = this;
      let { custom } =this.data;
      app.shareInit = function(list) {
        for (const key in list) {
          if (list.hasOwnProperty(key)) {
            if (custom[key] !== "undefined" && custom[key] !== undefined && list[key] !== "undefined" && list[key] !== undefined) {
              custom[key] = list[key];
            }
          }
        }
        _this.setData({ custom });
        _this.showPopup();
      };
    },
    showPopup() {
      this.setData({ showPop: true });
    },

    onClose() {
      this.setData({ showPop: false });
    },
    cancel() {
      this.onClose();
    },
    copyText(e) {
张卓 committed
71 72 73 74 75
      let pagePath = `${processEnv.BASE_URL}?mixid=${globalData.shopInfo.shopCode}`;
      let copyVal = pagePath;
      app.fenxiaoModel.getSpokesmanidByShare().then(res=>{
        if (res.hasInvitationStatus == 1) {
          copyVal = concatUrl(copyVal,res)
李嘉林 committed
76
        }
张卓 committed
77 78 79 80 81 82 83 84 85 86 87 88
        console.log(copyVal,11111222)
        wx.setClipboardData({
          data: copyVal,
          success: function(res) {
            wx.getClipboardData({
              success: function(res) {
                wx.showToast({ title: "复制成功" });
              }
            });
          }
        });
      })
李嘉林 committed
89 90
    },
    toPosters() {
李嘉林 committed
91 92
      let userInfo = wx.getStorageSync("userInfo") ? JSON.parse(wx.getStorageSync("userInfo")):'';
      let queryHref = `${processEnv.BASE_URL}?mixid=${globalData.shopInfo.shopCode}`;
张卓 committed
93 94 95 96 97 98 99 100 101 102 103
      app.fenxiaoModel.getSpokesmanidByShare().then(res=>{
        if (res.hasInvitationStatus == 1) {
          queryHref = concatUrl(queryHref,res)
        }
        let linkVal = `/goods/posters?type=index&href=${queryHref}`;
        if (userInfo) {
          linkVal += `&nickname=${userInfo.nickName}`;
        }
        console.log(linkVal, "------------------linkVal");
        $themeToLink({ type: 1, link: linkVal });
      })
李嘉林 committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    },
  },
  // 组件生命周期
  lifetimes: {
    created() {},
    attached() {
      this.init();
    },
    ready() {},
    moved() {},
    detached() {}
  },
  definitionFilter() {},
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data;

      // show事件发生前,页面不是处于隐藏状态时
      if (!isPageHidden) {
        return;
      }

      // 重新执行定时器等操作
    },
    // 页面被隐藏
    hide() {
      this.setData({
        isPageHidden: true
      });

      // 清除定时器等操作
    },
    // 页面尺寸变化时
    resize() {}
  }
};

Component(componentOptions);