details.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // pages/details/details.js
  2. const getReq = require('./../../config.js').getReq
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrls: [],
  9. datas: {},
  10. getOneSummary: [],
  11. webViewUrl: '',
  12. indicatorDots: true,
  13. vertical: false,
  14. autoplay: true,
  15. interval: 2000,
  16. duration: 500,
  17. animation_flag: false,
  18. sec_index: 0,
  19. goodsNumber: 1,
  20. cartOrBuy: ''
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. let webViewUrl = `https://passport.lrlz.com/mobile/index.php?act=goods_common&op=detail&goods_id=${options.goods_id}&client_type=ios`
  27. this.setData({
  28. webViewUrl
  29. })
  30. // this.getDatas(options.goods_id)
  31. this.getDatas(6417)
  32. },
  33. getDatas(goods_id) {
  34. wx.showLoading({
  35. title: '加载中',
  36. })
  37. var self = this
  38. getReq({
  39. act: 'goods_common',
  40. op: 'index',
  41. goods_id
  42. }, function (res) {
  43. wx.hideLoading()
  44. if (res.code == 200) {
  45. let oneSummary = self.getOneSummary(res.datas.summary,goods_id)
  46. self.setData({
  47. datas: res.datas,
  48. getOneSummary: oneSummary,
  49. imgUrls: res.datas.common_info.images
  50. })
  51. }
  52. })
  53. },
  54. getOneSummary(sumarys,goods_id) {
  55. let getOneSummary = sumarys.filter((item, index) => {
  56. return item.goods_id == goods_id
  57. })
  58. return getOneSummary[0]
  59. },
  60. secSku(e) {
  61. let goodsId = e.currentTarget.dataset.goodsid
  62. let sec_index = e.currentTarget.dataset.secindex
  63. if (this.data.sec_index == sec_index) {
  64. return
  65. }
  66. let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
  67. this.setData({
  68. sec_index,
  69. getOneSummary,
  70. goodsNumber: 1
  71. })
  72. },
  73. goodsNumHandle(e) {
  74. let type = e.currentTarget.dataset.type
  75. if (type == 'minus') {
  76. if (this.data.goodsNumber <= 1) {
  77. wx.showToast({
  78. title: '客官!不能再少了!',
  79. icon: 'none',
  80. duration: 2000
  81. })
  82. return
  83. }
  84. else {
  85. this.setData({
  86. goodsNumber: --this.data.goodsNumber
  87. })
  88. }
  89. }
  90. else {
  91. if (this.data.goodsNumber >= this.data.getOneSummary['goods_storage']) {
  92. wx.showToast({
  93. title: '客官!只有这么多了!',
  94. icon: 'none',
  95. duration: 2000
  96. })
  97. return
  98. }
  99. else {
  100. this.setData({
  101. goodsNumber: ++this.data.goodsNumber
  102. })
  103. }
  104. }
  105. },
  106. checkSubmit() {
  107. let cartOrBuy = this.data.cartOrBuy
  108. this.setData({
  109. animation_flag: false
  110. })
  111. if (cartOrBuy == 'isCart') {
  112. wx.showLoading({
  113. title: '加载中',
  114. })
  115. getReq({
  116. act: 'cart',
  117. op: 'addex',
  118. quantity: this.data.goodsNumber,
  119. goods_id: this.data.getOneSummary.goods_id
  120. },function(res) {
  121. wx.hideLoading()
  122. if (res.code == 200) {
  123. wx.showToast({
  124. title: '添加成功!',
  125. duration: 2000
  126. })
  127. }
  128. else {
  129. wx.showToast({
  130. icon: 'none',
  131. title: res.message,
  132. duration: 2000
  133. })
  134. }
  135. })
  136. }
  137. else if (cartOrBuy == 'isBuy') {
  138. wx.navigateTo({
  139. url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
  140. // // 测试多种商品
  141. // url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=1&num=${this.data.goodsNumber}&cart_id='131344,131343,131342'`
  142. })
  143. }
  144. else {
  145. return
  146. }
  147. },
  148. toWebView() {
  149. let webViewUrl = encodeURIComponent(this.data.webViewUrl)
  150. wx.navigateTo({
  151. url: `/pages/webView/webView?url=${webViewUrl}`
  152. })
  153. },
  154. animation_flag(e) {
  155. let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
  156. let flag = e.currentTarget.dataset.flag
  157. let animation_flag = flag == 'true' ? true : false
  158. this.setData({
  159. animation_flag,
  160. cartOrBuy
  161. })
  162. },
  163. /**
  164. * 生命周期函数--监听页面初次渲染完成
  165. */
  166. onReady: function () {
  167. },
  168. /**
  169. * 生命周期函数--监听页面显示
  170. */
  171. onShow: function () {
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function () {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function () {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function () {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage: function () {
  197. }
  198. })