pianoDetail.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // pages/pianoDetail/pianoDetail.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. num: 1,
  11. initMoney: 19.90,
  12. id: "",
  13. payFlag: 1,
  14. schoolList: [],
  15. moreFlag: 0,
  16. isBuy: true,
  17. downLoadShow: false
  18. },
  19. getMoreSchool: function () {
  20. if (this.data.moreFlag == 0) {
  21. this.setData({
  22. moreFlag: 1
  23. })
  24. } else {
  25. this.setData({
  26. moreFlag: 0
  27. })
  28. }
  29. },
  30. remNum: function () {
  31. var num = this.data.num
  32. if (num <= 1) {
  33. return false
  34. } else {
  35. num--
  36. var money = this.data.initMoney
  37. money = parseFloat(money) * parseFloat(num).toFixed(2)
  38. this.setData({
  39. num: num,
  40. 'item.money': money.toFixed(2)
  41. })
  42. }
  43. },
  44. addNum: function () {
  45. var num = this.data.num
  46. if (num >= 10) {
  47. wx.showToast({
  48. title: '已达单次购买上限',
  49. icon: "none"
  50. })
  51. return
  52. }
  53. num++;
  54. var money = this.data.initMoney
  55. money = parseFloat(money) * parseFloat(num).toFixed(2)
  56. this.setData({
  57. num: num,
  58. 'item.money': money.toFixed(2)
  59. })
  60. },
  61. callPhone(e) {
  62. const index = e.currentTarget.dataset.index
  63. const phone = this.data.schoolList[index].CONTRACT_TELEPHONE
  64. if (phone) {
  65. wx.makePhoneCall({
  66. phoneNumber: phone
  67. })
  68. } else {
  69. wx.showToast({
  70. title: '暂无联系电话',
  71. icon: "none"
  72. })
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面加载
  77. */
  78. onLoad: function (options) {
  79. let urls = urlDef.urls
  80. let item = JSON.parse(options.data)
  81. if (item.imgUrl == null || item.imgUrl == undefined) {
  82. item.imgUrl = urls.oss_file + 'image/0e02f9fc-1d41-4551-a150-b1be8196b49d.jpg'
  83. }
  84. this.setData({ item: item, initMoney: item.money })
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. },
  121. tabBuy: function () {
  122. let stu = wx.getStorageSync('student');
  123. util.doPost(
  124. 'buyPianoCard',{
  125. id: this.data.item.id,
  126. studentId: stu.studentId
  127. }).then(res =>{
  128. if(res.success == 1){
  129. this.payFunction(res.data)
  130. wx.showLoading({
  131. title: '正在唤醒支付',
  132. })
  133. }
  134. })
  135. },
  136. payFunction: function (_this) {
  137. util.doPost(
  138. 'payment', {
  139. payDesc: _this.cardName,
  140. bussType: '15',
  141. sourceId: _this.id,
  142. amount: _this.payMoney,
  143. openId: wx.getStorageSync('openId'),
  144. appId: app.globalData.appId
  145. }).then(res => {
  146. wx.hideLoading({
  147. success: (res) => {},
  148. })
  149. if (res.success > 0) {
  150. // 唤醒支付
  151. var payData = res.data;
  152. var that = this
  153. wx.requestPayment({
  154. timeStamp: payData.timeStamp,
  155. nonceStr: payData.nonceStr,
  156. package: payData.package,
  157. signType: payData.signType,
  158. paySign: payData.paySign,
  159. success: function (res) {
  160. // wx.redirectTo({
  161. // url: '/pages/payDone/payDone?money=' + that.data.orderInfo.paidAmount + "&type=App",
  162. // })
  163. console.log('payment success ... ' + JSON.stringify(res));
  164. },
  165. fail: function (res) {
  166. console.log('payment fail ... ' + JSON.stringify(res));
  167. },
  168. complete: function (res) {
  169. that.setData({
  170. flag: true
  171. })
  172. console.log('payment complete ... ' + JSON.stringify(res));
  173. }
  174. })
  175. } else {
  176. const tip = res.errMsg
  177. wx.showToast({
  178. title: tip,
  179. icon: 'none'
  180. })
  181. }
  182. })
  183. },
  184. })