details.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. options_goods_id:''
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  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. options_goods_id: options.goods_id
  33. })
  34. this.getDatas(options.goods_id)
  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. icon: 'none',
  153. title: '添加成功!',
  154. duration: 1500
  155. })
  156. }
  157. else {
  158. wx.showToast({
  159. icon: 'none',
  160. title: res.message,
  161. duration: 1500
  162. })
  163. }
  164. })
  165. }
  166. else if (cartOrBuy == 'isBuy') {
  167. if (this.data.getOneSummary.goods_storage < 1) {
  168. wx.showToast({
  169. title: '客官!暂时没有库存!',
  170. icon: 'none',
  171. duration: 1500
  172. })
  173. return
  174. }
  175. wx.navigateTo({
  176. url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
  177. })
  178. }
  179. else {
  180. return
  181. }
  182. },
  183. toWebView() {
  184. let webViewUrl = encodeURIComponent(this.data.webViewUrl)
  185. wx.navigateTo({
  186. url: `/pages/webView/webView?url=${webViewUrl}`
  187. })
  188. },
  189. animation_flag(e) {
  190. let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
  191. let flag = e.currentTarget.dataset.flag
  192. let animation_flag = flag == 'true' ? true : false
  193. this.setData({
  194. animation_flag,
  195. cartOrBuy
  196. })
  197. },
  198. getgift(sumarys, goods_id) {
  199. let goods = this.getOneSummary(sumarys, goods_id)
  200. let giftSummary = ''
  201. if (goods.have_gift) {
  202. giftSummary = this.getGiftSummary(sumarys, goods.gifts)
  203. }
  204. return giftSummary
  205. },
  206. getGiftSummary(sumarys, gifts) {
  207. let arr = []
  208. gifts.map(item => {
  209. sumarys.filter(sum => {
  210. if(item.gift_goods_id == sum.goods_id) {
  211. arr.push({
  212. sum,
  213. gifts: item
  214. })
  215. }
  216. })
  217. })
  218. return arr
  219. },
  220. /**
  221. * 生命周期函数--监听页面初次渲染完成
  222. */
  223. onReady: function () {
  224. },
  225. /**
  226. * 生命周期函数--监听页面显示
  227. */
  228. onShow: function () {
  229. if (app.globalData.fcodeErr) {
  230. wx.showToast({
  231. icon: 'none',
  232. title: app.globalData.fcodeErr,
  233. duration: 1500
  234. })
  235. app.globalData.fcodeErr = ''
  236. this.setData({
  237. animation_flag: false
  238. })
  239. // console.log(this.data.options_goods_id)
  240. setTimeout(() => {
  241. this.getDatas(this.data.options_goods_id)
  242. }, 1500)
  243. }
  244. if (app.globalData.backLogin) {
  245. this.getDatas(this.data.getOneSummary.goods_id);
  246. }
  247. },
  248. /**
  249. * 生命周期函数--监听页面隐藏
  250. */
  251. onHide: function () {
  252. },
  253. /**
  254. * 生命周期函数--监听页面卸载
  255. */
  256. onUnload: function () {
  257. },
  258. /**
  259. * 页面相关事件处理函数--监听用户下拉动作
  260. */
  261. onPullDownRefresh: function () {
  262. },
  263. /**
  264. * 页面上拉触底事件的处理函数
  265. */
  266. onReachBottom: function () {
  267. },
  268. /**
  269. * 用户点击右上角分享
  270. */
  271. onShareAppMessage: function () {
  272. }
  273. })