新增首页园区和商户的交互

This commit is contained in:
qiaomu 2024-03-29 17:26:08 +08:00
parent 2b45de5a7f
commit 3284bea475
13 changed files with 193 additions and 30 deletions

View File

@ -1,8 +1,8 @@
{
"pages": [
"pages/home/index",
"pages/my/index",
"pages/handleLogin/index",
"pages/my/index",
"pages/member/index",
"pages/login/index",
"pages/apply/index",

View File

@ -1,2 +1,4 @@
<!--components/avatar/index.wxml-->
<view class="wrapper">{{text}}</view>
<view class="wrapper">
<view class="text">{{text}}</view>
</view>

View File

@ -9,3 +9,8 @@
align-items: center;
color: #fff;
}
.text {
max-width: 100rpx;
overflow: hidden;
}

View File

@ -0,0 +1,38 @@
// components/picker/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
valueKey: {
type: String,
default: "name"
},
show: Boolean,
columns: Array,
type: String
},
/**
* 组件的初始数据
*/
data: {
// columns:['杭州', '宁波', '温州', '嘉兴', '湖州']
},
/**
* 组件的方法列表
*/
methods: {
onClose() {
this.triggerEvent("close");
},
confirm(e) {
this.triggerEvent("ok", {...e.detail, type: this.data.type})
},
cancel() {
this.triggerEvent("cancel")
}
}
})

View File

@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"van-popup": "@vant/weapp/popup/index",
"van-picker": "@vant/weapp/picker/index"
}
}

View File

@ -0,0 +1,11 @@
<!--components/picker/index.wxml-->
<van-popup
show="{{ show }}"
position="bottom"
bind:close="onClose"
>
<view style="width: 100vw;">
<van-picker show-toolbar
title="标题" columns="{{ columns }}" bind:change="onChange" value-key="name" bind:confirm="confirm" bind:cancel="cancel" />
</view>
</van-popup>

View File

@ -0,0 +1 @@
/* components/picker/index.wxss */

View File

