details.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. console.log(options)
  20. this.setData({
  21. dataType: options.type,
  22. sat_sharematerialid: options.id
  23. })
  24. let isToken = wx.getStorageSync('userMsg').token; //判断是否为无状态进入
  25. const params = {
  26. "classname": "saletool.sharematerial.sharematerial",
  27. "method": isToken ? "selectDetail" : "selectDetailNoToken",
  28. "content": {
  29. "sat_sharematerialid": options.id
  30. }
  31. };
  32. const res = isToken ? await _Http.basic(params) : await _Http.base(params);
  33. if (res.msg != '成功') res = await _Http.base(params);
  34. if (!res.data.attinfos) {
  35. wx.navigateBack()
  36. wx.showToast({
  37. title: '该素材已被删除',
  38. icon: "none"
  39. })
  40. return
  41. }
  42. if (res.msg == '成功') {
  43. if (res.data.attinfos.length) res.data.attinfos = MFT.fileList(res.data.attinfos);
  44. this.setData({
  45. detailsData: res.data
  46. });
  47. console.log(wx.getLaunchOptionsSync().scene)
  48. //分享进入
  49. if ([1007, 1008, 1155].includes(wx.getLaunchOptionsSync().scene)) {
  50. wx.setNavigationBarTitle({
  51. title: res.data.title
  52. })
  53. console.log(res.data.title)
  54. this.setData({
  55. "shareData.userid": options.userid,
  56. "shareData.systemclient": "wechatsaletool",
  57. "shareData.sat_sharematerialid": options.id
  58. })
  59. /* popupShow: true */
  60. }
  61. } else {
  62. wx.showToast({
  63. title: res.msg,
  64. icon: "none"
  65. })
  66. }
  67. },
  68. /* 获取手机号 */
  69. getphonenumber({
  70. detail
  71. }) {
  72. this.setData({
  73. "shareData.code_phone": detail.code ? detail.code : '',
  74. addNewCount: this.data.addNewCount + 1
  75. })
  76. this.handleAddNew();
  77. },
  78. /* 新增拉新用户 */
  79. async addNew(gain = true) {
  80. let name = '微信用户',
  81. channel = null,
  82. that = this;
  83. if (gain) name = await new Promise((res, rej) => {
  84. wx.getUserProfile({
  85. desc: '用于完善用户资料',
  86. success: ({
  87. userInfo
  88. }) => {
  89. res(userInfo.nickName)
  90. },
  91. fail: () => {
  92. res('微信用户')
  93. }
  94. })
  95. })
  96. switch (wx.getLaunchOptionsSync().scene) {
  97. case 1007:
  98. channel = '单人会话分享'
  99. break;
  100. case 1008:
  101. channel = '群聊会话分享'
  102. break;
  103. case 1155:
  104. channel = '朋友圈分享'
  105. break;
  106. default:
  107. channel = '其他方式'
  108. break;
  109. };
  110. wx.login({
  111. success(res) {
  112. that.setData({
  113. "shareData.fname": name,
  114. "shareData.channel": channel,
  115. "shareData.code_login": res.code,
  116. addNewCount: that.data.addNewCount + 1
  117. })
  118. that.handleAddNew();
  119. }
  120. });
  121. },
  122. handleAddNew() {
  123. if (this.data.addNewCount != 2) return;
  124. _Http.base({
  125. "classname": "saletool.sharematerial.sharematerial",
  126. "method": "addNew",
  127. "content": this.data.shareData
  128. }, false)
  129. this.setData({
  130. popupShow: false
  131. })
  132. },
  133. openFile(e) {
  134. checkFile.checkFile(e.currentTarget.dataset.item);
  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': this.data.detailsData.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}&userid=${wx.getStorageSync('userMsg').userid}`,
  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}&userid=${wx.getStorageSync('userMsg').userid}`,
  168. imageUrl: data.cover
  169. }
  170. }
  171. })