item.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var WxParse = require('../../wxParse/wxParse.js');
  2. const app = getApp()
  3. Page({
  4. data: {
  5. loading: false,
  6. disabled: true,
  7. item_id: 0,
  8. items: [],
  9. },
  10. /**
  11. * 生命周期函数--监听页面显示
  12. */
  13. onLoad: function (options) {
  14. app.setUcode(options); //读取邀请码
  15. if (options.scene) {
  16. var scene = app.util().strToArray(decodeURIComponent(options.scene));
  17. var item_id = parseInt(scene.id);
  18. } else {
  19. var item_id = parseInt(options.id);
  20. }
  21. //获取当前页面点击ID
  22. this.setData({ item_id: item_id });
  23. },
  24. /**
  25. * 生命周期函数--监听页面显示
  26. */
  27. onShow: function () {
  28. this.getItem();
  29. },
  30. /**
  31. * 获取商品信息
  32. */
  33. getItem: function (e) {
  34. let that = this;
  35. var item_id = that.data.item_id;
  36. app.api().Get('api/v3/fastshop/sale/item', {
  37. 'id': item_id
  38. }, function (result) {
  39. if (result.data.types == 1 && result.data.state == 1){
  40. that.setData({
  41. disabled:false,
  42. });
  43. }
  44. that.setData({
  45. items: result.data,
  46. });
  47. WxParse.wxParse('content','html',result.data.item.content,that,0);
  48. })
  49. },
  50. //立即购买
  51. buy_now: function () {
  52. let that = this;
  53. var item_id = that.data.item_id;
  54. //下单前查询是否有库存和购买
  55. wx.showLoading({title: '抢购中'})
  56. app.api().Post('api/v3/fastshop/order/isOrder',{'id': item_id}, function (result) {
  57. wx.setStorageSync('cart',item_id)
  58. setTimeout(function () {
  59. wx.navigateTo({ url: 'dopay' })
  60. }, 600)
  61. })
  62. },
  63. /**
  64. * 分享按钮
  65. */
  66. onShareAppMessage: function (res) {
  67. let that = this;
  68. var item_id = that.data.item_id,ucode = app.globalData.loginuser.ucode;
  69. return {
  70. path: '/pages/market/item?id=' + item_id + '&ucode=' + ucode,
  71. }
  72. },
  73. //返回首页
  74. toRedirect: function () {
  75. wx.switchTab({
  76. url: '/pages/index/index',
  77. });
  78. },
  79. //滚动
  80. onPageScroll(res) {
  81. wx.createSelectorQuery().select('.weui-panel').boundingClientRect().exec(rect => {
  82. if (rect[0].top - 100 <= 0){
  83. this.setData({
  84. 'barbolor':'#FFFFFF',
  85. 'appname': '产品详情'
  86. })
  87. }else{
  88. this.setData({
  89. 'barbolor': 'none',
  90. 'appname': ''
  91. })
  92. }
  93. })
  94. }
  95. })