details.js 5.2 KB

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