details.js 5.7 KB

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