pianoDetail.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. params:{}
  19. },
  20. getMoreSchool: function () {
  21. if (this.data.moreFlag == 0) {
  22. this.setData({
  23. moreFlag: 1
  24. })
  25. } else {
  26. this.setData({
  27. moreFlag: 0
  28. })
  29. }
  30. },
  31. remNum: function () {
  32. var num = this.data.num
  33. if (num <= 1) {
  34. return false
  35. } else {
  36. num--
  37. var money = this.data.initMoney
  38. money = parseFloat(money) * parseFloat(num).toFixed(2)
  39. this.setData({
  40. num: num,
  41. 'item.money': money.toFixed(2)
  42. })
  43. }
  44. },
  45. addNum: function () {
  46. var num = this.data.num
  47. if (num >= 10) {
  48. wx.showToast({
  49. title: '已达单次购买上限',
  50. icon: "none"
  51. })
  52. return
  53. }
  54. num++;
  55. var money = this.data.initMoney
  56. money = parseFloat(money) * parseFloat(num).toFixed(2)
  57. this.setData({
  58. num: num,
  59. 'item.money': money.toFixed(2)
  60. })
  61. },
  62. callPhone(e) {
  63. const index = e.currentTarget.dataset.index
  64. const phone = this.data.schoolList[index].CONTRACT_TELEPHONE
  65. if (phone) {
  66. wx.makePhoneCall({
  67. phoneNumber: phone
  68. })
  69. } else {
  70. wx.showToast({
  71. title: '暂无联系电话',
  72. icon: "none"
  73. })
  74. }
  75. },
  76. queryList: function (id) {
  77. const urls = urlDef.urls;
  78. let params = {id:id}
  79. util.apiPost(urls.get_piano_card_list, params).then(rs => {
  80. if( rs[0].schemeType == 1){
  81. this.setData({
  82. isBuy: false
  83. })
  84. }
  85. this.setData({ item: rs[0], initMoney: rs[0].money })
  86. })
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad: function (options) {
  92. if(options.studentId){
  93. const params = {
  94. studentId: options.id,
  95. id: options.id
  96. }
  97. this.setData({
  98. params
  99. })
  100. this.queryList(options.id)
  101. } else if(options.proId){
  102. this.queryList(options.proId)
  103. } else {
  104. let urls = urlDef.urls
  105. let item = JSON.parse(options.data)
  106. if(item.schemeType == 1){
  107. this.setData({
  108. isBuy: false
  109. })
  110. }
  111. if (item.imgUrl == null || item.imgUrl == undefined) {
  112. item.imgUrl = urls.oss_file + 'image/0e02f9fc-1d41-4551-a150-b1be8196b49d.jpg'
  113. }
  114. this.setData({ item: item, initMoney: item.money })
  115. }
  116. },
  117. showDownLoad:function(){
  118. // this.setData({
  119. // downLoadShow: true
  120. // })
  121. wx.navigateToMiniProgram({
  122. appId: 'wx4efd688fa52ba3f7',
  123. path: 'pages/welcome/welcome?isPage=buyCard&isId='+this.data.item.id,
  124. // extraData: {
  125. // foo: 'bar'
  126. // },
  127. envVersion: 'release',
  128. success(res) {
  129. // 打开成功
  130. wx.redirectTo({
  131. url: '/pages/index/index',
  132. })
  133. }
  134. })
  135. },
  136. /**
  137. * 生命周期函数--监听页面初次渲染完成
  138. */
  139. onReady: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面显示
  143. */
  144. onShow: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面隐藏
  148. */
  149. onHide: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面卸载
  153. */
  154. onUnload: function () {
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh: function () {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage: function () {
  170. },
  171. tabBuy: function () {
  172. // let stu = wx.getStorageSync('student');
  173. let stu = null
  174. let id = null
  175. if(this.data.params.studentId){
  176. stu = this.data.params
  177. id = this.data.params.id
  178. } else {
  179. stu = wx.getStorageSync('student');
  180. id = this.data.item.id;
  181. }
  182. util.doPost(
  183. 'buyPianoCard',{
  184. id: id,
  185. studentId: stu.studentId
  186. }).then(res =>{
  187. if(res.success == 1){
  188. this.payFunction(res.data)
  189. wx.showLoading({
  190. title: '正在唤醒支付',
  191. })
  192. }
  193. })
  194. },
  195. payFunction: function (_this) {
  196. util.doPost(
  197. 'payment', {
  198. payDesc: _this.cardName,
  199. bussType: '15',
  200. sourceId: _this.id,
  201. amount: _this.payMoney,
  202. openId: wx.getStorageSync('openId'),
  203. appId: app.globalData.appId
  204. }).then(res => {
  205. wx.hideLoading({
  206. success: (res) => {},
  207. })
  208. if (res.success > 0) {
  209. // 唤醒支付
  210. var payData = res.data;
  211. var that = this
  212. wx.requestPayment({
  213. timeStamp: payData.timeStamp,
  214. nonceStr: payData.nonceStr,
  215. package: payData.package,
  216. signType: payData.signType,
  217. paySign: payData.paySign,
  218. success: function (res) {
  219. wx.redirectTo({
  220. url: '/pages/payDone/payDone?money=' + that.data.initMoney,
  221. })
  222. console.log('payment success ... ' + JSON.stringify(res));
  223. },
  224. fail: function (res) {
  225. console.log('payment fail ... ' + JSON.stringify(res));
  226. },
  227. complete: function (res) {
  228. that.setData({
  229. flag: true
  230. })
  231. console.log('payment complete ... ' + JSON.stringify(res));
  232. }
  233. })
  234. } else {
  235. const tip = res.errMsg
  236. wx.showToast({
  237. title: tip,
  238. icon: 'none'
  239. })
  240. }
  241. })
  242. },
  243. })