index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.isAuth('scope.userInfo', function (res) {
  33. if (res) {
  34. app.request('product.api.addCarts', { product_id: that.pid, num: 1 }, {
  35. success: function (data, res) {
  36. app.location('carts/index?id=' + that.pid);
  37. }
  38. })
  39. } else {
  40. app.location('login/index');
  41. }
  42. });
  43. },
  44. /**
  45. * 用户点击右上角分享
  46. */
  47. onShareAppMessage: function (options) {
  48. //打开好友列表
  49. wx.showShareMenu({
  50. withShareTicket: true,
  51. success: function (res) {
  52. console.log('wx.showShareMenu success', res.data);
  53. },
  54. fail: function (res) {
  55. console.log('wx.showShareMenu fail', res.data);
  56. }
  57. });
  58. if (app.getUid() != '') {//拼接分享参数
  59. var scene = app.getUid() + ',' + this.pid;
  60. return {
  61. title: '',
  62. desc: '',
  63. path: '/template/home/index?scene=' + encodeURIComponent(scene)
  64. };
  65. }
  66. }
  67. })