paypage.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // pages/mine/wxml/paypage/paypage.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. textarea : "",
  9. prodUrl:app.globalData.prodUrl,
  10. discount: 0,
  11. setDiscount:0,
  12. totalSum: 0
  13. },
  14. bindTextAreaBlur: function (e) {
  15. this.setData({
  16. textarea: e.detail.value,
  17. })
  18. },
  19. formSubmit: function(e) {
  20. let _this = this;
  21. wx.showModal({
  22. title: '提示',
  23. content: '请核对相关内容,确认支付!',
  24. success: function(res) {
  25. if (res.confirm) {
  26. if (_this.data.msg === '0') {
  27. wx.showModal({
  28. title: '提示',
  29. content: '请先添加收货地址',
  30. success: function(res) {
  31. if (res.confirm) {
  32. //console.log('用户点击确定')
  33. wx.navigateTo({
  34. url: '../receivingaddress/receivingaddress?kid=' + e.target.dataset.kid
  35. })
  36. } else if (res.cancel) {
  37. //console.log('用户点击取消')
  38. }
  39. }
  40. })
  41. } else if (_this.data.msg === '1') {
  42. wx.showModal({
  43. title: '提示',
  44. content: '请先添加默认地址',
  45. success: function (res) {
  46. if (res.confirm) {
  47. //console.log('用户点击确定')
  48. wx.navigateTo({
  49. url: '../receivingaddress/receivingaddress?kid=' + e.target.dataset.kid
  50. })
  51. } else if (res.cancel) {
  52. //console.log('用户点击取消')
  53. }
  54. }
  55. })
  56. } else {
  57. //console.log(_this.data.setDiscount)
  58. wx.request({
  59. url: app.globalData.prodUrl + 'web-pm/wx/pm/payment',
  60. data: {
  61. item_kid: e.detail.target.dataset.kid,
  62. address_id: e.detail.target.dataset.address_id,
  63. message: _this.data.textarea,
  64. red_pack_balance: _this.data.setDiscount
  65. },
  66. header: {
  67. 'ydw-token': wx.getStorageSync('key').ydw_token
  68. },
  69. method: 'GET',
  70. dataType: 'json',
  71. responseType: 'text',
  72. success: function(res) {
  73. _this.setData({
  74. payNo_id: res.data.payNo.kid
  75. })
  76. wx.request({
  77. url: app.globalData.prodUrl + 'web-pm/wx/pay/to_pay',
  78. data: {
  79. payno_id: res.data.payNo.kid,
  80. openid: wx.getStorageSync('key').openid
  81. },
  82. header: {
  83. 'ydw-token': wx.getStorageSync('key').ydw_token
  84. },
  85. success: function(data) {
  86. var time = new Date()
  87. wx.requestPayment({
  88. 'timeStamp': data.data.json.timeStamp,
  89. 'nonceStr': data.data.json.nonceStr,
  90. 'package': data.data.json.package,
  91. 'signType': 'MD5',
  92. 'paySign': data.data.json.paySign,
  93. 'success': function(res) {
  94. wx.navigateBack({
  95. delta: 1,
  96. success: function() {
  97. //console.log(data)
  98. wx.request({
  99. url: app.globalData.prodUrl + 'web-pm/wx/pm/push_one_user',
  100. header: {
  101. 'ydw-token': wx.getStorageSync('key').ydw_token
  102. },
  103. data: {
  104. payno_id: _this.data.payNo_id,
  105. formId: e.detail.formId
  106. },
  107. success: function (data) {
  108. //console.log(data)
  109. }
  110. })
  111. wx.showToast({
  112. title: '支付成功!',
  113. icon: 'none',
  114. duration: 3000
  115. });
  116. var pages = getCurrentPages();
  117. var page = getCurrentPages().pop();
  118. //console.log(pages)
  119. if (page == undefined || page == null) return;
  120. pages[1].onLoad(pages[1].options);
  121. }
  122. })
  123. },
  124. 'fail': function(res) {
  125. //console.log('fail', res)
  126. }
  127. })
  128. }
  129. })
  130. },
  131. fail: function(res) {}
  132. })
  133. }
  134. } else if (res.cancel) {
  135. //console.log('用户点击取消')
  136. }
  137. }
  138. })
  139. },
  140. /**
  141. * 生命周期函数--监听页面加载
  142. */
  143. onLoad: function(options) {
  144. var _this = this;
  145. wx.request({
  146. url: app.globalData.prodUrl + 'web-pm/wx/pm/prepare_payment',
  147. header: {
  148. 'ydw-token': wx.getStorageSync('key').ydw_token
  149. },
  150. data: {
  151. kid: options.kid
  152. },
  153. success: function(data) {
  154. _this.setData({
  155. array: data.data.item,
  156. shop: data.data.shop,
  157. msg: data.data.tip.msg,
  158. discount: data.data.balance,
  159. setDiscount: data.data.balance,
  160. totalSum: (data.data.item.price_end - data.data.balance).toFixed(2)
  161. });
  162. if (data.data.receive_address) {
  163. _this.setData({
  164. address: data.data.receive_address,
  165. })
  166. }
  167. },
  168. });
  169. },
  170. switch1Change: function (e) {
  171. //console.log(e);
  172. let _this = this;
  173. if(e.detail.value){
  174. _this.setData({
  175. setDiscount: _this.data.discount,
  176. totalSum: (_this.data.array.price_end - _this.data.discount).toFixed(2)
  177. })
  178. } else {
  179. _this.setData({
  180. setDiscount: 0,
  181. totalSum: _this.data.array.price_end
  182. })
  183. }
  184. },
  185. /**
  186. * 生命周期函数--监听页面初次渲染完成
  187. */
  188. onReady: function() {
  189. },
  190. /**
  191. * 生命周期函数--监听页面显示
  192. */
  193. onShow: function() {
  194. },
  195. /**
  196. * 生命周期函数--监听页面隐藏
  197. */
  198. onHide: function() {
  199. },
  200. /**
  201. * 生命周期函数--监听页面卸载
  202. */
  203. onUnload: function() {
  204. },
  205. /**
  206. * 页面相关事件处理函数--监听用户下拉动作
  207. */
  208. onPullDownRefresh: function() {
  209. },
  210. /**
  211. * 页面上拉触底事件的处理函数
  212. */
  213. onReachBottom: function() {
  214. }
  215. })