From 2c952e71a38a693b6a1c4aef30e1aef674b2ecea Mon Sep 17 00:00:00 2001 From: qiaomu <3520484422@qq.com> Date: Fri, 30 Aug 2024 17:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 4 +- pages/home/index.js | 7 +- pages/publicTransfer/index.js | 119 ++++++++++++++++++++++++++++++++ pages/publicTransfer/index.json | 9 +++ pages/publicTransfer/index.wxml | 25 +++++++ pages/publicTransfer/index.wxss | 1 + pages/recharge/index.js | 113 ------------------------------ pages/recharge/index.json | 10 --- pages/recharge/index.wxml | 51 -------------- pages/recharge/index.wxss | 62 ----------------- pages/rechargeDetail/index.js | 85 +++++++++++++---------- pages/rechargeRecord/index.wxml | 8 ++- service/public.js | 23 ++++++ utils/index.js | 8 ++- utils/request.js | 4 ++ 15 files changed, 250 insertions(+), 279 deletions(-) create mode 100644 pages/publicTransfer/index.js create mode 100644 pages/publicTransfer/index.json create mode 100644 pages/publicTransfer/index.wxml create mode 100644 pages/publicTransfer/index.wxss delete mode 100644 pages/recharge/index.js delete mode 100644 pages/recharge/index.json delete mode 100644 pages/recharge/index.wxml delete mode 100644 pages/recharge/index.wxss create mode 100644 service/public.js diff --git a/app.json b/app.json index 57ccd30..e20360c 100644 --- a/app.json +++ b/app.json @@ -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": [ { diff --git a/pages/home/index.js b/pages/home/index.js index 2ce113b..25fae78 100644 --- a/pages/home/index.js +++ b/pages/home/index.js @@ -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(); diff --git a/pages/publicTransfer/index.js b/pages/publicTransfer/index.js new file mode 100644 index 0000000..0ff22e1 --- /dev/null +++ b/pages/publicTransfer/index.js @@ -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() { + + } +}) \ No newline at end of file diff --git a/pages/publicTransfer/index.json b/pages/publicTransfer/index.json new file mode 100644 index 0000000..c2a876c --- /dev/null +++ b/pages/publicTransfer/index.json @@ -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" +} \ No newline at end of file diff --git a/pages/publicTransfer/index.wxml b/pages/publicTransfer/index.wxml new file mode 100644 index 0000000..7d31d4f --- /dev/null +++ b/pages/publicTransfer/index.wxml @@ -0,0 +1,25 @@ + + + + + + + + + + + 点击上传 + + + + + + + + 提交 + \ No newline at end of file diff --git a/pages/publicTransfer/index.wxss b/pages/publicTransfer/index.wxss new file mode 100644 index 0000000..9e7911d --- /dev/null +++ b/pages/publicTransfer/index.wxss @@ -0,0 +1 @@ +/* pages/publicTransfer/index.wxss */ \ No newline at end of file diff --git a/pages/recharge/index.js b/pages/recharge/index.js deleted file mode 100644 index 780ab6d..0000000 --- a/pages/recharge/index.js +++ /dev/null @@ -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() { - - } -}) \ No newline at end of file diff --git a/pages/recharge/index.json b/pages/recharge/index.json deleted file mode 100644 index 6618c57..0000000 --- a/pages/recharge/index.json +++ /dev/null @@ -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": "充值" -} \ No newline at end of file diff --git a/pages/recharge/index.wxml b/pages/recharge/index.wxml deleted file mode 100644 index c765007..0000000 --- a/pages/recharge/index.wxml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - 充值表号: - {{ detail.meter.code }} - - - 表计地址: - {{ detail.meter.address }} - - - - 剩余金额: - {{ detail.money }} - - - 公司名称: - {{ detail.tenement.name }} - - - - - {{item}} - 自定义 - - - - - - - - \ No newline at end of file diff --git a/pages/recharge/index.wxss b/pages/recharge/index.wxss deleted file mode 100644 index a62e17e..0000000 --- a/pages/recharge/index.wxss +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/pages/rechargeDetail/index.js b/pages/rechargeDetail/index.js index cd5ec8a..b4be760 100644 --- a/pages/rechargeDetail/index.js +++ b/pages/rechargeDetail/index.js @@ -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() { diff --git a/pages/rechargeRecord/index.wxml b/pages/rechargeRecord/index.wxml index 73ac1df..dac645a 100644 --- a/pages/rechargeRecord/index.wxml +++ b/pages/rechargeRecord/index.wxml @@ -7,11 +7,13 @@ {{ meterCode }} - 全部 + 全部电表 - - 合计: {{amount}}元 + + {{ typeText }} + 全部类型 + diff --git a/service/public.js b/service/public.js new file mode 100644 index 0000000..f2dd5eb --- /dev/null +++ b/service/public.js @@ -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); + } + }) + }) +} \ No newline at end of file diff --git a/utils/index.js b/utils/index.js index 87f675e..2cc3cbe 100644 --- a/utils/index.js +++ b/utils/index.js @@ -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) } \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index 3b624fd..1d6ed2c 100644 --- a/utils/request.js +++ b/utils/request.js @@ -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()