diff --git a/components/searchSelect/index.js b/components/searchSelect/index.js index 96d49a4..117d476 100644 --- a/components/searchSelect/index.js +++ b/components/searchSelect/index.js @@ -1,3 +1,11 @@ +import { getParkList } from "../../service/park" +import { getParkMeterList } from "../../service/meter" +import { alertInfo } from "../../utils/index"; +import request from "../../utils/request" +import { payWays } from "../../utils/data"; + +const { OK } = request; + // components/searchSelect/index.js Component({ @@ -5,20 +13,108 @@ Component({ * 组件的属性列表 */ properties: { - + title: String, + type: String, + show: Boolean, + park: String, + }, + observers: { + "show,type": function(newShow, newType) { + if (newShow && newType) { + this.onSearch() + } + } }, - /** * 组件的初始数据 */ data: { - columns: ['杭州', '宁波', '温州', '嘉兴', '湖州'], + columns: [], + searchText: "", + payWays, + }, + lifetimes: { + attached() { + + } }, /** * 组件的方法列表 */ methods: { - + onChangeSearch(e) { + this.setData({ + searchText: e.detail, + }) + }, + onCancel() { + this.setData({ + columns: [], + list: [], + searchText: "" + }) + this.triggerEvent("cancel") + }, + onConfirm(event) { + const { index } = event.detail; + const { list = [], type } = this.data; + const item = list[index]; + this.setData({ + columns: [], + list: [], + searchText: "" + }) + this.triggerEvent("confirm", { data: item, type } ); + }, + onPayConfirm(event) { + const { index } = event.detail; + const { payWays = [], type } = this.data; + const item = payWays[index]; + this.setData({ + columns: [], + list: [], + searchText: "" + }) + this.triggerEvent("confirm", { data: item, way: index, type } ); + }, + onSearch() { + const { type } = this.data; + console.log('type', type) + switch(type) { + case "park": + this.onSearchPark(); + return; + case "meter": + console.log("meter") + this.onSearchMeter(); + return; + } + }, + async onSearchPark() { + const { searchText = "" } = this.data; + const { code, message, data: parks = [] } = await getParkList({keyword: searchText}); + if (code !== OK) { + alertInfo(message) + return + } + this.setData({ + columns: parks?.map(item => item?.name), + list: parks, + }) + }, + async onSearchMeter() { + const { searchText = "", park } = this.data; + console.log('this.data', this.data) + const { code, message, data: parks = [] } = await getParkMeterList({keyword: searchText, park}); + if (code !== OK) { + alertInfo(message) + return + } + this.setData({ + columns: parks?.map(item => `${item.meterNo}-${item.address}${item.tenement?.name ? '-' + item.tenement?.name : ''}`), + list: parks, + }) + } } }) \ No newline at end of file diff --git a/components/searchSelect/index.json b/components/searchSelect/index.json index b3af1ff..f362af4 100644 --- a/components/searchSelect/index.json +++ b/components/searchSelect/index.json @@ -1,8 +1,8 @@ { "component": true, "usingComponents": { - "van-overlay": "@vant/weapp/overlay/index", - "van-picker": "@vant/weapp/picker/index" - + "van-popup": "@vant/weapp/popup/index", + "van-picker": "@vant/weapp/picker/index", + "van-search": "@vant/weapp/search/index" } } \ No newline at end of file diff --git a/components/searchSelect/index.wxml b/components/searchSelect/index.wxml index 5c3ade1..fe751bf 100644 --- a/components/searchSelect/index.wxml +++ b/components/searchSelect/index.wxml @@ -1,14 +1,39 @@ - - 111 + + + + \ No newline at end of file diff --git a/pages/workBench/components/recharge/index.js b/pages/workBench/components/recharge/index.js index 932a858..559769d 100644 --- a/pages/workBench/components/recharge/index.js +++ b/pages/workBench/components/recharge/index.js @@ -1,3 +1,9 @@ + +import { handleRecharge } from "../../../../service/recharge"; +import { alertInfo, alertSuccess } from "../../../../utils/index"; +import request from '../../../../utils/request' +const { OK } = request; + // pages/workBench/components/recharge/index.js Component({ @@ -12,13 +18,114 @@ Component({ * 组件的初始数据 */ data: { - + show: false, }, /** * 组件的方法列表 */ methods: { - + onParkFocus(e) { + this.setData({ + show: true, + title: "园区", + type: 'park' + }) + }, + onMeterFocus(e) { + const { park } = this.data; + if (!park) { + alertInfo("请先选择园区") + return; + } + this.setData({ + show: true, + title: "电表", + type: 'meter' + }) + }, + onConfirm(e) { + // console.log('e', e) + const { data, type, way } = e.detail; + console.log('e.detail', e.detail) + switch(type) { + case "park": + this.setData({ + parkName: data.name, + park: data.id, + }) + break; + case "meter": + this.setData({ + meterName: `${data.meterNo}-${data.address}${data.tenement?.name ? '-' + data.tenement?.name : ''}`, + meter: data.id, + }) + break; + case "pay": + this.setData({ + payName: data, + way: way, + }); + break; + } + this.onConcal(); + }, + onConcal() { + this.setData({ + show: false, + title: "", + type: "", + }) + }, + onPayFocus() { + this.setData({ + show: true, + title: "付款方式", + type: 'pay' + }) + }, + onChangeMoney(e) { + console.log('e', e) + this.setData({ money: e.detail }) + }, + onChangeVoucherNo(e) { + console.log('e', e) + this.setData({ voucherNo: e.detail }) + }, + async handleSubmit() { + const { park, meter, money, way, voucherNo } = this.data; + if (!park) { + alertInfo("请选择园区"); + return; + } + if (!meter) { + alertInfo("请选择电表") + return; + } + if (!money) { + alertInfo("请输入金额") + return + } + if (!way && way !== 0) { + alertInfo("请选择付款方式") + return + } + if (!voucherNo) { + alertInfo("请输入凭证号") + return + } + const { code, message } = await handleRecharge(park, { + amount: `${money || ''}`, + meter, + paymentType: way, + voucherNo, + type: "0" + }) + if (code !== OK) { + alertInfo(message) + return + } + alertSuccess("充值成功") + } } }) \ No newline at end of file diff --git a/pages/workBench/components/recharge/index.json b/pages/workBench/components/recharge/index.json index b94c3e8..779a6e1 100644 --- a/pages/workBench/components/recharge/index.json +++ b/pages/workBench/components/recharge/index.json @@ -1,6 +1,9 @@ { "component": true, "usingComponents": { - "van-popup": "@vant/weapp/popup/index" + "van-popup": "@vant/weapp/popup/index", + "search-select": "/components/searchSelect/index", + "van-field": "@vant/weapp/field/index", + "van-button": "@vant/weapp/button/index" } } \ No newline at end of file diff --git a/pages/workBench/components/recharge/index.wxml b/pages/workBench/components/recharge/index.wxml index f2a7fef..fbf989e 100644 --- a/pages/workBench/components/recharge/index.wxml +++ b/pages/workBench/components/recharge/index.wxml @@ -1,3 +1,80 @@ -充值 - \ No newline at end of file + + + + 选择 + + + + + 选择 + + + + + + + 选择 + + + + + + + 确认 + 取消 + + diff --git a/service/meter.js b/service/meter.js index 534932d..2f37d61 100644 --- a/service/meter.js +++ b/service/meter.js @@ -14,4 +14,9 @@ export const getMeterDetail = async function({ tenement, id }) { // 获取某一商户的电表列表 export const getTenementMeterList = async function(tid) { return await GET(`/wx/getMeterList/${tid}`); +} + +// 获取某一园区下的电表列表 +export const getParkMeterList = async function({park = "", keyword = ""}) { + return await GET(`/equipment/getOperateMeterList?page=1&park=${park}&keyword=${keyword}`); } \ No newline at end of file diff --git a/service/park.js b/service/park.js index a21b36e..6b8e536 100644 --- a/service/park.js +++ b/service/park.js @@ -2,8 +2,8 @@ import apis from '../utils/request'; const { GET, POST, PUT, DELETE } = apis // 获取园区列表 -export const getParkList = async function({ keyword }) { - return await GET(`/wx/getParkList?keyword=${keyword}`); +export const getParkList = async function({ keyword = "" }) { + return await GET(`/wx/getParkList?keyword=${keyword || ""}`); } // 获取未登录的园区列表 diff --git a/service/recharge.js b/service/recharge.js index 5efeb62..2fd8cbd 100644 --- a/service/recharge.js +++ b/service/recharge.js @@ -25,4 +25,9 @@ export const returnFee = async function(data) { // 创建对公 export const createPublicTopUp = async function(data) { return await POST(`/wx/createPublicTopUp`, data); +} + +// 后台充值 +export const handleRecharge = async function(park, data) { + return await POST(`/wechatTopup/${park}`, data) } \ No newline at end of file diff --git a/utils/data.js b/utils/data.js index a31220a..b4c55db 100644 --- a/utils/data.js +++ b/utils/data.js @@ -3,7 +3,8 @@ export const getRechargeOperateType = (num) => { return types[num]; } +export const payWays = ["现金", "银行卡", "支付宝", "微信", "云闪付","对公转账", "小程序-微信支付"] + export const getRechargeOperateWay = (num) => { - const types = ["现金", "银行卡", "支付宝", "微信", "云闪付","对公转账", "小程序-微信支付"] - return types[num]; -} \ No newline at end of file + return payWays[num]; +}