details.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const _Http = getApp().globalData.http,
  2. MFT = require("../../utils/matchingFeilType"),
  3. checkFile = require("../../utils/checkFile");
  4. import Dialog from '@vant/weapp/dialog/dialog';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. sat_sharematerialid: null,
  11. detailsData: {},
  12. dataType: 0
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. async onLoad(options) {
  18. this.setData({
  19. dataType: options.type,
  20. sat_sharematerialid: options.id
  21. })
  22. let isToken = wx.getStorageSync('userMsg').token; //判断是否为无状态进入
  23. const params = {
  24. "classname": "saletool.sharematerial.sharematerial",
  25. "method": isToken ? "selectDetail" : "selectDetailNoToken",
  26. "content": {
  27. "sat_sharematerialid": options.id
  28. }
  29. };
  30. const res = isToken ? await _Http.basic(params) : await _Http.base(params);
  31. if (res.msg != '成功') res = await _Http.base(params);
  32. if (res.msg == '成功') {
  33. if (res.data.attinfos.length) res.data.attinfos = MFT.fileList(res.data.attinfos);
  34. this.setData({
  35. detailsData: res.data
  36. });
  37. //分享进入
  38. if (wx.getLaunchOptionsSync().scene == 1154) {
  39. this.addNew(false)
  40. } else if ([1007, 1008].includes(wx.getLaunchOptionsSync().scene)) Dialog.confirm({
  41. title: '提示',
  42. message: '请帮助完善信息',
  43. })
  44. .then(this.addNew)
  45. .catch(this.addNew)
  46. } else {
  47. wx.showToast({
  48. title: res.msg,
  49. icon: "none"
  50. })
  51. }
  52. },
  53. /* 新增拉新用户 */
  54. async addNew(gain = true) {
  55. let name = '微信用户';
  56. if (gain) name = await new Promise((res, rej) => {
  57. wx.getUserProfile({
  58. desc: '用于完善用户资料',
  59. success: ({
  60. userInfo
  61. }) => {
  62. res(userInfo.nickName)
  63. },
  64. fail: () => {
  65. res('微信用户')
  66. }
  67. })
  68. })
  69. let channel = null,
  70. that = this;
  71. switch (wx.getLaunchOptionsSync().scene) {
  72. case 1007:
  73. channel = '单人会话分享'
  74. break;
  75. case 1008:
  76. channel = '群聊会话分享'
  77. break;
  78. case 1154:
  79. channel = '朋友圈分享'
  80. break;
  81. default:
  82. channel = '其他方式'
  83. break;
  84. }
  85. wx.login({
  86. success(res) {
  87. _Http.base({
  88. "classname": "saletool.sharematerial.sharematerial",
  89. "method": "addNew",
  90. "content": {
  91. "sat_sharematerialid": that.data.sat_sharematerialid,
  92. "fname": name,
  93. "channel": channel,
  94. "code": res.code,
  95. "systemclient": "wechatsaletool"
  96. }
  97. }, false).then(res => {
  98. console.log("记录分享", res)
  99. })
  100. }
  101. })
  102. },
  103. openFile(e) {
  104. checkFile.checkFile(e.currentTarget.dataset.item);
  105. },
  106. updateShareLog(id) {
  107. _Http.basic({
  108. "classname": "saletool.sharematerial.sharematerial",
  109. "method": "updateShareLog",
  110. "content": {
  111. "sat_sharematerialid": id,
  112. "channel": "wechat"
  113. }
  114. })
  115. this.setData({
  116. 'detailsData.sharecount': this.data.detailsData.sharecount + 1
  117. })
  118. },
  119. onShareAppMessage() {
  120. const promise = new Promise(resolve => {
  121. let data = this.data.detailsData;
  122. this.updateShareLog(data.sat_sharematerialid);
  123. resolve({
  124. title: data.title,
  125. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
  126. imageUrl: data.cover
  127. })
  128. })
  129. return {
  130. promise
  131. }
  132. },
  133. onShareTimeline: function () {
  134. let data = this.data.detailsData;
  135. return {
  136. title: data.title,
  137. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
  138. imageUrl: data.cover
  139. }
  140. }
  141. })