Browse Source

推广素材

zhaoxiaohai 3 years ago
parent
commit
94d7be99fa

+ 103 - 12
pages/promotional/details.js

@@ -1,11 +1,13 @@
 const _Http = getApp().globalData.http,
     MFT = require("../../utils/matchingFeilType"),
     checkFile = require("../../utils/checkFile");
+import Dialog from '@vant/weapp/dialog/dialog';
 Page({
     /**
      * 页面的初始数据
      */
     data: {
+        sat_sharematerialid: null,
         detailsData: {},
         dataType: 0
     },
@@ -14,24 +16,36 @@ Page({
      * 生命周期函数--监听页面加载
      */
     async onLoad(options) {
+        console.log(options)
+        wx.login({
+            timeout: 0,
+        })
         this.setData({
-            dataType: options.type
+            dataType: options.type,
+            sat_sharematerialid: options.id
         })
+        let isToken = wx.getStorageSync('userMsg').token; //判断是否为无状态进入
         const params = {
             "classname": "saletool.sharematerial.sharematerial",
-            "method": "selectDetail",
+            "method": isToken ? "selectDetail" : "selectDetailNoToken",
             "content": {
                 "sat_sharematerialid": options.id
             }
         };
-        const res = wx.getStorageSync('userMsg').token ? await _Http.basic(params) : await _Http.base(params);
+        const res = isToken ? await _Http.basic(params) : await _Http.base(params);
         if (res.msg != '成功') await _Http.base(params);
         if (res.msg == '成功') {
-            let data = res.data;
-            if (data.attinfos.length) data.attinfos = MFT.fileList(data.attinfos);
+            if (res.data.attinfos.length) res.data.attinfos = MFT.fileList(res.data.attinfos);
             this.setData({
-                detailsData: data
-            })
+                detailsData: res.data
+            });
+            //无状态弹窗
+            if (!isToken) Dialog.confirm({
+                    title: '提示',
+                    message: '帮助完善信息',
+                })
+                .then(this.addNew)
+                .catch(this.addNew)
         } else {
             wx.showToast({
                 title: res.msg,
@@ -39,6 +53,55 @@ Page({
             })
         }
     },
+    /* 新增拉新用户 */
+    async addNew(id) {
+        let name = await new Promise((res, rej) => {
+            wx.getUserProfile({
+                desc: '用于完善用户资料',
+                success: ({
+                    userInfo
+                }) => {
+                    res(userInfo.nickName)
+                },
+                fail: () => {
+                    res('微信用户')
+                }
+            })
+        })
+        let channel = null,
+            that = this;
+        switch (wx.getLaunchOptionsSync().scene) {
+            case 1007:
+                channel = '单人会话分享'
+                break;
+            case 1008:
+                channel = '群聊会话分享'
+                break;
+            case 1154:
+                channel = '朋友圈分享'
+                break;
+            default:
+                channel = '其他方式'
+                break;
+        }
+        wx.login({
+            success(res) {
+                _Http.base({
+                    "classname": "saletool.sharematerial.sharematerial",
+                    "method": "addNew",
+                    "content": {
+                        "sat_sharematerialid": that.data.sat_sharematerialid,
+                        "fname": name,
+                        "channel": channel,
+                        "code": res.code,
+                        "systemclient": "wechatsaletool"
+                    }
+                }, false).then(res => {
+                    console.log("记录分享", res)
+                })
+            }
+        })
+    },
     openFile(e) {
         checkFile.checkFile(e.currentTarget.dataset.item);
     },
@@ -82,11 +145,39 @@ Page({
     onReachBottom() {
 
     },
-
-    /**
-     * 用户点击右上角分享
-     */
+    updateShareLog(id) {
+        _Http.basic({
+            "classname": "saletool.sharematerial.sharematerial",
+            "method": "updateShareLog",
+            "content": {
+                "sat_sharematerialid": id,
+                "channel": "wechat"
+            }
+        })
+        this.setData({
+            'detailsData.sharecount': data.sharecount + 1
+        })
+    },
     onShareAppMessage() {
-
+        const promise = new Promise(resolve => {
+            let data = this.data.detailsData;
+            this.updateShareLog(data.sat_sharematerialid);
+            resolve({
+                title: data.title,
+                path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
+                imageUrl: data.cover
+            })
+        })
+        return {
+            promise
+        }
+    },
+    onShareTimeline: function () {
+        let data = this.data.detailsData;
+        return {
+            title: data.title,
+            path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
+            imageUrl: data.cover
+        }
     }
 })

+ 2 - 1
pages/promotional/details.json

@@ -1,6 +1,7 @@
 {
     "navigationBarTitleText": "素材详情",
     "usingComponents": {
-        "mp-html": "/components/mp-html/index"
+        "mp-html": "/components/mp-html/index",
+        "van-dialog": "@vant/weapp/dialog/index"
     }
 }

+ 5 - 2
pages/promotional/details.wxml

@@ -28,5 +28,8 @@
 <view style="height: 60px;" />
 
 <view class="footer">
-    <van-button custom-class='footer-button' color="var(--warning)">分享</van-button>
-</view>
+    <van-button custom-class='footer-button' open-type='share' color="var(--warning)">分享</van-button>
+</view>
+
+<!-- 弹窗 -->
+<van-dialog id="van-dialog" confirm-button-color='var(--assist)' />

+ 9 - 2
pages/promotional/index.js

@@ -220,10 +220,17 @@ Page({
         const promise = new Promise(resolve => {
             setTimeout(() => {
                 let data = this.selectComponent("#list").data.shareData;
+                _Http.basic({
+                    "classname": "saletool.sharematerial.sharematerial",
+                    "method": "updateShareLog",
+                    "content": {
+                        "sat_sharematerialid": data.sat_sharematerialid,
+                        "channel": "wechat"
+                    }
+                })
                 resolve({
                     title: data.title,
-                    path: `/pages/promotional/details`,
-                    query: `id=${data.sat_sharematerialid}&type=${data.type}`,
+                    path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}`,
                     imageUrl: data.cover
                 })
             }, 50)

+ 6 - 2
pages/promotional/modules/productList.js

@@ -39,10 +39,14 @@ Component({
             })
         },
         handleShare(e) {
+            const {
+                item,
+                index
+            } = e.currentTarget.dataset;
             this.setData({
-                shareData: e.currentTarget.dataset.item
+                shareData: item,
+                [`list[${index}].sharecount`]: item.sharecount + 1
             })
-            console.log(this.data.shareData)
         }
     }
 })

+ 1 - 1
pages/promotional/modules/productList.wxml

@@ -14,7 +14,7 @@
                 </view>
             </view>
         </navigator>
-        <van-button custom-class='share-button' open-type='share' size="large" catchtap="handleShare" data-item="{{item}}">一键分享</van-button>
+        <van-button custom-class='share-button' open-type='share' size="large" catchtap="handleShare" data-item="{{item}}" data-index="{{index}}">一键分享</van-button>
     </view>
 </My_card>
 <My_empty wx:if="{{!list.length}}" />