details.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. const _Http = getApp().globalData.http,
  2. MFT = require("../../utils/matchingFeilType"),
  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. console.log(wx.getLaunchOptionsSync().scene)
  47. //分享进入
  48. if ([1007, 1008, 1155].includes(wx.getLaunchOptionsSync().scene)) {
  49. wx.setNavigationBarTitle({
  50. title: res.data.title
  51. })
  52. console.log(res.data.title)
  53. this.setData({
  54. "shareData.userid": options.userid,
  55. "shareData.systemclient": "wechatsaletool",
  56. "shareData.sat_sharematerialid": options.id
  57. })
  58. /* popupShow: true */
  59. }
  60. } else {
  61. wx.showToast({
  62. title: res.msg,
  63. icon: "none"
  64. })
  65. }
  66. },
  67. /* 获取手机号 */
  68. getphonenumber({
  69. detail
  70. }) {
  71. this.setData({
  72. "shareData.code_phone": detail.code ? detail.code : '',
  73. addNewCount: this.data.addNewCount + 1
  74. })
  75. this.handleAddNew();
  76. },
  77. /* 新增拉新用户 */
  78. async addNew(gain = true) {
  79. let name = '微信用户',
  80. channel = null,
  81. that = this;
  82. if (gain) name = await new Promise((res, rej) => {
  83. wx.getUserProfile({
  84. desc: '用于完善用户资料',
  85. success: ({
  86. userInfo
  87. }) => {
  88. res(userInfo.nickName)
  89. },
  90. fail: () => {
  91. res('微信用户')
  92. }
  93. })
  94. })
  95. switch (wx.getLaunchOptionsSync().scene) {
  96. case 1007:
  97. channel = '单人会话分享'
  98. break;
  99. case 1008:
  100. channel = '群聊会话分享'
  101. break;
  102. case 1155:
  103. channel = '朋友圈分享'
  104. break;
  105. default:
  106. channel = '其他方式'
  107. break;
  108. };
  109. wx.login({
  110. success(res) {
  111. that.setData({
  112. "shareData.fname": name,
  113. "shareData.channel": channel,
  114. "shareData.code_login": res.code,
  115. addNewCount: that.data.addNewCount + 1
  116. })
  117. that.handleAddNew();
  118. }
  119. });
  120. },
  121. handleAddNew() {
  122. if (this.data.addNewCount != 2) return;
  123. _Http.base({
  124. "classname": "saletool.sharematerial.sharematerial",
  125. "method": "addNew",
  126. "content": this.data.shareData
  127. }, false)
  128. this.setData({
  129. popupShow: false
  130. })
  131. },
  132. openFile(e) {
  133. checkFile.checkFile(e.currentTarget.dataset.item);
  134. },
  135. updateShareLog(id) {
  136. _Http.basic({
  137. "classname": "saletool.sharematerial.sharematerial",
  138. "method": "updateShareLog",
  139. "content": {
  140. "sat_sharematerialid": id,
  141. "channel": "wechat"
  142. }
  143. })
  144. this.setData({
  145. 'detailsData.sharecount': this.data.detailsData.sharecount + 1
  146. })
  147. },
  148. onShareAppMessage() {
  149. const promise = new Promise(resolve => {
  150. let data = this.data.detailsData;
  151. this.updateShareLog(data.sat_sharematerialid);
  152. resolve({
  153. title: data.title,
  154. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}&userid=${wx.getStorageSync('userMsg').userid}`,
  155. imageUrl: data.cover
  156. })
  157. })
  158. return {
  159. promise
  160. }
  161. },
  162. onShareTimeline: function () {
  163. let data = this.data.detailsData;
  164. return {
  165. title: data.title,
  166. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}&userid=${wx.getStorageSync('userMsg').userid}`,
  167. imageUrl: data.cover
  168. }
  169. }
  170. })