diff --git a/app.json b/app.json index e20a7d1..f3a2b77 100644 --- a/app.json +++ b/app.json @@ -1,22 +1,21 @@ { "pages": [ "pages/login/index", - "pages/home/index", - "pages/handleLogin/index", "pages/apply/index", "pages/qrCode/index", + "pages/my/index", + "pages/home/index", + "pages/handleLogin/index", "pages/waitApprove/index", "pages/rechargeRecord/index", "pages/invoiceList/index", "pages/meterList/index", "pages/recharge/index", "pages/member/index", - "pages/my/index", "pages/questions/index", "pages/index/index", "pages/invoiceDetail/index", "pages/editInvoice/index" - ], "tabBar": { "list": [ diff --git a/pages/apply/index.js b/pages/apply/index.js index 786b80c..9f54fb7 100644 --- a/pages/apply/index.js +++ b/pages/apply/index.js @@ -1,3 +1,4 @@ +import { getTenementDetail } from "../../service/tenement"; import { userApply } from "../../service/user"; import { alertInfo, alertSuccess } from "../../utils/index"; import request from '../../utils/request' @@ -10,7 +11,8 @@ Page({ */ data: { id: "", - name: "", + tenement: {}, + nickName: "" }, /** @@ -18,12 +20,67 @@ Page({ */ onLoad(options) { const querys = decodeURIComponent(options.scene) - const { id, name } = querys; - this.setData({ id, name }) + const { id } = querys; + // this.setData({ id, name }) + this.getInfo(id); + }, + async getInfo(id) { + const { code, message, data } = await getTenementDetail(id); + if (code !== OK) { + alertInfo(message) + return + } + this.setData({ + tenement: data, + id + }) }, exit() { wx.exitMiniProgram() }, + onChangeName(e) { + this.setData({ + nickName: e.detail + }) + }, + async handleLogin(phoneCode) { + const { id, nickName } = this.data; + loadingFunc(async () => { + const wxLoginCode = await wxLogin() + const result = await userApply({ code: wxLoginCode, phoneCode, id, name: nickName }) + const { code, message, data } = result; + if (code !== OK) { + alertError(message) + return + } + if (!data?.id) { + this.noPermission() + return; + } + alertSuccess("登录成功") + const { token, ...user } = data + wx.setStorageSync('user', user) + wx.setStorageSync('token', data?.token) + wx.switchTab({ + url: '/pages/home/index', + }) + }) + }, + getPhoneNumber(e) { + const { errno, code: phoneCode } = e.detail; + switch(errno) { + case 103: + alertInfo("已拒绝"); + + return; + case 1400001: + alertInfo("服务达到上限") + return; + default: + this.handleLogin(phoneCode) + return; + } + }, async join() { const { id } = this.data; const { code, message, data } = await userApply({ id }) diff --git a/pages/apply/index.json b/pages/apply/index.json index 0b81116..92c79eb 100644 --- a/pages/apply/index.json +++ b/pages/apply/index.json @@ -1,5 +1,6 @@ { "usingComponents": { - "van-button": "@vant/weapp/button/index" + "van-button": "@vant/weapp/button/index", + "van-field": "@vant/weapp/field/index" } } \ No newline at end of file diff --git a/pages/apply/index.wxml b/pages/apply/index.wxml index d1a7c88..a802f9a 100644 --- a/pages/apply/index.wxml +++ b/pages/apply/index.wxml @@ -1,11 +1,21 @@ + 即将加入{{tenement.name}} + + + - 确定要加入{{name}}吗? 退出 - 确认 + 确认 diff --git a/pages/apply/index.wxss b/pages/apply/index.wxss index de189a4..42948cc 100644 --- a/pages/apply/index.wxss +++ b/pages/apply/index.wxss @@ -6,6 +6,7 @@ display: flex; justify-content: center; align-items: center; + flex-direction: column; } .text { @@ -24,3 +25,10 @@ margin-right: 40rpx; } +.nickName { + width: 95vw; + margin-bottom: 60rpx; + display: flex; + justify-content: center; +} + diff --git a/pages/qrCode/index.js b/pages/qrCode/index.js index d5bafad..2ddeeae 100644 --- a/pages/qrCode/index.js +++ b/pages/qrCode/index.js @@ -1,6 +1,7 @@ import request from "../../utils/request" import { getWxCode } from "../../service/user" -import { alertInfo } from "../../utils/index"; +import { alertInfo, loadingFunc } from "../../utils/index"; +import { getOwnTenementList } from "../../service/tenement"; const { OK } = request; @@ -10,19 +11,52 @@ Page({ * 页面的初始数据 */ data: { - url: "" + list: [], + urls: [], + indexs: [], }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { - this.getCode() + this.getList() }, - async getCode() { - const data = await getWxCode() + async getList() { + const { code, message, data } = await getOwnTenementList() + if (code !== OK) { + alertInfo(message) + return; + } + let tenements = []; + data?.forEach(item => { + const { tenements: ts = [] } = item; + tenements = [...tenements, ...ts]; + }) this.setData({ - url: wx.arrayBufferToBase64(data) + list: [...tenements] + }) + }, + async getCode(e, that) { + const { index, id } = e.currentTarget.dataset; + const { code, message, data } = await getWxCode(id) + if (code !== OK) { + alertInfo(message) + return; + } + const newUrls = that.data.urls; + newUrls[index] = data; + const newIndexs = that.data.indexs; + newIndexs[index] = true; + that.setData({ + urls: newUrls, + indexs: newIndexs, + }) + }, + look(e) { + const that = this; + loadingFunc(async () => { + await this.getCode(e, that) }) }, /** diff --git a/pages/qrCode/index.wxml b/pages/qrCode/index.wxml index e3e8993..8e47b94 100644 --- a/pages/qrCode/index.wxml +++ b/pages/qrCode/index.wxml @@ -1,7 +1,12 @@ - - + + + {{item.name}} + 查看二维码 + + + + - 扫码二维码,管理员同意后可进入 \ No newline at end of file diff --git a/pages/qrCode/index.wxss b/pages/qrCode/index.wxss index 832d66e..3e813c0 100644 --- a/pages/qrCode/index.wxss +++ b/pages/qrCode/index.wxss @@ -1,14 +1,37 @@ /* pages/qrCode/index.wxss */ .wrapper { - width: 100vw; + /* width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; - flex-direction: column; + flex-direction: column; */ + /* margin-top: 20rpx; */ + margin-left: 32rpx; + margin-right: 32rpx; } .text { text-align: center; margin-bottom: 15vh; +} + +.item { + margin: 20rpx 0; +} + +.tenement { + display: flex; + align-items: center; + +} + +.name { + flex: 1; +} + +.image { + margin: 50rpx 0; + display: flex; + justify-content: center; } \ No newline at end of file diff --git a/service/tenement.js b/service/tenement.js index 302ceff..0d502a5 100644 --- a/service/tenement.js +++ b/service/tenement.js @@ -4,4 +4,14 @@ const { GET, POST, PUT, DELETE } = apis // 获取园区id模糊搜索商户列表 export const getTenementList = async function({ park, keyword }) { return await GET(`/wx/getTenementList?park=${park}&keyword=${keyword}`); +} + +// 获取名下所有的商户 +export const getOwnTenementList = async function() { + return await GET(`/wx/getOwnTenements`); +} + +// 获取商户详情 +export const getTenementDetail = async function(id) { + return await GET(`/wx/getTenementDetail/${id}`); } \ No newline at end of file diff --git a/service/user.js b/service/user.js index d929995..018380b 100644 --- a/service/user.js +++ b/service/user.js @@ -12,8 +12,8 @@ export const userValidate = async function(data) { } // 获取用户邀请二维码 -export const getWxCode = async function(data) { - return await GET('/wx/getWxCode', data); +export const getWxCode = async function(id) { + return await GET(`/wx/getWxCode?id=${id}`); } // 获取扫描二维码的列表 @@ -41,7 +41,7 @@ export const reApprove = async function() { return await POST('/wx/reApprove'); } -// 非管理员重新提交申请 +// 非管理员扫码 export const userApply = async function(data) { return await POST('/wx/apply', data); } \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index 7802d9d..e3c3412 100644 --- a/utils/request.js +++ b/utils/request.js @@ -26,7 +26,8 @@ const request = async function (options, config = {}) { Accept: 'application/json', 'content-type': 'application/json; charset=utf-8', "Authorization": token, - "env": "trial", + // "env": "trial", + "env": envVersion, ...config }; console.log('config', config)