Liuyi
2024-11-27 98a835cc45adbe5ef8ee3cca5ad478f7df673b80
1
2
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
39
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const config_baseUrl = require("../../config/baseUrl.js");
const api_index = require("../../api/index.js");
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const topHeight = common_vendor.ref(0);
    function getTopHeight() {
      if (common_vendor.index.getMenuButtonBoundingClientRect) {
        topHeight.value = common_vendor.index.getMenuButtonBoundingClientRect().top * 2;
      }
    }
    const cardInfo = common_vendor.ref({
      id: "",
      userName: "微信用户",
      headImg: "",
      userPhone: "",
      integral: "",
      waterCardNumber: "",
      balance: "",
      count: "",
      state: "",
      //state:true:挂失,false:正常
      cardType: "",
      //卡类型01卡消费 02计次消费 03游客消费 04电子卡
      userCardType: ""
      //userCardType:true:共享卡,false:正常卡
    });
    const isLoss = common_vendor.ref(false);
    const isVip = common_vendor.ref(false);
    const isShareCard = common_vendor.ref(false);
    async function getVipInfo() {
      await api_index.getVipInfoApi().then((res) => {
        if (res.code == 200 && res.data.id) {
          console.log("获取会员卡返回响应-首页", res);
          cardInfo.value.waterCardNumber = res.data.cardNumber;
          cardInfo.value.cardType = res.data.cardType;
          cardInfo.value.state = res.data.state == 2 ? true : false;
          cardInfo.value.userCardType = res.data.userCardType == 2 ? true : false;
          isLoss.value = cardInfo.value.state;
          isShareCard.value = cardInfo.value.userCardType;
          if (res.data.cardType == 1) {
            cardInfo.value.balance = res.data.balance;
          } else if (res.data.cardType == 2) {
            cardInfo.value.count = res.data.count;
          }
          isVip.value = true;
          console.log("cardInfo", cardInfo.value, "isShareCard.value", isShareCard.value);
        }
      });
    }
    async function getInfo() {
      await api_index.getUserInfo().then(async (res) => {
        if (res.code == 200) {
          cardInfo.value.userName = res.data.userInfo.userName ? res.data.userInfo.userName : cardInfo.value.userName;
          cardInfo.value.headImg = res.data.userInfo.headImg;
          cardInfo.value.integral = res.data.userInfo.integral;
          cardInfo.value.userPhone = res.data.userInfo.userPhone;
          cardInfo.value.id = res.data.userInfo.id;
          await getVipInfo();
          console.log("00000", cardInfo.value);
          common_vendor.index.setStorageSync("userInfo", JSON.stringify(cardInfo.value));
        }
      });
    }
    function toScan() {
      common_vendor.index.scanCode({
        scanType: ["qrCode"],
        success: async function(res) {
          console.log("条码内容:" + res.result);
          common_vendor.index.navigateTo({
            url: `/pages/scanWater/index?facilityCode=${res.result}`
          });
        }
      });
    }
    const functionList = common_vendor.ref([
      { text: "余额记录", icon: "../../static/images/index/icon31.png", bgColor: "#16b387", url: "/pages/functionList/balanceRecord/index", isUrl: 1 },
      { text: "消费记录", icon: "../../static/images/index/icon32.png", bgColor: "#329ae8", url: "/pages/functionList/paymentRecord/index", isUrl: 1 },
      { text: "充值记录", icon: "../../static/images/index/icon33.png", bgColor: "#f0a50e", url: "/pages/functionList/rechargeRecord/index", isUrl: 1 },
      { text: "水卡共享", icon: "../../static/images/index/icon34.png", bgColor: "#55ca8c", url: "/pages/functionList/share/cardShare/index", isUrl: 1 },
      { text: "故障上报", icon: "../../static/images/index/icon35.png", bgColor: "#a88ff1", url: "/pages/infoBreakdown/index", isUrl: 1 },
      { text: "优惠卷", icon: "../../static/images/index/icon36.png", bgColor: "#18bfc4", url: "", isUrl: 4 },
      { text: "会员卡挂失", icon: "../../static/images/index/icon37.png", bgColor: "#4875f0", url: "", isUrl: 2 },
      { text: "会员卡解绑", icon: "../../static/images/index/icon38.png", bgColor: "#f45088", url: "", isUrl: 3 }
    ]);
    function navTo(itemUrl) {
      if (itemUrl) {
        common_vendor.index.navigateTo({
          url: itemUrl
        });
      }
    }
    async function setEvent(isUrl, url) {
      if (isUrl == 1) {
        navTo(url);
      } else if (isUrl == 2) {
        if (cardInfo.value.waterCardNumber) {
          if (!isShareCard.value && !cardInfo.value.state) {
            common_vendor.index.showModal({
              title: "会员卡挂失",
              content: "确认挂失会员卡?",
              success: async function(res) {
                if (res.confirm) {
                  await api_index.reportLossApi(cardInfo.value.waterCardNumber).then(async (res2) => {
                    if (res2.code == 200) {
                      common_vendor.index.showToast({
                        title: "已挂失",
                        duration: 2e3
                      });
                      await api_index.getVipInfoApi().then((res3) => {
                        if (res3.code == 200) {
                          if (res3.data.state == 2) {
                            isLoss.value = true;
                          }
                        }
                      });
                    }
                  });
                }
              }
            });
          } else if (isShareCard.value) {
            common_vendor.index.showToast({
              title: "共享卡无权限",
              icon: "none"
            });
          } else if (cardInfo.value.state) {
            common_vendor.index.showToast({
              title: "已挂失",
              icon: "none"
            });
          }
        } else {
          common_vendor.index.showToast({
            title: "未绑定会员卡!",
            icon: "none"
          });
        }
      } else if (isUrl == 3) {
        if (cardInfo.value.waterCardNumber) {
          if (!isShareCard.value) {
            common_vendor.index.showModal({
              title: "会员卡注销",
              content: "确认注销会员卡?",
              success: async function(res) {
                if (res.confirm) {
                  await api_index.removeCardApi(cardInfo.value.waterCardNumber).then(async (res2) => {
                    if (res2.code == 200) {
                      common_vendor.index.showToast({
                        title: "已注销",
                        duration: 2e3,
                        icon: "none"
                      });
                      await api_index.getVipInfoApi().then((res3) => {
                        if (res3.code == 200) {
                          if (!res3.data.id) {
                            isVip.value = false;
                            cardInfo.value.balance = "";
                            cardInfo.value.count = "";
                            cardInfo.value.waterCardNumber = "";
                            common_vendor.index.setStorageSync("userInfo", JSON.stringify(cardInfo.value));
                          }
                        }
                      });
                    }
                  });
                }
              }
            });
          } else {
            common_vendor.index.showToast({
              title: "共享卡无权限",
              icon: "none"
            });
          }
        } else {
          common_vendor.index.showToast({
            title: "未绑定会员卡!",
            icon: "none"
          });
        }
      } else {
        upGrade();
      }
    }
    function upGrade() {
      common_vendor.index.showToast({
        title: "该功能正在升级中!",
        duration: 1e3,
        icon: "none"
      });
    }
    let userLocation = {
      lat: "",
      lon: ""
    };
    function getUserLocation() {
      common_vendor.index.authorize({
        scope: "scope.userLocation",
        success() {
          console.log("成功授权位置信息1");
          storageLocation();
        },
        fail() {
          console.log("用户拒绝授权位置信息,再次提示用户授权");
          showToast();
        }
      });
      function storageLocation() {
        common_vendor.index.getLocation({
          type: "gcj02",
          isHighAccuracy: true,
          success: (res) => {
            userLocation.lat = res.latitude;
            userLocation.lon = res.longitude;
            common_vendor.index.setStorageSync("userLocation", JSON.stringify(userLocation));
          },
          fail: () => {
            showToast();
          }
        });
      }
      function showToast() {
        common_vendor.index.showModal({
          title: "请求授权当前位置",
          content: "请求获取您的位置,加载附近饮水设备信息!",
          confirmText: "前往设置",
          success: (res) => {
            if (res.confirm) {
              common_vendor.index.openSetting({
                success: (res1) => {
                  if (res1.authSetting["scope.userLocation"]) {
                    console.log("用户二次授权成功");
                    setTimeout(() => {
                      storageLocation();
                    }, 1e3);
                  } else {
                    showToast();
                    console.log("用户拒绝授权");
                  }
                }
              });
            } else {
              common_vendor.index.showToast({
                title: "请先授权!",
                duration: 2e3,
                icon: "none"
              });
              showToast();
            }
          }
        });
      }
    }
    common_vendor.onMounted(async () => {
      getTopHeight();
      await getInfo();
      await getUserLocation();
      console.log("进入首页了");
    });
    common_vendor.onShow(async () => {
      getTopHeight();
      await getInfo();
    });
    common_vendor.index.showShareMenu({
      withShareTicket: true,
      menus: ["shareAppMessage", "shareTimeline"],
      success: function() {
        console.log("分享菜单显示成功");
      },
      fail: function(err) {
        console.error("分享菜单显示失败", err);
      }
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: cardInfo.value.headImg
      }, cardInfo.value.headImg ? {
        b: common_vendor.unref(config_baseUrl.BASE_URL) + "/upload" + cardInfo.value.headImg
      } : {
        c: common_assets._imports_0$4
      }, {
        d: common_vendor.t(cardInfo.value.userName),
        e: common_vendor.o(($event) => navTo("/pages/userInfo/index")),
        f: common_vendor.o(($event) => navTo("/pages/userInfo/index")),
        g: common_assets._imports_1$2,
        h: common_assets._imports_0$3,
        i: isShareCard.value
      }, isShareCard.value ? {
        j: common_vendor.t(cardInfo.value.waterCardNumber)
      } : {}, {
        k: !isShareCard.value
      }, !isShareCard.value ? common_vendor.e({
        l: isVip.value
      }, isVip.value ? {
        m: common_assets._imports_3$1
      } : {}, {
        n: isVip.value
      }, isVip.value ? {} : {}, {
        o: !isVip.value
      }, !isVip.value ? {} : {}, {
        p: isLoss.value && isVip.value
      }, isLoss.value && isVip.value ? {} : {}, {
        q: isVip.value
      }, isVip.value ? {
        r: common_vendor.t(cardInfo.value.waterCardNumber)
      } : {}, {
        s: isVip.value
      }, isVip.value ? {} : {}, {
        t: isVip.value
      }, isVip.value ? {
        v: common_vendor.t(cardInfo.value.balance)
      } : {}, {
        w: !isVip.value
      }, !isVip.value ? {
        x: common_assets._imports_4$1,
        y: common_vendor.o(($event) => navTo("/pages/addCard/index"))
      } : {}, {
        z: isVip.value
      }, isVip.value ? {
        A: common_vendor.o(($event) => navTo("/pages/recharge/index"))
      } : {}) : {}, {
        B: topHeight.value + "rpx",
        C: common_assets._imports_5,
        D: common_vendor.o(($event) => navTo("/pages/preSendWater/index")),
        E: common_assets._imports_1$1,
        F: common_vendor.o(($event) => navTo("/pages/facilityList/index")),
        G: common_assets._imports_7,
        H: common_vendor.o(($event) => toScan()),
        I: common_vendor.f(functionList.value, (item, index, i0) => {
          return {
            a: item.icon,
            b: item.bgColor,
            c: common_vendor.t(item.text),
            d: common_vendor.o(($event) => setEvent(item.isUrl, item.url), index),
            e: index
          };
        }),
        J: common_assets._imports_8,
        K: common_assets._imports_9,
        L: common_assets._imports_10,
        M: common_assets._imports_11,
        N: common_vendor.o(($event) => navTo("/pagesPoints/pointsMall/index")),
        O: common_assets._imports_12,
        P: common_assets._imports_13,
        Q: common_vendor.o(($event) => navTo("/pages/station/index")),
        R: common_assets._imports_14,
        S: common_assets._imports_13,
        T: common_vendor.o(upGrade)
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]);
wx.createPage(MiniProgramPage);