ts_aimz/pages/copyright/publicPay/publicPay.js
2025-04-09 11:31:24 +08:00

300 lines
9.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/copyright/publicPay/publicPay.js
import PayApi from '../../../net/api/payApi'
import {
request,
uploadImgUrl
} from "../../../net/http";
const dateTimePicker = require('../../../utils/util');
const Cache = require('../../../utils/storage')
Page({
/**
* 页面的初始数据
*/
data: {
incomeEnterprise: {},
showError: false,
errorHint: '',
dateTimeArray: null,
dateTime: null,
selectTime: '',
startYear: 2010,
endYear: 2050,
files: [],
companyName: '', //公司名称
companyBank: '', //开户行
companyBankNum: '', //账户号码
packageId: null, //套餐ID
payMoney: 0, //金额
packageName: '', //套餐名称
accountRechargeId: '', //订单ID
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//判断是选择的套餐包或直接输入的金额
console.log(options.packageId)
console.log(options.money)
wx.setNavigationBarTitle({
title: '对公转账',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
// 获取完整的年月日时分秒,以及默认显示的数组
const obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
console.log(obj.dateTime)
this.setData({
packageId: options.packageId, //套餐包
packageName: options.name,
payMoney: options.money, //金额
dateTimeArray: obj.dateTimeArray,
dateTime: obj.dateTime,
selectFile: this.selectFile.bind(this),
uploadFile: this.uploadFile.bind(this),
});
this.buildCurrentTime()
this.getEnterpriseAccountInfo()
//获取订单
this.doGetOrder()
},
//公司名称
inputCompanyName(e) {
this.setData({
companyName: e.detail.value
})
},
//公司名称
inputCompanyBank(e) {
this.setData({
companyBank: e.detail.value
})
},
//账号
inputCompanyNum(e) {
this.setData({
companyBankNum: e.detail.value
})
},
changeDateTime(e) {
// 处理日期时间选择变化的逻辑
console.log('选择的日期时间发生变化:', e.detail.value);
this.setData({
dateTime: e.detail.value
});
this.buildCurrentTime()
},
//构建选中的时间
buildCurrentTime() {
const _self = this
const array = _self.data.dateTimeArray
const times = _self.data.dateTime
const time = `${array[0][times[0]]}-${array[1][times[1]]}-${array[2][times[2]]} ${array[3][times[3]]}:${array[4][times[4]]}:${array[5][times[5]]}`
console.log(time)
_self.setData({
selectTime: time
})
},
changeDateTimeColumn(e) {
// 处理日期时间选择器列变化的逻辑
console.log('选择器的列发生变化:', e.detail.column, e.detail.value);
},
//获取订单编号
doGetOrder() {
wx.showLoading({
title: '加载中...',
})
const _self = this
const data = {
packageInfoId: _self.data.packageId ? _self.data.packageId : '',
rechargeMoney: _self.data.payMoney,
thirdParty: "对公转账"
}
PayApi.doGetOrder(data)
.then(res => {
wx.hideLoading()
if (res.accountRechargeId && res.accountRechargeId != '') {
_self.setData({
accountRechargeId: res.accountRechargeId
})
} else {
_self.setData({
showError: true,
errorHint: '获取订单失败,请重试'
})
setTimeout(() => {
wx.navigateBack()
}, 1000);
}
console.log(res)
}, err => {
wx.hideLoading()
console.log(err)
_self.setData({
showError: true,
errorHint: '获取订单失败,请重试'
})
setTimeout(() => {
wx.navigateBack()
}, 1000);
})
},
//获取收款方信息
getEnterpriseAccountInfo() {
const _self = this
wx.showLoading({
title: '加载中...',
})
PayApi.doGetEnterpriseAccountInfo()
.then(res => {
wx.hideLoading()
console.log(res)
_self.setData({
incomeEnterprise: res
})
}, err => {
wx.hideLoading()
_self.setData({
showError: true,
errorHint: err.msg ? err.msg : '网络错误,请重试'
})
console.log(err)
})
},
previewImage(e) {
wx.previewImage({
current: e.currentTarget.id, // 当前显示图片的http链接
urls: this.data.files // 需要预览的图片http链接列表
})
},
selectFile(files) {
console.log('files', files)
// 返回false可以阻止某次文件上传
},
uploadFile(files) {
const tempFilePaths = files.tempFilePaths;
const token = Cache.get('token')
const header = {}
if (token) {
header.Auth = `Bearer ${token}`;
}
var that = this
for (let i = 0; i < tempFilePaths.length; i++) {
wx.uploadFile({
url: uploadImgUrl,
header: header,
filePath: tempFilePaths[i],
name: 'image',
success(res) {
console.log(res)
let result = JSON.parse(res.data)
that.data.files.push(result.data)
// do something例如把上传成功后的图片地址保存起来
},
fail(err) {
console.log(err);
// do something when upload failed
}
})
}
// 文件上传的函数返回一个promise
return new Promise((resolve, reject) => {
var result = {};
result['urls'] = tempFilePaths;
resolve(result);
})
},
deleteImage: function (e) {
var index = e.detail.index;
this.data.files.splice(index, 1);
},
uploadError(e) {
console.log('upload error', e.detail)
},
uploadSuccess(e) {
console.log('upload success', e.detail)
},
//完成充值
checkParams() {
const _self = this
if (_self.data.companyName == '') {
_self.setData({
errorHint: '请输入公司名称',
showError: true
})
return false
}
if (_self.data.companyBank == '') {
_self.setData({
errorHint: '请输入开户银行',
showError: true
})
return false
}
if (_self.data.companyBankNum == '') {
_self.setData({
errorHint: '请输入银行账号',
showError: true
})
return false
}
if (_self.data.files.length <= 0) {
_self.setData({
errorHint: '请上传打款凭证',
showError: true
})
return false
}
return true
},
//提交
completePay() {
const _self = this
var isLegal = _self.checkParams()
if (!isLegal) {
return
}
wx.showLoading({
title: '提交中...',
})
const fileIdStr = _self.data.files.map(file => file.fileId).join(',');
const data = {
orgBank: _self.data.companyBank,
orgName: _self.data.companyName,
orgNumber: _self.data.companyBankNum,
packageInfoId: _self.data.packageId ? _self.data.packageId : '',
rechargeFinalTime: _self.data.selectTime,
rechargeMoney: _self.data.payMoney,
rechargeRemark: "",
rechargeVoucher: fileIdStr,
thirdParty: "对公转账"
}
PayApi.doCompleteEnterprisePay(_self.data.accountRechargeId, data)
.then(res => {
wx.hideLoading()
console.log(res)
wx.redirectTo({
url: '/pages/copyright/common/payState?type=1',
})
}, err => {
wx.hideLoading()
console.log(err)
_self.setData({
errorHint: err.msg ? err.msg : '网络错误,请稍后重试',
showError: true
})
})
}
})