新增首页园区和商户的交互
This commit is contained in:
parent
2b45de5a7f
commit
3284bea475
2
app.json
2
app.json
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
"pages/home/index",
|
"pages/home/index",
|
||||||
"pages/my/index",
|
|
||||||
"pages/handleLogin/index",
|
"pages/handleLogin/index",
|
||||||
|
"pages/my/index",
|
||||||
"pages/member/index",
|
"pages/member/index",
|
||||||
"pages/login/index",
|
"pages/login/index",
|
||||||
"pages/apply/index",
|
"pages/apply/index",
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
<!--components/avatar/index.wxml-->
|
<!--components/avatar/index.wxml-->
|
||||||
<view class="wrapper">{{text}}</view>
|
<view class="wrapper">
|
||||||
|
<view class="text">{{text}}</view>
|
||||||
|
</view>
|
|
@ -9,3 +9,8 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
max-width: 100rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
38
components/picker/index.js
Normal file
38
components/picker/index.js
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
7
components/picker/index.json
Normal file
7
components/picker/index.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"van-popup": "@vant/weapp/popup/index",
|
||||||
|
"van-picker": "@vant/weapp/picker/index"
|
||||||
|
}
|
||||||
|
}
|
11
components/picker/index.wxml
Normal file
11
components/picker/index.wxml
Normal 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>
|
1
components/picker/index.wxss
Normal file
1
components/picker/index.wxss
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/* components/picker/index.wxss */
|
|
@ -19,16 +19,8 @@ Page({
|
||||||
* 生命周期函数--监听页面加载
|
* 生命周期函数--监听页面加载
|
||||||
*/
|
*/
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
console.log('options', options)
|
|
||||||
const querys = decodeURIComponent(options.scene)
|
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 = querys.slice(querys.indexOf("=") + 1)
|
||||||
// const id = seach.get('id')
|
|
||||||
console.log('更换')
|
|
||||||
console.log('id', id)
|
|
||||||
// this.setData({ id, name })
|
|
||||||
this.getInfo(id);
|
this.getInfo(id);
|
||||||
},
|
},
|
||||||
async getInfo(id) {
|
async getInfo(id) {
|
||||||
|
@ -52,11 +44,8 @@ Page({
|
||||||
},
|
},
|
||||||
async handleLogin(phoneCode) {
|
async handleLogin(phoneCode) {
|
||||||
const { id, nickName } = this.data;
|
const { id, nickName } = this.data;
|
||||||
console.log('准备开始')
|
|
||||||
loadingFunc(async () => {
|
loadingFunc(async () => {
|
||||||
console.log('开始')
|
|
||||||
const wxLoginCode = await wxLogin()
|
const wxLoginCode = await wxLogin()
|
||||||
console.log('wxLoginCode', wxLoginCode)
|
|
||||||
const result = await userApply({ code: wxLoginCode, phoneCode, id, name: nickName })
|
const result = await userApply({ code: wxLoginCode, phoneCode, id, name: nickName })
|
||||||
const { code, message, data } = result;
|
const { code, message, data } = result;
|
||||||
if (code !== OK) {
|
if (code !== OK) {
|
||||||
|
@ -78,7 +67,6 @@ Page({
|
||||||
},
|
},
|
||||||
getPhoneNumber(e) {
|
getPhoneNumber(e) {
|
||||||
const { nickName } = this.data;
|
const { nickName } = this.data;
|
||||||
console.log('nickName', e, nickName)
|
|
||||||
if (!nickName) {
|
if (!nickName) {
|
||||||
alertInfo("请填写你的名字")
|
alertInfo("请填写你的名字")
|
||||||
return;
|
return;
|
||||||
|
@ -93,7 +81,6 @@ Page({
|
||||||
alertInfo("服务达到上限")
|
alertInfo("服务达到上限")
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
console.log("进入登录流程")
|
|
||||||
this.handleLogin(phoneCode)
|
this.handleLogin(phoneCode)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ Page({
|
||||||
alertInfo("请输入你的昵称")
|
alertInfo("请输入你的昵称")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let err = ""
|
||||||
loadingFunc(async () => {
|
loadingFunc(async () => {
|
||||||
const wxLoginCode = await wxLogin()
|
const wxLoginCode = await wxLogin()
|
||||||
const { code, message, data } = await userValidate({ park, tenement, phone, name, code: wxLoginCode })
|
const { code, message, data } = await userValidate({ park, tenement, phone, name, code: wxLoginCode })
|
||||||
|
@ -91,7 +92,6 @@ Page({
|
||||||
url: '/pages/home/index',
|
url: '/pages/home/index',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 生命周期函数--监听页面初次渲染完成
|
* 生命周期函数--监听页面初次渲染完成
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
import { getOwnTenementList } from "../../service/tenement";
|
||||||
|
import { getUserInfo } from "../../service/user";
|
||||||
import { alertInfo } from "../../utils/index";
|
import { alertInfo } from "../../utils/index";
|
||||||
|
import request from '../../utils/request';
|
||||||
|
const { OK } = request;
|
||||||
// pages/home/index.js
|
// pages/home/index.js
|
||||||
Page({
|
Page({
|
||||||
|
|
||||||
|
@ -8,6 +11,12 @@ Page({
|
||||||
*/
|
*/
|
||||||
data: {
|
data: {
|
||||||
user: {},
|
user: {},
|
||||||
|
all: [],
|
||||||
|
park: {},
|
||||||
|
tenement: {},
|
||||||
|
show: false,
|
||||||
|
columns: [],
|
||||||
|
pickerType: ""
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,12 +25,59 @@ Page({
|
||||||
onLoad(options) {
|
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() {
|
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) {
|
changeMoney(e) {
|
||||||
const { money } = e.currentTarget.dataset;
|
const { money } = e.currentTarget.dataset;
|
||||||
|
@ -30,7 +86,6 @@ Page({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onChangeMoney(e) {
|
onChangeMoney(e) {
|
||||||
console.log('e', e)
|
|
||||||
this.setData({ money: Number(e.detail) })
|
this.setData({ money: Number(e.detail) })
|
||||||
},
|
},
|
||||||
recharge() {
|
recharge() {
|
||||||
|
@ -49,8 +104,58 @@ Page({
|
||||||
* 生命周期函数--监听页面显示
|
* 生命周期函数--监听页面显示
|
||||||
*/
|
*/
|
||||||
onShow() {
|
onShow() {
|
||||||
const user = wx.getStorageSync('user')
|
this.setUser();
|
||||||
this.setData({ user })
|
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
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
"van-button": "@vant/weapp/button/index",
|
"van-button": "@vant/weapp/button/index",
|
||||||
"van-image": "@vant/weapp/image/index",
|
"van-image": "@vant/weapp/image/index",
|
||||||
"avatar": "/components/avatar/index",
|
"avatar": "/components/avatar/index",
|
||||||
"van-field": "@vant/weapp/field/index"
|
"van-field": "@vant/weapp/field/index",
|
||||||
|
"picker": "/components/picker/index"
|
||||||
},
|
},
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
|
@ -1,11 +1,13 @@
|
||||||
<!--pages/home/index.wxml-->
|
<!--pages/home/index.wxml-->
|
||||||
|
<page-meta page-style="{{ show ? 'overflow: hidden;' : '' }}" />
|
||||||
|
<view>
|
||||||
<view class="top">
|
<view class="top">
|
||||||
<custom-status-bar />
|
<custom-status-bar />
|
||||||
<view class="chooseParkWrapper">
|
<view class="chooseParkWrapper">
|
||||||
用电管理服务 ·
|
用电管理服务 ·
|
||||||
<view class="parkContent">
|
<view class="parkContent" bind:tap="choosePark">
|
||||||
<view class="park">
|
<view class="park">
|
||||||
金石工业园
|
{{park.name}}
|
||||||
</view>
|
</view>
|
||||||
<van-icon name="arrow-down" style="margin-left: 16rpx;" />
|
<van-icon name="arrow-down" style="margin-left: 16rpx;" />
|
||||||
</view>
|
</view>
|
||||||
|
@ -20,9 +22,9 @@
|
||||||
<van-button type="info" size="small" plain="{{true}}" class="loginBtn" bind:tap="jumpToLogin">请登录</van-button>
|
<van-button type="info" size="small" plain="{{true}}" class="loginBtn" bind:tap="jumpToLogin">请登录</van-button>
|
||||||
</view>
|
</view>
|
||||||
<view class="logined" wx:else>
|
<view class="logined" wx:else>
|
||||||
<avatar text="{{ user.tenement.name.slice(0,2) }}" />
|
<avatar text="{{ user.nickName }}" />
|
||||||
<view>
|
<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 class="welcome"> 欢迎使用华昌宝能用电管理系统! </view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -80,4 +82,7 @@
|
||||||
<view class="operate">
|
<view class="operate">
|
||||||
<van-button color="rgb(88, 165, 141)" block>去缴费</van-button>
|
<van-button color="rgb(88, 165, 141)" block>去缴费</van-button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
|
</view>
|
||||||
|
<picker show="{{show}}" valueKey="name" columns="{{columns}}" bind:ok="onOk" bind:cancel="onCancel" type="{{pickerType}}" />
|
||||||
|
|
|
@ -142,6 +142,7 @@ export const showLoading = async (options = {}) => {
|
||||||
export const hideLoading = async () => {
|
export const hideLoading = async () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
wx.hideLoading({
|
wx.hideLoading({
|
||||||
|
noConflict: true,
|
||||||
success: () => {
|
success: () => {
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user