This commit is contained in:
qiaomu 2024-08-30 17:31:35 +08:00
parent 2262031abd
commit 2c952e71a3
15 changed files with 250 additions and 279 deletions

View File

@ -14,11 +14,11 @@
"pages/waitApprove/index",
"pages/apply/index",
"pages/qrCode/index",
"pages/recharge/index",
"pages/questions/index",
"pages/rechargeDetail/index",
"pages/updateInvoice/index",
"pages/rechargeWay/index"
"pages/rechargeWay/index",
"pages/publicTransfer/index"
],
"subPackages": [
{

View File

@ -25,7 +25,7 @@ Page({
rechargeVisible: false,
actions: [
{ name: '微信支付', },
{ name: '对公支付', disabled: true },
{ name: '对公支付' },
],
},
@ -326,7 +326,10 @@ Page({
onSelectRechargeWay(e) {
switch(e.detail.name) {
case "对公支付":
alertInfo("开发中")
const { user, money, meter, tenement, park } = this.data;
wx.navigateTo({
url: `/pages/publicTransfer/index?money=${money}&meterId=${meter.id}&tenementId=${tenement.id}&tenementName=${tenement.name}`,
})
break;
default:
this.wxRecharge();

View File

@ -0,0 +1,119 @@
// pages/publicTransfer/index.js
import { getMeterDetail, getMeterList, getTenementMeterList } from "../../service/meter";
import { uploadFile } from "../../service/public";
import { alertInfo, loadingFunc, getFileName } from "../../utils/index";
import request from '../../utils/request';
const { OK } = request;
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { money, meterId, tenementId, tenementName } = options;
console.log('money', money, 'meterId', meterId)
this.init({ money, meterId, tenementId, tenementName });
},
async init({ money, meterId, tenementId, tenementName }) {
const { code, message, data } = await getMeterDetail({ tenement: tenementId, id: meterId });
if (code !== OK) {
alertInfo(message);
return;
}
this.setData({
meter: data,
money,
tenementName,
tenementId,
})
},
onUpload() {
const that = this;
wx.chooseMedia({
count: 1, // 可以选择文件的数量
mediaType: ['image'], // 可以选择文件的类型,这里只允许上传文件
sourceType: ['album', 'camera'],
success: (res) => {
(loadingFunc(async () => {
const result = await uploadFile(res.tempFiles[0]?.tempFilePath)
console.log('result', result)
if (result.statusCode !== 200) {
alertInfo("上传失败")
return;
}
const data = JSON.parse(result.data)
this.setData({
fileList: [{ url: data.data, name: getFileName(data.data) }]
})
}))()
}
});
},
handleSubmit() {
const { fileList } = this.data;
if (!fileList.length) {
alertInfo("请上传凭证")
return;
}
},
handleDelete() {
this.setData({ fileList: [] })
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

View File

@ -0,0 +1,9 @@
{
"usingComponents": {
"navigator": "/components/navigator/index",
"van-field": "@vant/weapp/field/index",
"van-uploader": "@vant/weapp/uploader/index",
"van-button": "@vant/weapp/button/index"
},
"navigationStyle": "custom"
}

View File

@ -0,0 +1,25 @@
<!--pages/publicTransfer/index.wxml-->
<navigator title="对公转账" canBack="{{true}}" />
<van-cell-group>
<van-field label="用户名称" value="{{ tenementName }}" border="{{ false }}" readonly />
<van-field label="电表编号" value="{{ meter.code }}" border="{{ false }}" readonly />
<van-field label="电表地址" value="{{ meter.address }}" border="{{ false }}" readonly />
<van-field label="付款方式" value="{{ '对公支付' }}" border="{{ false }}" readonly />
<van-field label="付款金额" value="{{ money }}" border="{{ false }}" readonly />
<van-field label="充值凭证" border="{{ false }}" use-input-slot type="textarea">
<van-button slot="input" size="small" type="info" bind:tap="onUpload">
点击上传
</van-button>
</van-field>
</van-cell-group>
<view style="padding: 20rpx;">
<van-uploader
file-list="{{ fileList }}"
show-upload="{{false}}"
bind:delete="handleDelete"
preview-size="220rpx"
/>
<van-button bind:tap="handleSubmit" type="info" block style="margin-top: 20rpx;"> 提交 </van-button>
</view>

View File

@ -0,0 +1 @@
/* pages/publicTransfer/index.wxss */

View File

@ -1,113 +0,0 @@
import { getMeterDetail } from "../../service/meter";
import { getGlobalData, showModal } from "../../utils/index";
// pages/recharge/index.js
Page({
/**
* 页面的初始数据
*/
data: {
money: 0,
moneyIndex: -1,
primaryColor: getGlobalData().primaryColor,
defaultMoneyArray: [100, 200, 500, 1000, 2000],
customFlag: false,
detail: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { tenement, code } = options
this.init({ tenement, code })
},
async init(options) {
const { code, message, data = {}} = await getMeterDetail(options)
this.setData({
detail: data
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
chooseMoney(e) {
const { money, index } = e.currentTarget.dataset;
this.setData({
money,
moneyIndex: Number(index),
customFlag: false,
});
},
onChangeCode(e) {
const { codes } = this.data;
const index = Number(e.detail.value);
this.setData({
code: codes[index]
})
},
custom() {
this.setData({
moneyIndex: -1,
customFlag: true,
})
},
onChangeCustomMoney(e) {
const money = e.detail.value;
this.setData({
money: money,
})
},
async recharge() {
const { detail = {}, money } = this.data;
const confirmResult = await showModal({ title: "充值确认", content: `确认充值表号为${detail?.meter?.code}的表计${money}元吗?` });
if (!confirmResult) {
return;
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

View File

@ -1,10 +0,0 @@
{
"usingComponents": {
"navigator": "/components/navigator/index",
"van-grid": "@vant/weapp/grid/index",
"van-grid-item": "@vant/weapp/grid-item/index",
"van-row": "@vant/weapp/row/index",
"van-col": "@vant/weapp/col/index"
},
"navigationBarTitleText": "充值"
}

View File

@ -1,51 +0,0 @@
<!--pages/recharge/index.wxml-->
<view class="wrapper">
<van-row gutter="10">
<van-col span="12">
<view class="title">充值表号:</view>
<view class="content">{{ detail.meter.code }}</view>
</van-col>
<van-col span="12">
<view class="title">表计地址:</view>
<view class="content">{{ detail.meter.address }}</view>
</van-col>
<van-col span="12" custom-class="colBottom">
<view class="title">剩余金额:</view>
<view class="content">{{ detail.money }}</view>
</van-col>
<van-col span="12" custom-class="colBottom">
<view class="title">公司名称:</view>
<view class="content">{{ detail.tenement.name }}</view>
</van-col>
</van-row>
<view class="moneyBoxs">
<view
wx:for="{{defaultMoneyArray}}"
class="moneyBox border radius12"
style="background-color: {{moneyIndex === index ? primaryColor : ''}};"
wx:key="index"
bind:tap="chooseMoney"
data-money="{{item}}"
data-index="{{index}}"
> {{item}} </view>
<view class="moneyBox border radius12" bind:tap="custom"> 自定义 </view>
</view>
<view
class="customInput border radius12"
wx:if="{{customFlag}}"
>
<input
type="number"
focus
placeholder="请输入要充值的金额"
bindinput="onChangeCustomMoney"
/>
</view>
<view class="operate">
<button type="primary" bind:tap="recharge" disabled="{{!money}}"> 充值 </button>
</view>
</view>

View File

@ -1,62 +0,0 @@
/* pages/recharge/index.wxss */
.moneyBoxs {
margin-top: 32rpx;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.moneyBox {
width: 30%;
height: 140rpx;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 24rpx;
}
.chooseMeter {
display: flex;
align-items: center;
margin-top: 10rpx;
}
.selectMeter {
margin-left: 24rpx;
}
.operate {
margin-top: 24rpx;
}
.input {
height: 40rpx;
width: 400rpx;
line-height: 40rpx;
border-radius: 20rpx;
padding: 12rpx 14rpx 16rpx;
/* border: 1rpx solid #ccc; */
}
.customInput {
padding: 16rpx 24rpx;
}
.gridTitle {
margin-bottom: 24rpx;
}
.colBottom {
margin-top: 40rpx;
}
.title {
font-weight: 600;
font-size: 40rpx;
margin-bottom: 20rpx;
}
.content {
font-size: 32rpx;
}

View File

@ -33,42 +33,57 @@ Page({
})
},
record() {
const { detail } = this.data;
wx.showModal({
title: '提示',
content: '为了您更好的体验,请复制链接,通过电脑浏览器打开下载',
showCancel: true,
cancelText: '关闭',
confirmText: '复制链接',
complete: (res) => {
if (res.confirm) {
const result = wx.getAccountInfoSync();
const { envVersion } = result.miniProgram;
let api = ""
switch (envVersion) {
// 开发版
case 'develop':
wx.setClipboardData({
data: `http://1.92.72.5:8080/recharge-print/?id=${detail.id}`,
})
break;
// 体验版
case 'trial':
wx.setClipboardData({
data: `http://1.92.72.5:8080/recharge-print/?id=${detail.id}`,
})
break;
// 正式版
case 'release':
wx.setClipboardData({
data: `https://zgd.hbhcbn.com/recharge-print/?id=${detail.id}`,
})
break;
}
const handleDownload = () => {
return new Promise((resolve, rej) => {
const { detail } = this.data;
const result = wx.getAccountInfoSync();
const { envVersion } = result.miniProgram;
let api = ""
switch (envVersion) {
// 开发版
case 'develop':
api = `http://localhost:9001`;
// api = `https://zgd.hbhcbn.com/recharge-print-api-test`;
break;
// 体验版
case 'trial':
api = `https://zgd.hbhcbn.com/recharge-print-api-test`;
break;
// 正式版
case 'release':
api = `https://zgd.hbhcbn.com/recharge-print-api`;
break;
}
}
console.log("api", `${api}/${detail.id}`)
wx.downloadFile({
url: `${api}/${detail.id}`,
success: (res) => {
console.log('res', res)
if (res.statusCode === 200) {
if (!res.tempFilePath) {
alertError("获取文件失败")
rej()
return;
}
wx.openDocument({
filePath: res.tempFilePath,
fileType: [ "pdf"], // 3. 这个必须写合法类型,不然下载不了
success: function (res) {
resolve()
},
fail: function (e) {
alertError("打开失败")
console.log('打开失败错误为', e)
rej()
}
})
}
}
})
})
}
loadingFunc(async () => {
await handleDownload();
})
},
back() {

View File

@ -7,11 +7,13 @@
</view>
<view class="tenementPicker" bind:tap="clickMeter">
<view wx:if="{{meterCode}}" class="tenementName"> {{ meterCode }} </view>
<view wx:else> 全部 </view>
<view wx:else> 全部电表 </view>
<van-icon name="arrow-down" custom-class="down" />
</view>
<view class="allMoney">
合计: {{amount}}元
<view class="tenementPicker" bind:tap="clickType">
<view wx:if="{{typeText}}" class="tenementName"> {{ typeText }} </view>
<view wx:else> 全部类型 </view>
<van-icon name="arrow-down" custom-class="down" />
</view>
</view>
<view class="wrapper" wx:if="{{list.length}}">

23
service/public.js Normal file
View File

@ -0,0 +1,23 @@
import apis from '../utils/request';
import { getConfigByEnv } from "../utils/index"
const { GET, POST, PUT, DELETE } = apis
export const uploadFile = (filePath) => {
const { api } = getConfigByEnv();
return new Promise((resolve, reject) => {
wx.uploadFile({
filePath: filePath,
name: 'file',
url: `${api}/file/upload`,
header: {
authorization: 'Bearer ' + wx.getStorageSync("token")
},
success: (res) => {
resolve(res);
},
fail: (err) => {
reject(err);
}
})
})
}

View File

@ -45,7 +45,8 @@ export function getConfigByEnv() {
switch (envVersion) {
// 开发版
case 'develop':
api = "http://localhost:8000"
// api = "http://localhost:8000"
api = "https://zgd.hbhcbn.com/api3"
// api = "https://zgd.hbhcbn.com/api3"
// api = "https://zgd.hbhcbn.com/wxApi"
// api = "http://127.0.0.1:4523/m1/4143821-0-default"
@ -247,4 +248,9 @@ export function getPageUrl() {
const currentPage = pages[pages.length-1] //获取当前页面的对象
const url = currentPage.route //当前页面url
return url
}
/** 根据文件路径获取文件名 */
export function getFileName(path) {
return path.slice(path.lastIndexOf("/") + 1, -1)
}

View File

@ -85,6 +85,10 @@ const parseResponse = function (response, url) {
// const { statusCode } = response;
const { code } = response?.data || {};
console.log('url', url,'code', code, 'response.data', response.data)
if (!code) {
alertError("服务异常")
return
}
if (code === 401) {
const currentUrl = getPageUrl()