details.js 4.8 KB

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