index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Page({
  2. dever: getApp().dever,
  3. product_id: '',
  4. data: {
  5. content: ''
  6. },
  7. onLoad: function (options) {
  8. var that = this;
  9. that.dever.showLoading();
  10. if(typeof options.scene == 'undefined'){
  11. that.product_id = options.id;
  12. }else{
  13. var scene = decodeURIComponent(options.scene);
  14. scene = scene.split(',');
  15. //var uid = scene[0];
  16. that.product_id = scene[1];
  17. }
  18. that.dever.request('product.api.view',{
  19. signature: that.dever.getSignature(),
  20. id: that.product_id
  21. }, {
  22. success: function (data, res) {
  23. var temp = that.dever.html('content', data.product.content, that);
  24. that.setData({
  25. content: temp
  26. })
  27. that.dever.hideLoading();
  28. }
  29. });
  30. },
  31. /**
  32. * 跳转海报分享页面,分享海报
  33. */
  34. toShare: function(){
  35. var that = this;
  36. that.dever.isLogin(function (res) {
  37. if (res) {
  38. this.dever.location('poster/index');
  39. } else {
  40. that.dever.location('login/index');
  41. }
  42. });
  43. },
  44. /**
  45. * 立即购买
  46. */
  47. doBuy: function(e){
  48. var that = this;
  49. this.dever.isLogin(function (res) {
  50. if (res) {
  51. that.dever.request('product.api.addCarts', {
  52. json: 1,
  53. signature: that.dever.getSignature(),
  54. product_id: that.product_id,
  55. num: 1
  56. }, {
  57. success: function (data, res) {
  58. that.dever.location('carts/index?id=' + that.product_id);
  59. }
  60. });
  61. } else {
  62. that.dever.location('login/index');
  63. }
  64. });
  65. }
  66. })