details.js 5.4 KB

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