// pages/pianoDetail/pianoDetail.js const app = getApp() const util = require("../../utils/util") const urlDef = require("../../utils/urls") Page({ /** * 页面的初始数据 */ data: { num: 1, initMoney: 19.90, id: "", payFlag: 1, schoolList: [], moreFlag: 0, isBuy: true, downLoadShow: false, params:{} }, getMoreSchool: function () { if (this.data.moreFlag == 0) { this.setData({ moreFlag: 1 }) } else { this.setData({ moreFlag: 0 }) } }, remNum: function () { var num = this.data.num if (num <= 1) { return false } else { num-- var money = this.data.initMoney money = parseFloat(money) * parseFloat(num).toFixed(2) this.setData({ num: num, 'item.money': money.toFixed(2) }) } }, addNum: function () { var num = this.data.num if (num >= 10) { wx.showToast({ title: '已达单次购买上限', icon: "none" }) return } num++; var money = this.data.initMoney money = parseFloat(money) * parseFloat(num).toFixed(2) this.setData({ num: num, 'item.money': money.toFixed(2) }) }, callPhone(e) { const index = e.currentTarget.dataset.index const phone = this.data.schoolList[index].CONTRACT_TELEPHONE if (phone) { wx.makePhoneCall({ phoneNumber: phone }) } else { wx.showToast({ title: '暂无联系电话', icon: "none" }) } }, queryList: function (id) { const urls = urlDef.urls; let params = {id:id} util.apiPost(urls.get_piano_card_list, params).then(rs => { if( rs[0].schemeType == 1){ this.setData({ isBuy: false }) } this.setData({ item: rs[0], initMoney: rs[0].money }) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.studentId){ const params = { studentId: options.id, id: options.id } this.setData({ params }) this.queryList(options.id) } else if(options.proId){ this.queryList(options.proId) } else { let urls = urlDef.urls let item = JSON.parse(options.data) if(item.schemeType == 1){ this.setData({ isBuy: false }) } if (item.imgUrl == null || item.imgUrl == undefined) { item.imgUrl = urls.oss_file + 'image/0e02f9fc-1d41-4551-a150-b1be8196b49d.jpg' } this.setData({ item: item, initMoney: item.money }) } }, showDownLoad:function(){ // this.setData({ // downLoadShow: true // }) wx.navigateToMiniProgram({ appId: 'wx4efd688fa52ba3f7', path: 'pages/welcome/welcome?isPage=buyCard&isId='+this.data.item.id, // extraData: { // foo: 'bar' // }, envVersion: 'develop', success(res) { // 打开成功 } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, tabBuy: function () { // let stu = wx.getStorageSync('student'); let stu = null let id = null if(this.data.params.studentId){ stu = this.data.params id = this.data.params.id } else { stu = wx.getStorageSync('student'); id = this.data.item.id; } util.doPost( 'buyPianoCard',{ id: id, studentId: stu.studentId }).then(res =>{ if(res.success == 1){ this.payFunction(res.data) wx.showLoading({ title: '正在唤醒支付', }) } }) }, payFunction: function (_this) { util.doPost( 'payment', { payDesc: _this.cardName, bussType: '15', sourceId: _this.id, amount: _this.payMoney, openId: wx.getStorageSync('openId'), appId: app.globalData.appId }).then(res => { wx.hideLoading({ success: (res) => {}, }) if (res.success > 0) { // 唤醒支付 var payData = res.data; var that = this wx.requestPayment({ timeStamp: payData.timeStamp, nonceStr: payData.nonceStr, package: payData.package, signType: payData.signType, paySign: payData.paySign, success: function (res) { wx.redirectTo({ url: '/pages/payDone/payDone?money=' + that.data.initMoney, }) console.log('payment success ... ' + JSON.stringify(res)); }, fail: function (res) { console.log('payment fail ... ' + JSON.stringify(res)); }, complete: function (res) { that.setData({ flag: true }) console.log('payment complete ... ' + JSON.stringify(res)); } }) } else { const tip = res.errMsg wx.showToast({ title: tip, icon: 'none' }) } }) }, })