details.js 5.9 KB

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