完成对公初始操作和专区

This commit is contained in:
2024-09-09 15:57:59 +08:00
parent 9a6c4d30f4
commit 927b7a6470
12 changed files with 97 additions and 45 deletions

View File

@@ -1,7 +1,8 @@
// pages/publicTransfer/index.js
import { getMeterDetail, getMeterList, getTenementMeterList } from "../../service/meter";
import { uploadFile } from "../../service/public";
import { alertInfo, loadingFunc, getFileName } from "../../utils/index";
import { createPublicTopUp } from '../../service/recharge'
import { uploadFile, uploadPublicFile } from "../../service/public";
import { alertInfo, loadingFunc, getFileName, alertSuccess } from "../../utils/index";
import request from '../../utils/request';
const { OK } = request;
@@ -19,11 +20,10 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { money, meterId, tenementId, tenementName } = options;
console.log('money', money, 'meterId', meterId)
this.init({ money, meterId, tenementId, tenementName });
const { money, meterId, tenementId, tenementName, park } = options;
this.init({ money, meterId, tenementId, tenementName, park });
},
async init({ money, meterId, tenementId, tenementName }) {
async init({ money, meterId, tenementId, tenementName, park }) {
const { code, message, data } = await getMeterDetail({ tenement: tenementId, id: meterId });
if (code !== OK) {
alertInfo(message);
@@ -34,36 +34,55 @@ Page({
money,
tenementName,
tenementId,
park
})
},
async upload(res) {
const result = await uploadPublicFile(res.tempFiles[0]?.tempFilePath)
if (result.statusCode !== 200) {
alertInfo("上传失败")
return;
}
const data = JSON.parse(result.data)
this.setData({
fileList: [{ url: data.data, name: getFileName(data.data) }]
})
},
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) }]
})
}))()
loadingFunc(async () => {
await this.upload(res)
})
}
});
},
handleSubmit() {
const { fileList } = this.data;
if (!fileList.length) {
async handleSubmit() {
const { fileList, meter, money, park, tenementId } = this.data;
if (!fileList?.length) {
alertInfo("请上传凭证")
return;
}
const { code, message } = await createPublicTopUp({
id: meter.id,
tenement: tenementId,
money: Number(money),
park,
vouch: fileList[0].url
})
if (code !== OK) {
alertInfo(message)
return;
}
alertSuccess("已提交,待审核")
setTimeout(() => {
wx.redirectTo({
url: '/pages/home/index',
})
}, 600)
},
handleDelete() {
this.setData({ fileList: [] })