details.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const _Http = getApp().globalData.http,
  2. MFT = require("../../utils/matchingFeilType"),
  3. checkFile = require("../../utils/checkFile");
  4. import Dialog from '@vant/weapp/dialog/dialog';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. sat_sharematerialid: null,
  11. detailsData: {},
  12. dataType: 0
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. async onLoad(options) {
  18. this.setData({
  19. dataType: options.type,
  20. sat_sharematerialid: options.id
  21. })
  22. let isToken = wx.getStorageSync('userMsg').token; //判断是否为无状态进入
  23. const params = {
  24. "classname": "saletool.sharematerial.sharematerial",
  25. "method": isToken ? "selectDetail" : "selectDetailNoToken",
  26. "content": {
  27. "sat_sharematerialid": options.id
  28. }
  29. };
  30. const res = isToken ? await _Http.basic(params) : await _Http.base(params);
  31. if (res.msg != '成功') await _Http.base(params);
  32. if (res.msg == '成功') {
  33. if (res.data.attinfos.length) res.data.attinfos = MFT.fileList(res.data.attinfos);
  34. this.setData({
  35. detailsData: res.data
  36. });
  37. //无状态弹窗
  38. if (!isToken) Dialog.confirm({
  39. title: '提示',
  40. message: '帮助完善信息',
  41. })
  42. .then(this.addNew)
  43. .catch(this.addNew)
  44. } else {
  45. wx.showToast({
  46. title: res.msg,
  47. icon: "none"
  48. })
  49. }
  50. },
  51. /* 新增拉新用户 */
  52. async addNew(id) {
  53. let name = await new Promise((res, rej) => {
  54. wx.getUserProfile({
  55. desc: '用于完善用户资料',
  56. success: ({
  57. userInfo
  58. }) => {
  59. res(userInfo.nickName)
  60. },
  61. fail: () => {
  62. res('微信用户')
  63. }
  64. })
  65. })
  66. let channel = null,
  67. that = this;
  68. switch (wx.getLaunchOptionsSync().scene) {
  69. case 1007:
  70. channel = '单人会话分享'
  71. break;
  72. case 1008:
  73. channel = '群聊会话分享'
  74. break;
  75. case 1154:
  76. channel = '朋友圈分享'
  77. break;
  78. default:
  79. channel = '其他方式'
  80. break;
  81. }
  82. wx.login({
  83. success(res) {
  84. _Http.base({
  85. "classname": "saletool.sharematerial.sharematerial",
  86. "method": "addNew",
  87. "content": {
  88. "sat_sharematerialid": that.data.sat_sharematerialid,
  89. "fname": name,
  90. "channel": channel,
  91. "code": res.code,
  92. "systemclient": "wechatsaletool"
  93. }
  94. }, false).then(res => {
  95. console.log("记录分享", res)
  96. })
  97. }
  98. })
  99. },
  100. openFile(e) {
  101. checkFile.checkFile(e.currentTarget.dataset.item);
  102. },
  103. updateShareLog(id) {
  104. _Http.basic({
  105. "classname": "saletool.sharematerial.sharematerial",
  106. "method": "updateShareLog",
  107. "content": {
  108. "sat_sharematerialid": id,
  109. "channel": "wechat"
  110. }
  111. })
  112. this.setData({
  113. 'detailsData.sharecount': this.data.detailsData.sharecount + 1
  114. })
  115. },
  116. onShareAppMessage() {
  117. const promise = new Promise(resolve => {
  118. let data = this.data.detailsData;
  119. this.updateShareLog(data.sat_sharematerialid);
  120. resolve({
  121. title: data.title,
  122. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
  123. imageUrl: data.cover
  124. })
  125. })
  126. return {
  127. promise
  128. }
  129. },
  130. onShareTimeline: function () {
  131. let data = this.data.detailsData;
  132. return {
  133. title: data.title,
  134. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
  135. imageUrl: data.cover
  136. }
  137. }
  138. })