details.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // pages/details/details.js
  2. const getReq = require('./../../config.js').getReq;
  3. const app = getApp();
  4. var WxParse = require('../../wxParse/wxParse.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgUrls: [],
  11. datas: {},
  12. getOneSummary: [],
  13. webViewUrl: '',
  14. indicatorDots: true,
  15. vertical: false,
  16. autoplay: true,
  17. interval: 2000,
  18. duration: 500,
  19. animation_flag: false,
  20. sec_index: 0,
  21. goodsNumber: 1,
  22. cartOrBuy: '',
  23. getgift: '',
  24. options_goods_id: ''
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. let webViewUrl = `https://passport.lrlz.com/mobile/index.php?act=goods_common&op=detail&goods_id=${options.goods_id}&client_type=ios`
  31. this.setData({
  32. webViewUrl,
  33. options_goods_id: options.goods_id
  34. })
  35. // console.log(options.goods_id)
  36. this.getDatas(options.goods_id)
  37. // this.getDatas(7636)
  38. var that = this;
  39. getReq({
  40. act: 'goods_common',
  41. op: 'detail',
  42. goods_id: options.goods_id
  43. }, function(res) {
  44. var str = res.split(/<[\/]?body>/gi)[1];
  45. console.log(str);
  46. WxParse.wxParse('article', 'html', str, that);
  47. });
  48. },
  49. getDatas(goods_id) {
  50. wx.showLoading({
  51. title: '加载中',
  52. })
  53. var self = this
  54. getReq({
  55. act: 'goods_common',
  56. op: 'index',
  57. goods_id
  58. }, function (res) {
  59. wx.hideLoading()
  60. if (res.code == 200) {
  61. let oneSummary = self.getOneSummary(res.datas.summary, goods_id)
  62. let getgift = self.getgift(res.datas.summary, goods_id)
  63. let differencePrice = (oneSummary.goods_price - oneSummary.bonus_price).toFixed(2)
  64. oneSummary = Object.assign({}, { differencePrice }, oneSummary)
  65. self.setData({
  66. datas: res.datas,
  67. getOneSummary: oneSummary,
  68. imgUrls: res.datas.common_info.images,
  69. getgift
  70. })
  71. }
  72. else {
  73. wx.showToast({
  74. icon: 'none',
  75. title: res.message,
  76. duration: 1500
  77. })
  78. }
  79. })
  80. },
  81. getOneSummary(sumarys, goods_id) {
  82. let getOneSummary = sumarys.filter((item, index) => {
  83. return item.goods_id == goods_id
  84. })
  85. return getOneSummary[0]
  86. },
  87. secSku(e) {
  88. let goodsId = e.currentTarget.dataset.goodsid
  89. let sec_index = e.currentTarget.dataset.secindex
  90. if (this.data.sec_index == sec_index) {
  91. return
  92. }
  93. let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
  94. let getgift = this.getgift(this.data.datas.summary, goodsId)
  95. if (getOneSummary.goods_storage < 1) {
  96. wx.showToast({
  97. title: '客官!暂时没有库存!',
  98. icon: 'none',
  99. duration: 1500
  100. })
  101. return
  102. }
  103. this.setData({
  104. sec_index,
  105. getOneSummary,
  106. goodsNumber: 1,
  107. getgift
  108. })
  109. },
  110. goodsNumHandle(e) {
  111. let type = e.currentTarget.dataset.type
  112. if (type == 'minus') {
  113. if (this.data.goodsNumber <= 1) {
  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. else {
  128. if (this.data.goodsNumber >= this.data.getOneSummary['goods_storage']) {
  129. wx.showToast({
  130. title: '客官!只有这么多了!',
  131. icon: 'none',
  132. duration: 1500
  133. })
  134. return
  135. }
  136. else {
  137. this.setData({
  138. goodsNumber: ++this.data.goodsNumber
  139. })
  140. }
  141. }
  142. },
  143. checkSubmit() {
  144. if (!app.globalData.userInfo) {
  145. wx.navigateTo({
  146. url: '/pages/login/login'
  147. });
  148. return;
  149. }
  150. let cartOrBuy = this.data.cartOrBuy
  151. this.setData({
  152. animation_flag: false
  153. })
  154. if (cartOrBuy == 'isCart') {
  155. wx.showLoading({
  156. title: '加载中',
  157. })
  158. getReq({
  159. act: 'cart',
  160. op: 'addex',
  161. quantity: this.data.goodsNumber,
  162. goods_id: this.data.getOneSummary.goods_id
  163. }, function (res) {
  164. wx.hideLoading()
  165. if (res.code == 200) {
  166. wx.showToast({
  167. icon: 'none',
  168. title: '添加成功!',
  169. duration: 1500
  170. })
  171. }
  172. else {
  173. wx.showToast({
  174. icon: 'none',
  175. title: res.message,
  176. duration: 1500
  177. })
  178. }
  179. })
  180. }
  181. else if (cartOrBuy == 'isBuy') {
  182. if (this.data.getOneSummary.goods_storage < 1) {
  183. wx.showToast({
  184. title: '客官!暂时没有库存!',
  185. icon: 'none',
  186. duration: 1500
  187. })
  188. return
  189. }
  190. wx.navigateTo({
  191. url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
  192. })
  193. }
  194. else {
  195. return
  196. }
  197. },
  198. toWebView() {
  199. let webViewUrl = encodeURIComponent(this.data.webViewUrl)
  200. wx.navigateTo({
  201. url: `/pages/webView/webView?url=${webViewUrl}`
  202. })
  203. },
  204. animation_flag(e) {
  205. let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
  206. let flag = e.currentTarget.dataset.flag
  207. let animation_flag = flag == 'true' ? true : false
  208. this.setData({
  209. animation_flag,
  210. cartOrBuy
  211. })
  212. },
  213. getgift(sumarys, goods_id) {
  214. let goods = this.getOneSummary(sumarys, goods_id)
  215. let giftSummary = ''
  216. if (goods.have_gift) {
  217. giftSummary = this.getGiftSummary(sumarys, goods.gifts)
  218. }
  219. return giftSummary
  220. },
  221. getGiftSummary(sumarys, gifts) {
  222. let arr = []
  223. gifts.map(item => {
  224. sumarys.filter(sum => {
  225. if (item.gift_goods_id == sum.goods_id) {
  226. arr.push({
  227. sum,
  228. gifts: item
  229. })
  230. }
  231. })
  232. })
  233. return arr
  234. },
  235. /**
  236. * 生命周期函数--监听页面初次渲染完成
  237. */
  238. onReady: function () {
  239. },
  240. /**
  241. * 生命周期函数--监听页面显示
  242. */
  243. onShow: function () {
  244. if (app.globalData.fcodeErr) {
  245. wx.showToast({
  246. icon: 'none',
  247. title: app.globalData.fcodeErr,
  248. duration: 1500
  249. })
  250. app.globalData.fcodeErr = ''
  251. this.setData({
  252. animation_flag: false
  253. })
  254. setTimeout(() => {
  255. this.getDatas(this.data.options_goods_id)
  256. }, 1500)
  257. }
  258. if (app.globalData.backLogin) {
  259. this.getDatas(this.data.getOneSummary.goods_id);
  260. }
  261. },
  262. /**
  263. * 生命周期函数--监听页面隐藏
  264. */
  265. onHide: function () {
  266. },
  267. /**
  268. * 生命周期函数--监听页面卸载
  269. */
  270. onUnload: function () {
  271. },
  272. /**
  273. * 页面相关事件处理函数--监听用户下拉动作
  274. */
  275. onPullDownRefresh: function () {
  276. },
  277. /**
  278. * 页面上拉触底事件的处理函数
  279. */
  280. onReachBottom: function () {
  281. },
  282. /**
  283. * 用户点击右上角分享
  284. */
  285. onShareAppMessage: function () {
  286. let goods_id = this.data.options_goods_id
  287. let goods_name = this.data.getOneSummary.goods_mobile_name
  288. let imageUrl = this.data.imgUrls[0];
  289. return {
  290. title: `熊猫美妆为您推荐:${goods_name}`,
  291. path: `/pages/details/details?goods_id=${goods_id}`,
  292. imageUrl: imageUrl
  293. }
  294. }
  295. })