@ -19,16 +19,8 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('options', options)
const querys = decodeURIComponent(options.scene)
console.log('querys', querys)
// const search = new URLSearchParams(querys)
// const { id } = querys;
const id = querys.slice(querys.indexOf("=") + 1)
// const id = seach.get('id')
console.log('更换')
console.log('id', id)
// this.setData({ id, name })
this.getInfo(id);
},
async getInfo(id) {
@ -52,11 +44,8 @@ Page({
},
async handleLogin(phoneCode) {
const { id, nickName } = this.data;
console.log('准备开始')
loadingFunc(async () => {
console.log('开始')
const wxLoginCode = await wxLogin()
console.log('wxLoginCode', wxLoginCode)
const result = await userApply({ code: wxLoginCode, phoneCode, id, name: nickName })
const { code, message, data } = result;
if (code !== OK) {
@ -78,7 +67,6 @@ Page({
},
getPhoneNumber(e) {
const { nickName } = this.data;
console.log('nickName', e, nickName)
if (!nickName) {
alertInfo("请填写你的名字")
return;
@ -93,7 +81,6 @@ Page({
alertInfo("服务达到上限")
return;
default:
console.log("进入登录流程")
this.handleLogin(phoneCode)
return;
}

View File

@ -71,6 +71,7 @@ Page({
alertInfo("请输入你的昵称")
return
}
let err = ""
loadingFunc(async () => {
const wxLoginCode = await wxLogin()
const { code, message, data } = await userValidate({ park, tenement, phone, name, code: wxLoginCode })
@ -91,7 +92,6 @@ Page({
url: '/pages/home/index',
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成

View File

@ -1,5 +1,8 @@
import { getOwnTenementList } from "../../service/tenement";
import { getUserInfo } from "../../service/user";
import { alertInfo } from "../../utils/index";
import request from '../../utils/request';
const { OK } = request;
// pages/home/index.js
Page({
@ -8,6 +11,12 @@ Page({
*/
data: {
user: {},
all: [],
park: {},
tenement: {},
show: false,
columns: [],
pickerType: ""
},
/**
@ -16,12 +25,59 @@ Page({
onLoad(options) {
},
choosePark() {
this.setData({
columns: this.data.all,
show: true,
pickerType: "park"
})
},
chooseTenement() {
const { park = {}} = this.data;
const { tenements } = park;
this.setData({
columns: tenements,
show: true,
pickerType: "tenement"
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
onOk(e) {
// console.log('e', e)
const { type, index, value } = e.detail;
const currentPark = this.data.park;
if (type === "park") {
if (value.id === currentPark?.id) {
this.setData({ show: false })
return
}
this.setData({
show: false,
park: value,
tenement: value.tenements?.[0]
})
}
if (type === "tenement") {
const currentTenement = this.data.tenement;
if (value.id === currentTenement?.id) {
this.setData({ show: false })
return
}
this.setData({
show: false,
tenement: value
})
}
},
onCancel() {
this.setData({
show: false,
})
},
changeMoney(e) {
const { money } = e.currentTarget.dataset;
@ -30,7 +86,6 @@ Page({
})
},
onChangeMoney(e) {
console.log('e', e)
this.setData({ money: Number(e.detail) })
},
recharge() {
@ -49,8 +104,58 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
const user = wx.getStorageSync('user')
this.setData({ user })
this.setUser();
this.getAllList();
this.watchTenement();
},
watchTenement() {
let value = this.data.tenement; // 获取被监听属性的当前值
// 使用 Object.defineProperty 方法在数据对象上定义属性的 getter 和 setter
Object.defineProperty(this.data, 'tenement', {
configurable: true, // 可配置
enumerable: true, // 可枚举
get: function () {
return value; // 返回属性的当前值
},
set: function (newVal) {
const oldValue = value;
value = newVal;
}
});
},
async setUser() {
const result = await getUserInfo();
if (result.code !== OK) {
alertInfo(result.message)
return;
}
this.setData({ user: result.data })
wx.setStorageSync('user', result.data)
},
async getAllList() {
const { code, message, data } = await getOwnTenementList()
if (code !== OK) {
alertInfo(message)
return
}
const [firstPark = {}] = data;
const { park, tenement } = this.data;
const updateDatas = {}
if (!park || !park.id) {
updateDatas.park = firstPark
}
if (!tenement || !tenement.id) {
if (!park || !park.id) {
updateDatas.tenement = firstPark.tenements?.[0]
} else {
updateDatas.tenement = park.tenements?.[0];
}
}
updateDatas.all = data;
this.setData({
...updateDatas
})
},
/**

View File

@ -5,7 +5,8 @@
"van-button": "@vant/weapp/button/index",
"van-image": "@vant/weapp/image/index",
"avatar": "/components/avatar/index",
"van-field": "@vant/weapp/field/index"
"van-field": "@vant/weapp/field/index",
"picker": "/components/picker/index"
},
"navigationStyle": "custom"
}

View File

@ -1,11 +1,13 @@
<!--pages/home/index.wxml-->
<view class="top">
<page-meta page-style="{{ show ? 'overflow: hidden;' : '' }}" />
<view>
<view class="top">
<custom-status-bar />
<view class="chooseParkWrapper">
用电管理服务 ·
<view class="parkContent">
<view class="parkContent" bind:tap="choosePark">
<view class="park">
金石工业园
{{park.name}}
</view>
<van-icon name="arrow-down" style="margin-left: 16rpx;" />
</view>
@ -20,9 +22,9 @@
<van-button type="info" size="small" plain="{{true}}" class="loginBtn" bind:tap="jumpToLogin">请登录</van-button>
</view>
<view class="logined" wx:else>
<avatar text="{{ user.tenement.name.slice(0,2) }}" />
<avatar text="{{ user.nickName }}" />
<view>
<van-button type="info" size="small" plain="{{true}}" class="loginBtn" >{{user.tenement.name}} <van-icon name="arrow-down" style="margin-left: 16rpx;" /></van-button>
<van-button type="info" size="small" plain="{{true}}" class="loginBtn" bind:click="chooseTenement">{{user.tenement.name}} <van-icon name="arrow-down" style="margin-left: 16rpx;" /></van-button>
<view class="welcome"> 欢迎使用华昌宝能用电管理系统! </view>
</view>
</view>
@ -80,4 +82,7 @@
<view class="operate">
<van-button color="rgb(88, 165, 141)" block>去缴费</van-button>
</view>
</view>
</view>
<picker show="{{show}}" valueKey="name" columns="{{columns}}" bind:ok="onOk" bind:cancel="onCancel" type="{{pickerType}}" />

View File

@ -142,6 +142,7 @@ export const showLoading = async (options = {}) => {
export const hideLoading = async () => {
return new Promise((resolve, reject) => {
wx.hideLoading({
noConflict: true,
success: () => {
resolve()
}