seckillDetail.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // subPackagesF/pages/seckillDetail/seckillDetail.js
  2. import {
  3. get,
  4. } from '../../../utils/http'
  5. var WxParse = require('../../../components/local/wxParse/wxParse.js')
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. store_id:'', //店铺ID
  12. storeName:'',//店铺名称
  13. goods_id:'',//商品ID
  14. seckillDetail:[],//秒杀产品详情
  15. seckill_id:"",//秒杀ID
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. console.log(options);
  22. this.setData({
  23. goods_id:options.goods_id,
  24. store_id:wx.getStorageSync('store_id'),
  25. seckill_id:options.seckill_id
  26. })
  27. // 获取店铺信息
  28. this.getStoreInfo()
  29. // 获取秒杀产品详情
  30. this.getSeckillDetail()
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady() {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow() {
  41. },
  42. /**
  43. * 去除富文本图片默认样式
  44. */
  45. removeCss(content) {
  46. let reg = /(style|class)="[^"]+"/gi
  47. let img = /<img[^>]+>/gi
  48. let res
  49. if (img.test(content)) {
  50. res = content.match(img)
  51. for (let i = 0; i < res.length; i++) {
  52. content = content.replace(res[i], res[i].replace(reg, ''))
  53. }
  54. }
  55. return content.replace(/\<img/gi, '<img class="richImg" ')
  56. },
  57. // 获取秒杀商品详情
  58. getSeckillDetail(){
  59. get('v2/api/spike/info',{
  60. id:this.data.goods_id,
  61. seckill_id:this.data.seckill_id
  62. },(res=>{
  63. if(res.code==200){
  64. let content = this.removeCss(res.data.content)
  65. res.data.content = this.removeCss(res.data.content)
  66. WxParse.wxParse('article', 'html', content, this, 5)
  67. res.data.banner_urls = res.data.banner_urls.split(',');
  68. this.setData({
  69. seckillDetail:res.data
  70. })
  71. }
  72. }))
  73. },
  74. // 获取店铺信息
  75. getStoreInfo(){
  76. get('api/store/info',{store_id:this.data.store_id},(res=>{
  77. if(res.code==200){
  78. this.setData({
  79. storeName:res.data.store_name
  80. })
  81. }
  82. }))
  83. },
  84. // 跳转到秒杀产品订单
  85. goSeckillOrder(){
  86. wx.navigateTo({
  87. url: `/subPackagesF/pages/seckillOrder/seckillOrder?goods_id=${this.data.goods_id}&&store_id=${this.data.store_id}&seckill_id=${this.data.seckill_id}`,
  88. })
  89. },
  90. /**
  91. * 生命周期函数--监听页面隐藏
  92. */
  93. onHide() {
  94. },
  95. /**
  96. * 生命周期函数--监听页面卸载
  97. */
  98. onUnload() {
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh() {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom() {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage() {
  114. }
  115. })