pianoDetail.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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: 'develop',
  128. success(res) {
  129. // 打开成功
  130. }
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面隐藏
  145. */
  146. onHide: function () {
  147. },
  148. /**
  149. * 生命周期函数--监听页面卸载
  150. */
  151. onUnload: function () {
  152. },
  153. /**
  154. * 页面相关事件处理函数--监听用户下拉动作
  155. */
  156. onPullDownRefresh: function () {
  157. },
  158. /**
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom: function () {
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage: function () {
  167. },
  168. tabBuy: function () {
  169. // let stu = wx.getStorageSync('student');
  170. let stu = null
  171. let id = null
  172. if(this.data.params.studentId){
  173. stu = this.data.params
  174. id = this.data.params.id
  175. } else {
  176. stu = wx.getStorageSync('student');
  177. id = this.data.item.id;
  178. }
  179. util.doPost(
  180. 'buyPianoCard',{
  181. id: id,
  182. studentId: stu.studentId
  183. }).then(res =>{
  184. if(res.success == 1){
  185. this.payFunction(res.data)
  186. wx.showLoading({
  187. title: '正在唤醒支付',
  188. })
  189. }
  190. })
  191. },
  192. payFunction: function (_this) {
  193. util.doPost(
  194. 'payment', {
  195. payDesc: _this.cardName,
  196. bussType: '15',
  197. sourceId: _this.id,
  198. amount: _this.payMoney,
  199. openId: wx.getStorageSync('openId'),
  200. appId: app.globalData.appId
  201. }).then(res => {
  202. wx.hideLoading({
  203. success: (res) => {},
  204. })
  205. if (res.success > 0) {
  206. // 唤醒支付
  207. var payData = res.data;
  208. var that = this
  209. wx.requestPayment({
  210. timeStamp: payData.timeStamp,
  211. nonceStr: payData.nonceStr,
  212. package: payData.package,
  213. signType: payData.signType,
  214. paySign: payData.paySign,
  215. success: function (res) {
  216. wx.redirectTo({
  217. url: '/pages/payDone/payDone?money=' + that.data.initMoney,
  218. })
  219. console.log('payment success ... ' + JSON.stringify(res));
  220. },
  221. fail: function (res) {
  222. console.log('payment fail ... ' + JSON.stringify(res));
  223. },
  224. complete: function (res) {
  225. that.setData({
  226. flag: true
  227. })
  228. console.log('payment complete ... ' + JSON.stringify(res));
  229. }
  230. })
  231. } else {
  232. const tip = res.errMsg
  233. wx.showToast({
  234. title: tip,
  235. icon: 'none'
  236. })
  237. }
  238. })
  239. },
  240. })