Files
rlz/coupon/pages/my/my.js
renjianbo 1d0a0b9b04 feat: add request.js utility, service page, and fix hospital image URLs
- Add request.js for unified API calls with loading/error handling
- Add service page (service type listing)
- Fix hospital list to load from API with proper image URL construction
- Add service types dynamic loading on index page
- Various mini program improvements (order, care, wallet pages)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-07 10:13:26 +08:00

193 lines
3.9 KiB
JavaScript

var Token = require('../../utils/util.js');
const app = getApp()
const { request } = require('../../utils/request')
Page({
data: {
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'),
phone: wx.getStorageSync('phone'),
uidFlag: wx.getStorageSync('uidFlag'),
status: '',
code: '',
height: '',
logging: false
},
onLoad: function (options) {
var statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
this.setData({
statusBarHeight: statusBarHeight,
height: 46 + statusBarHeight,
});
},
onShow: function () {
// 仅在未登录时获取 code
if (!this.data.uidFlag) {
this.getLogin()
}
},
// 登录
getLogin() {
var that = this;
wx.login({
success: res => {
app.globalData.code = res.code
that.setData({ code: res.code })
}
})
},
// 获取电话号码并登录
async getPhoneNumber(e) {
if (this.data.logging) return
this.setData({ logging: true })
try {
var res = await request({
url: '/weixinLogin',
method: 'POST',
loading: true,
loadingText: '登录中...',
data: {
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
wxcode: app.globalData.code
}
})
app.globalData.phone = res.phone;
wx.setStorageSync('phone', res.data.phoneNumber);
wx.setStorageSync('uid', res.data.userId);
wx.setStorageSync('token', res.data.token);
wx.setStorageSync('uidFlag', true);
this.setData({
uidFlag: true,
phone: res.phone
})
app.globalData.uid = res.data.userId;
wx.showToast({ title: '登录成功', icon: 'success' })
// 同步登录信息到服务端(失败不影响登录)
this.syncLogin()
// 返回上一页,若无法返回则到首页
var pages = getCurrentPages()
if (pages.length > 1) {
wx.navigateBack()
} else {
wx.switchTab({ url: '/pages/index/index' })
}
} catch (e) {
this.setData({ logging: false })
}
},
// 同步登录信息
syncLogin() {
wx.request({
url: app.buildUrltwo("/member/logintwo"),
header: app.getRequestHeader(),
method: "POST",
data: {
name: wx.getStorageSync('uid'),
phone: wx.getStorageSync('phone'),
storename: wx.getStorageSync('token')
}
})
},
getUserBaseInfo: function () {
var that = this;
request({
url: '/getUserToken',
method: 'GET',
data: { phonenumber: this.data.phone },
loading: false
}).then(resp => {
if (resp.erro == 0) {
that.setData({ infor: resp.infor })
}
}).catch(() => {})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
shoucang() {
wx.navigateTo({
url: '/pages/myshoucang/myshoucang_index?' + "type=" + "1",
})
},
pintuan() {
wx.navigateTo({
// url: '/pages/myshoucang/myshoucang_index?'+"type="+"2",
url: '/pages/order/order',
})
},
kanjia() {
// wx.navigateTo({
// url: '/pages/myshoucang/myshoucang_index?'+"type="+"3",
// })
wx.showToast({
title: '暂无开放',
icon: 'none'
});
},
qianbao() {
wx.navigateTo({
url: '/pages/wodeqianbao/qianbao'
})
},
guanyu() {
wx.navigateTo({
url: '/pages/guanyu/guanyu'
})
},
})