details.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. console.log(options)
  19. wx.login({
  20. timeout: 0,
  21. })
  22. this.setData({
  23. dataType: options.type,
  24. sat_sharematerialid: options.id
  25. })
  26. let isToken = wx.getStorageSync('userMsg').token; //判断是否为无状态进入
  27. const params = {
  28. "classname": "saletool.sharematerial.sharematerial",
  29. "method": isToken ? "selectDetail" : "selectDetailNoToken",
  30. "content": {
  31. "sat_sharematerialid": options.id
  32. }
  33. };
  34. const res = isToken ? await _Http.basic(params) : await _Http.base(params);
  35. if (res.msg != '成功') await _Http.base(params);
  36. if (res.msg == '成功') {
  37. if (res.data.attinfos.length) res.data.attinfos = MFT.fileList(res.data.attinfos);
  38. this.setData({
  39. detailsData: res.data
  40. });
  41. //无状态弹窗
  42. if (!isToken) Dialog.confirm({
  43. title: '提示',
  44. message: '帮助完善信息',
  45. })
  46. .then(this.addNew)
  47. .catch(this.addNew)
  48. } else {
  49. wx.showToast({
  50. title: res.msg,
  51. icon: "none"
  52. })
  53. }
  54. },
  55. /* 新增拉新用户 */
  56. async addNew(id) {
  57. let name = await new Promise((res, rej) => {
  58. wx.getUserProfile({
  59. desc: '用于完善用户资料',
  60. success: ({
  61. userInfo
  62. }) => {
  63. res(userInfo.nickName)
  64. },
  65. fail: () => {
  66. res('微信用户')
  67. }
  68. })
  69. })
  70. let channel = null,
  71. that = this;
  72. switch (wx.getLaunchOptionsSync().scene) {
  73. case 1007:
  74. channel = '单人会话分享'
  75. break;
  76. case 1008:
  77. channel = '群聊会话分享'
  78. break;
  79. case 1154:
  80. channel = '朋友圈分享'
  81. break;
  82. default:
  83. channel = '其他方式'
  84. break;
  85. }
  86. wx.login({
  87. success(res) {
  88. _Http.base({
  89. "classname": "saletool.sharematerial.sharematerial",
  90. "method": "addNew",
  91. "content": {
  92. "sat_sharematerialid": that.data.sat_sharematerialid,
  93. "fname": name,
  94. "channel": channel,
  95. "code": res.code,
  96. "systemclient": "wechatsaletool"
  97. }
  98. }, false).then(res => {
  99. console.log("记录分享", res)
  100. })
  101. }
  102. })
  103. },
  104. openFile(e) {
  105. checkFile.checkFile(e.currentTarget.dataset.item);
  106. },
  107. /**
  108. * 生命周期函数--监听页面初次渲染完成
  109. */
  110. onReady() {},
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow() {
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload() {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh() {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom() {
  135. },
  136. updateShareLog(id) {
  137. _Http.basic({
  138. "classname": "saletool.sharematerial.sharematerial",
  139. "method": "updateShareLog",
  140. "content": {
  141. "sat_sharematerialid": id,
  142. "channel": "wechat"
  143. }
  144. })
  145. this.setData({
  146. 'detailsData.sharecount': data.sharecount + 1
  147. })
  148. },
  149. onShareAppMessage() {
  150. const promise = new Promise(resolve => {
  151. let data = this.data.detailsData;
  152. this.updateShareLog(data.sat_sharematerialid);
  153. resolve({
  154. title: data.title,
  155. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
  156. imageUrl: data.cover
  157. })
  158. })
  159. return {
  160. promise
  161. }
  162. },
  163. onShareTimeline: function () {
  164. let data = this.data.detailsData;
  165. return {
  166. title: data.title,
  167. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
  168. imageUrl: data.cover
  169. }
  170. }
  171. })