123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- // pages/pay/pay.js
- import md5 from '../../utils/md5.js';//支付页面引入md5.js
- const app = getApp()
- const host = app.globalData.host;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- accountArray: ["不需要","个人发票", "公司发票"],
- accountTypeArray: ["纸质发票"],
- account:0,
- account_type:0,
- data:{}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- wx.request({
- url: host + '/api/wx/signup',
- method: 'GET',
- data: { id: options.id },
- success:res=>{
- this.setData({
- data:res.data.data
- })
- }
- })
- },
- pickerChange:function(e){
- if (e.target.dataset.name == 'account') {
- this.setData({
- account: e.detail.value
- })
- };
- if (e.target.dataset.name == 'account_type') {
- this.setData({
- account_type: e.detail.value
- })
- };
- },
- pay:function(e){
-
- // console.log(e.detail.value)
- var data = this.data.data, form = e.detail.value;
- if (this.data.account == 2){
- if (!form.bill_name){
- wx.showToast({
- title: '请输入公司全称',
- icon: 'none',
- duration: 2000
- })
- return false
- }
- if (!form.bill_no) {
- wx.showToast({
- title: '请输入税号',
- icon: 'none',
- duration: 2000
- })
- return false
- }
- }
- wx.showLoading({
- title: '正在提交...',
- })
- wx.request({
- url: host+'/api/wx/signup/pay',
- method:'POST',
- header: {
- openid: app.globalData.openid
- },
- data:{
- total_fee: data.price,
- signup_id:data.id,
- bill_type: Number(this.data.account)+1,
- bill_no: form.bill_no,
- bill_mat:1,
- bill_name: form.bill_name
- },
- success:res=>{
- console.log(res.data.data)
- wx.hideLoading()
- var timestamp = Math.round(new Date().getTime() / 1000).toString();
- var paySign = md5('appId=' + res.data.data.appid + '&nonceStr=' + res.data.data.nonce_str + '&package=prepay_id=' + res.data.data.prepay_id + '&signType=MD5&timeStamp=' + timestamp + '&key=' + res.data.data.key).toUpperCase();
- console.log(paySign)
- wx.requestPayment({
- timeStamp: timestamp,
- nonceStr: res.data.data.nonce_str,
- package: 'prepay_id=' + res.data.data.prepay_id,
- signType: 'MD5',
- paySign: paySign,
- success(res) {
- wx.switchTab({
- url: '/pages/apply/apply'
- });
- },
- fail(res) { console.log(res)}
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|