index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const app = getApp();
  2. Page({
  3. pid: '',
  4. onLoad: function (options) {
  5. this.pid = options.id;
  6. var that = this;
  7. app.showLoading();
  8. app.request('product.api.view', {id: this.pid}, {
  9. success: function (data, res) {
  10. app.html('content', data.product.content, that);
  11. },
  12. complete: function(res){
  13. app.hideLoading();
  14. }
  15. })
  16. },
  17. /**
  18. * 跳转海报分享页面,分享海报
  19. */
  20. toShare: function(){
  21. if(app.isLogin()){
  22. app.location('poster/index?id=' + this.pid);
  23. }else{
  24. app.location('login/index');
  25. }
  26. },
  27. /**
  28. * 立即购买
  29. */
  30. doBuy: function(e){
  31. var that = this;
  32. app.showLoading();
  33. app.isAuth('scope.userInfo', function (res) {
  34. if (res) {
  35. app.request('product.api.addCarts', { product_id: that.pid, num: 1 }, {
  36. success: function (data, res) {
  37. app.location('carts/index?id=' + that.pid);
  38. },
  39. complete: function (res) {
  40. app.hideLoading();
  41. }
  42. })
  43. } else {
  44. app.location('login/index');
  45. }
  46. });
  47. },
  48. /**
  49. * 用户点击右上角分享
  50. */
  51. onShareAppMessage: function (options) {
  52. //打开好友列表
  53. wx.showShareMenu({
  54. withShareTicket: true,
  55. success: function (res) {
  56. console.log('wx.showShareMenu success', res.data);
  57. },
  58. fail: function (res) {
  59. console.log('wx.showShareMenu fail', res.data);
  60. }
  61. });
  62. if (app.getUid() != '') {//拼接分享参数
  63. var scene = app.getUid() + ',' + this.pid;
  64. return {
  65. title: '',
  66. desc: '',
  67. path: '/template/home/index?scene=' + encodeURIComponent(scene)
  68. };
  69. }
  70. }
  71. })