邃芒智像相册
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

230 rivejä
4.5 KiB

  1. const app = getApp()
  2. import request from '../../utils/request'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userInfo: {},
  9. firstData: null,// 首充数据
  10. orderList: [],
  11. imgUrl: 'https://formall.oss-accelerate.aliyuncs.com/ga/payOrder-1.png',
  12. currentIndex: null,
  13. currentId: '',
  14. isShowNumberCheck: false,
  15. phone: '',
  16. noticeText: ''
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. if (app.globalData.noticeText) {
  23. this.setData({
  24. noticeText: app.globalData.noticeText
  25. })
  26. }
  27. this.setData({
  28. userInfo: JSON.parse(options.userInfo)
  29. })
  30. // **已弃用
  31. // this.getProductDetail()
  32. this.getProductList()
  33. this.checkUserInfo()
  34. },
  35. // 获取产品详情(价格、库存等)**已弃用
  36. // getProductDetail() {
  37. // const that = this
  38. // request.get({
  39. // url: '/api/product/detail',
  40. // }).then(res => {
  41. // console.log(res, 'getProductDetail');
  42. // that.setData({
  43. // salePrice: res.data.salePrice,
  44. // price: res.data.price,
  45. // days: res.data.days,
  46. // })
  47. // }).catch(err => {
  48. // console.log(err, 'err');
  49. // })
  50. // },
  51. // 跳转至联系我们页面
  52. goToProductDetail() {
  53. wx.navigateTo({
  54. url: '/pages/ContactUs/ContactUs',
  55. })
  56. },
  57. getProductList() {
  58. const that = this
  59. request.get({
  60. url: '/api/product/list',
  61. }).then(res => {
  62. console.log(res, 'getProductList');
  63. const firstData = res.data.filter(item => item.first == 1)
  64. // 首充数据
  65. if (firstData.length) {
  66. const data = {
  67. days: firstData[0].days,
  68. price: firstData[0].price,
  69. salePrice: firstData[0].salePrice,
  70. }
  71. this.setData({
  72. firstData: data,
  73. currentId: firstData[0].id
  74. })
  75. // 非首冲数据
  76. } else {
  77. this.setData({
  78. orderList: res.data
  79. })
  80. }
  81. }).catch(err => {
  82. console.log(err, 'err');
  83. })
  84. },
  85. selectItem(e) {
  86. const index = e.currentTarget.dataset.index
  87. const id = e.currentTarget.dataset.id
  88. const currentIndex = this.data.currentIndex
  89. this.setData({
  90. currentIndex: index == currentIndex ? null : index,
  91. currentId: index == currentIndex ? '' : id
  92. })
  93. },
  94. createPayOrder() {
  95. if (!this.data.phone) {
  96. this.setData({
  97. isShowNumberCheck: true
  98. })
  99. return
  100. }
  101. if (!this.data.currentId) {
  102. wx.showToast({
  103. title: '请选择一个套餐!',
  104. icon: 'error'
  105. })
  106. }
  107. const data = {
  108. appId: request.appId,
  109. productId: this.data.currentId
  110. }
  111. request.post({
  112. url: '/api/pay/createPayOrder',
  113. data
  114. }).then(res => {
  115. console.log(res, 'createPayOrder');
  116. this.requestPayment(res.data.data)
  117. }).catch(err => {
  118. console.log(err, 'err');
  119. })
  120. },
  121. requestPayment(data) {
  122. wx.requestPayment({
  123. timeStamp: data.timeStamp,
  124. nonceStr: data.nonceStr,
  125. package: data.package,
  126. signType: data.signType ? data.signType : "MD5",
  127. paySign: data.paySign,
  128. success: res => {
  129. wx.showLoading({
  130. title: '订单正在处理中...',
  131. })
  132. setTimeout(() => {
  133. wx.navigateTo({
  134. url: '/pages/index/index?checkUserInfo="go"'
  135. })
  136. }, 2000);
  137. },
  138. fail: res => {
  139. wx.hideLoading();
  140. wx.showToast({
  141. title: '支付失败',
  142. icon: 'error'
  143. })
  144. /**
  145. * 支付失败,需要更新订单的状态
  146. */
  147. },
  148. complete: res => { }
  149. });
  150. },
  151. /**
  152. * @description 检查用户信息
  153. * @returns userInfo
  154. */
  155. checkUserInfo() {
  156. const that = this
  157. request.get({
  158. url: '/api/user/userinfo'
  159. }).then(res => {
  160. console.log(res, 'userinfo');
  161. that.setData({
  162. phone: res.data.phone || null
  163. })
  164. }).catch(err => {
  165. console.log(err, 'err');
  166. })
  167. },
  168. /**
  169. * 生命周期函数--监听页面初次渲染完成
  170. */
  171. onReady() {
  172. },
  173. /**
  174. * 生命周期函数--监听页面显示
  175. */
  176. onShow() {
  177. },
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide() {
  182. },
  183. /**
  184. * 生命周期函数--监听页面卸载
  185. */
  186. onUnload() {
  187. },
  188. /**
  189. * 页面相关事件处理函数--监听用户下拉动作
  190. */
  191. onPullDownRefresh() {
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom() {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage() {
  202. }
  203. })