details.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. else {
  53. wx.showToast({
  54. icon: 'none',
  55. title: res.message,
  56. duration: 2000
  57. })
  58. }
  59. })
  60. },
  61. getOneSummary(sumarys, goods_id) {
  62. let getOneSummary = sumarys.filter((item, index) => {
  63. return item.goods_id == goods_id
  64. })
  65. return getOneSummary[0]
  66. },
  67. secSku(e) {
  68. let goodsId = e.currentTarget.dataset.goodsid
  69. let sec_index = e.currentTarget.dataset.secindex
  70. if (this.data.sec_index == sec_index) {
  71. return
  72. }
  73. let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
  74. this.setData({
  75. sec_index,
  76. getOneSummary,
  77. goodsNumber: 1
  78. })
  79. },
  80. goodsNumHandle(e) {
  81. let type = e.currentTarget.dataset.type
  82. if (type == 'minus') {
  83. if (this.data.goodsNumber <= 1) {
  84. wx.showToast({
  85. title: '客官!不能再少了!',
  86. icon: 'none',
  87. duration: 2000
  88. })
  89. return
  90. }
  91. else {
  92. this.setData({
  93. goodsNumber: --this.data.goodsNumber
  94. })
  95. }
  96. }
  97. else {
  98. if (this.data.goodsNumber >= this.data.getOneSummary['goods_storage']) {
  99. wx.showToast({
  100. title: '客官!只有这么多了!',
  101. icon: 'none',
  102. duration: 2000
  103. })
  104. return
  105. }
  106. else {
  107. this.setData({
  108. goodsNumber: ++this.data.goodsNumber
  109. })
  110. }
  111. }
  112. },
  113. checkSubmit() {
  114. let cartOrBuy = this.data.cartOrBuy
  115. this.setData({
  116. animation_flag: false
  117. })
  118. if (cartOrBuy == 'isCart') {
  119. wx.showLoading({
  120. title: '加载中',
  121. })
  122. getReq({
  123. act: 'cart',
  124. op: 'addex',
  125. quantity: this.data.goodsNumber,
  126. goods_id: this.data.getOneSummary.goods_id
  127. }, function (res) {
  128. wx.hideLoading()
  129. if (res.code == 200) {
  130. wx.showToast({
  131. title: '添加成功!',
  132. duration: 2000
  133. })
  134. }
  135. else {
  136. wx.showToast({
  137. icon: 'none',
  138. title: res.message,
  139. duration: 2000
  140. })
  141. }
  142. })
  143. }
  144. else if (cartOrBuy == 'isBuy') {
  145. wx.navigateTo({
  146. url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
  147. // // 测试多种商品
  148. // url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=1&num=${this.data.goodsNumber}&cart_id='131344,131343,131342'`
  149. })
  150. }
  151. else {
  152. return
  153. }
  154. },
  155. toWebView() {
  156. let webViewUrl = encodeURIComponent(this.data.webViewUrl)
  157. wx.navigateTo({
  158. url: `/pages/webView/webView?url=${webViewUrl}`
  159. })
  160. },
  161. animation_flag(e) {
  162. let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
  163. let flag = e.currentTarget.dataset.flag
  164. let animation_flag = flag == 'true' ? true : false
  165. this.setData({
  166. animation_flag,
  167. cartOrBuy
  168. })
  169. },
  170. /**
  171. * 生命周期函数--监听页面初次渲染完成
  172. */
  173. onReady: function () {
  174. },
  175. /**
  176. * 生命周期函数--监听页面显示
  177. */
  178. onShow: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload: function () {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh: function () {
  194. },
  195. /**
  196. * 页面上拉触底事件的处理函数
  197. */
  198. onReachBottom: function () {
  199. },
  200. /**
  201. * 用户点击右上角分享
  202. */
  203. onShareAppMessage: function () {
  204. }
  205. })