details.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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: true,
  18. sec_index: 0,
  19. goodsNumber: 1,
  20. cartOrBuy: '',
  21. getgift: ''
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. let webViewUrl = `https://passport.lrlz.com/mobile/index.php?act=goods_common&op=detail&goods_id=${options.goods_id}&client_type=ios`
  28. this.setData({
  29. webViewUrl
  30. })
  31. this.getDatas(options.goods_id)
  32. // this.getDatas(6779)
  33. },
  34. getDatas(goods_id) {
  35. wx.showLoading({
  36. title: '加载中',
  37. })
  38. var self = this
  39. getReq({
  40. act: 'goods_common',
  41. op: 'index',
  42. goods_id
  43. }, function (res) {
  44. wx.hideLoading()
  45. if (res.code == 200) {
  46. let oneSummary = self.getOneSummary(res.datas.summary, goods_id)
  47. let getgift = self.getgift(res.datas.summary, goods_id)
  48. self.setData({
  49. datas: res.datas,
  50. getOneSummary: oneSummary,
  51. imgUrls: res.datas.common_info.images,
  52. getgift
  53. })
  54. }
  55. else {
  56. wx.showToast({
  57. icon: 'none',
  58. title: res.message,
  59. duration: 1500
  60. })
  61. }
  62. })
  63. },
  64. getOneSummary(sumarys, goods_id) {
  65. let getOneSummary = sumarys.filter((item, index) => {
  66. return item.goods_id == goods_id
  67. })
  68. return getOneSummary[0]
  69. },
  70. secSku(e) {
  71. let goodsId = e.currentTarget.dataset.goodsid
  72. let sec_index = e.currentTarget.dataset.secindex
  73. if (this.data.sec_index == sec_index) {
  74. return
  75. }
  76. let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
  77. let getgift = this.getgift(this.data.datas.summary, goodsId)
  78. if (getOneSummary.goods_storage < 1) {
  79. wx.showToast({
  80. title: '客官!暂时没有库存!',
  81. icon: 'none',
  82. duration: 1500
  83. })
  84. return
  85. }
  86. this.setData({
  87. sec_index,
  88. getOneSummary,
  89. goodsNumber: 1,
  90. getgift
  91. })
  92. },
  93. goodsNumHandle(e) {
  94. let type = e.currentTarget.dataset.type
  95. if (type == 'minus') {
  96. if (this.data.goodsNumber <= 1) {
  97. wx.showToast({
  98. title: '客官!不能再少了!',
  99. icon: 'none',
  100. duration: 1500
  101. })
  102. return
  103. }
  104. else {
  105. this.setData({
  106. goodsNumber: --this.data.goodsNumber
  107. })
  108. }
  109. }
  110. else {
  111. if (this.data.goodsNumber >= this.data.getOneSummary['goods_storage']) {
  112. wx.showToast({
  113. title: '客官!只有这么多了!',
  114. icon: 'none',
  115. duration: 1500
  116. })
  117. return
  118. }
  119. else {
  120. this.setData({
  121. goodsNumber: ++this.data.goodsNumber
  122. })
  123. }
  124. }
  125. },
  126. checkSubmit() {
  127. let cartOrBuy = this.data.cartOrBuy
  128. this.setData({
  129. animation_flag: false
  130. })
  131. if (cartOrBuy == 'isCart') {
  132. wx.showLoading({
  133. title: '加载中',
  134. })
  135. getReq({
  136. act: 'cart',
  137. op: 'addex',
  138. quantity: this.data.goodsNumber,
  139. goods_id: this.data.getOneSummary.goods_id
  140. }, function (res) {
  141. wx.hideLoading()
  142. if (res.code == 200) {
  143. wx.showToast({
  144. title: '添加成功!',
  145. duration: 1500
  146. })
  147. }
  148. else {
  149. wx.showToast({
  150. icon: 'none',
  151. title: res.message,
  152. duration: 1500
  153. })
  154. }
  155. })
  156. }
  157. else if (cartOrBuy == 'isBuy') {
  158. wx.navigateTo({
  159. url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
  160. })
  161. }
  162. else {
  163. return
  164. }
  165. },
  166. toWebView() {
  167. let webViewUrl = encodeURIComponent(this.data.webViewUrl)
  168. wx.navigateTo({
  169. url: `/pages/webView/webView?url=${webViewUrl}`
  170. })
  171. },
  172. animation_flag(e) {
  173. let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
  174. let flag = e.currentTarget.dataset.flag
  175. let animation_flag = flag == 'true' ? true : false
  176. this.setData({
  177. animation_flag,
  178. cartOrBuy
  179. })
  180. },
  181. getgift(sumarys, goods_id) {
  182. let goods = this.getOneSummary(sumarys, goods_id)
  183. let giftSummary = ''
  184. if (goods.have_gift) {
  185. giftSummary = this.getGiftSummary(sumarys, goods.gifts)
  186. }
  187. return giftSummary
  188. },
  189. getGiftSummary(sumarys, gifts) {
  190. let arr = []
  191. gifts.map(item => {
  192. sumarys.filter(sum => {
  193. if(item.gift_goods_id == sum.goods_id) {
  194. arr.push({
  195. sum,
  196. gifts: item
  197. })
  198. }
  199. })
  200. })
  201. return arr
  202. },
  203. /**
  204. * 生命周期函数--监听页面初次渲染完成
  205. */
  206. onReady: function () {
  207. },
  208. /**
  209. * 生命周期函数--监听页面显示
  210. */
  211. onShow: function () {
  212. },
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide: function () {
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload: function () {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. onReachBottom: function () {
  232. },
  233. /**
  234. * 用户点击右上角分享
  235. */
  236. onShareAppMessage: function () {
  237. }
  238. })