Browse Source

推广素材

zhaoxiaohai 3 năm trước cách đây
mục cha
commit
d409ed7c2d

+ 6 - 6
pages/promotional/details.js

@@ -5,7 +5,7 @@ Page({
      * 页面的初始数据
      */
     data: {
-        detailsData:{},
+        detailsData: {},
     },
 
     /**
@@ -19,13 +19,13 @@ Page({
                 "sat_sharematerialid": options.id
             }
         }).then(res => {
-            console.log(res)
-            if(res.msg!='成功')return wx.showToast({
-              title: res.data,
-              icon:"none"
+            console.log("详情", res)
+            if (res.msg != '成功') return wx.showToast({
+                title: res.data,
+                icon: "none"
             })
             this.setData({
-                detailsData:res.data[0]
+                detailsData: res.data[0]
             })
         })
     },

+ 10 - 2
pages/promotional/index.js

@@ -20,7 +20,8 @@ Page({
             pageSize: 20,
             pageTotal: 1,
             where: {
-                condition: ""
+                condition: "",
+                sat_sharematerial_classid: ""
             }
         }
     },
@@ -48,7 +49,7 @@ Page({
         })
         if (this.data.content.pageNumber > this.data.content.pageTotal) return;
         let content = this.data.content;
-        if (this.data.activeId) content.where.sat_sharematerial_classid = this.data.activeId;
+        (this.data.activeId != null) ? content.where.sat_sharematerial_classid = this.data.activeId: delete(content.where.sat_sharematerial_classid);
         if (this.data.sort[0]) content.sort = this.data.sort;
         _Http.basic({
             "classname": "saletool.sharematerial.sharematerial",
@@ -123,6 +124,7 @@ Page({
             activeId: this.data.activeId === detail.id ? null : detail.id,
             activeName: this.data.activeName === detail.text ? null : detail.text
         });
+        this.selectComponent('#item').toggle(false);
         this.getList(true);
     },
     onClickNav({
@@ -144,6 +146,12 @@ Page({
         })
     },
 
+    addData() {
+        wx.navigateTo({
+            url: './upload?item=' + JSON.stringify(this.data.items)
+        })
+    },
+
     /**
      * 生命周期函数--监听页面显示
      */

+ 1 - 1
pages/promotional/index.wxml

@@ -1,7 +1,7 @@
 <!-- 搜索 -->
 <van-search value="{{ searchContent }}" bind:change='searchInput' use-action-slot shape="round" bind:clear='searchClear' background="var(--primary)" placeholder="请输入搜索关键词">
     <view class="upload-box" slot='action'>
-        <navigator url="/pages/promotional/upload" class="upload">
+        <navigator url="#" class="upload" bindtap="addData">
             <text class="iconfont icon-a-tuiguangsucaishangchuan1" />
             上传
         </navigator>

+ 128 - 4
pages/promotional/upload.js

@@ -2,7 +2,6 @@ const _Http = getApp().globalData.http,
     MFT = require("../../utils/matchingFeilType"),
     CF = require("../../utils/checkFile");
 Page({
-
     /**
      * 页面的初始数据
      */
@@ -19,22 +18,146 @@ Page({
         detailsData: {},
         editRichText: false, //编辑富文本
         richTextFile: [],
+        items: [],
+        activeName: "",
+        activeId: "",
+        selectShow: false,
+        loading: false
     },
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
+        if (options.item) {
+            this.setData({
+                items: JSON.parse(options.item)
+            })
+        } else {
+            this.selectMenu();
+        };
         _Http.basic({
             "classname": "webmanage.saletool.sharematerial.sharematerial",
             "method": "insertOrUpdate",
             content: this.data.content
         }).then(res => {
             console.log("新增", res)
+            this.setData({
+                detailsData: res.data[0],
+                "content.sat_sharematerialid": res.data[0].sat_sharematerialid
+            })
+        })
+    },
+    submit() {
+        let content = this.data.content;
+        if (content.title == '' || content.sat_sharematerial_classid == 9999) return wx.showToast({
+            title: '请检查素材标题或所属分类',
+            icon: "none"
+        });
+        if (this.data.loading || this.data.detailsData.status == "审核") return wx.showToast({
+            title: '正在提交中',
+            icon: "none"
+        });
+        this.setData({
+            loading: true
+        })
+        _Http.basic({
+            "classname": "webmanage.saletool.sharematerial.sharematerial",
+            "method": "insertOrUpdate",
+            content: this.data.content
+        }).then(res => {
+            if (res.msg != '成功') {
+                wx.showToast({
+                    title: res.data,
+                    icon: "none"
+                });
+                this.setData({
+                    loading: false
+                })
+                return;
+            }
             this.setData({
                 detailsData: res.data[0]
             })
+            _Http.basic({
+                "classname": "webmanage.saletool.sharematerial.sharematerial",
+                "method": "audit",
+                "content": {
+                    "sat_sharematerialid": res.data[0].sat_sharematerialid,
+                    "type": 1
+                }
+            }).then(s => {
+                this.setData({
+                    loading: false
+                })
+                if (res.msg != '成功') return wx.showToast({
+                    title: "保存失败,请重新尝试",
+                    icon: "none"
+                });
+                wx.showToast({
+                    title: "修改成功",
+                });
+                this.setData({
+                    "detailsData.status": "审核"
+                })
+                let pages = getCurrentPages();
+                let prevPage = pages[pages.length - 2];
+                prevPage.getList(true);
+                setTimeout(() => {
+                    wx.navigateBack({
+                        delta: 0,
+                    })
+                }, 300)
+            })
         })
     },
+    openSelect() {
+        this.setData({
+            selectShow: true
+        })
+    },
+    onClose() {
+        this.setData({
+            selectShow: false
+        })
+    },
+    /* 查询分类 */
+    selectMenu(index = 0, res) {
+        if (index == 5) return wx.showToast({
+            title: res.data,
+            icon: "none"
+        });
+        _Http.basic({
+            "classname": "saletool.sharematerial.sharematerial",
+            "method": "select",
+            "content": {
+                "parentid": 0
+            }
+        }).then(res => {
+            if (res.msg != '成功') return this.selectMenu(index + 1, res);
+            let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
+            this.setData({
+                items: JSON.parse(str)
+            });
+        });
+    },
+    /* 切换分类 */
+    onClickItem({
+        detail = {}
+    }) {
+        this.setData({
+            "content.sat_sharematerial_classid": detail.id,
+            activeName: detail.text
+        });
+        this.onClose();
+    },
+    onClickNav({
+        detail = {}
+    }) {
+        this.setData({
+            mainActiveIndex: detail.index || 0,
+        });
+    },
+    /* 上传文件 */
     getFile({
         detail
     }) {
@@ -48,8 +171,9 @@ Page({
                 "attachmentids": detail
             }
         }).then(res => {
+            console.log("上传成功", res)
             if (res.msg != '成功') return wx.showToast({
-                title: res.data,
+                title: res.msg,
                 icon: "none"
             });
             this.setData({
@@ -84,7 +208,6 @@ Page({
             "content.content": detail
         })
     },
-
     deleteFile(e) {
         const {
             item,
@@ -125,7 +248,8 @@ Page({
      * 生命周期函数--监听页面卸载
      */
     onUnload() {
-        if (this.data.detailsData.status == '新建') _Http.basic({
+        if (this.data.detailsData.status != '新建') return;
+        _Http.basic({
             "classname": "webmanage.saletool.sharematerial.sharematerial",
             "method": "delete",
             "content": {

+ 2 - 0
pages/promotional/upload.scss

@@ -1,3 +1,5 @@
+@import '/static/dropdown-switch.wxss';
+
 .box {
     margin-top: 0 !important;
     background: none !important;

+ 9 - 4
pages/promotional/upload.wxml

@@ -4,18 +4,23 @@
 
     <view class="label">素材内容</view>
     <view class="input base" style="display: flex; justify-content: space-between; color: #999;">
-        编辑富文本 <text style="color: #3874F6;" catchtap="openEditRichText">编辑/预览</text>
+        {{content.content==''?'编辑富文本':'浏览富文本'}} <text style="color: #3874F6;" catchtap="openEditRichText">编辑/预览</text>
     </view>
 
     <!-- 富文本 -->
     <My_richText show="{{editRichText}}" bindcallback='getRichText' />
 
     <view class="label">素材分类</view>
-    <navigator class="category base" url="#">
-        <view>请选择素材分类</view>
+    <navigator class="category base" url="#" bindtap="openSelect">
+        <view>{{activeName||"请选择素材分类"}}</view>
         <van-icon name="arrow-down" />
     </navigator>
 
+    <van-popup show="{{ selectShow }}" position="top" bind:close="onClose">
+        <!-- 分类选择 -->
+        <van-tree-select items="{{ items }}" main-active-class='main-active' content-active-class='content-active' main-active-index="{{ mainActiveIndex }}" active-id="{{content.sat_sharematerial_classid}}" bind:click-nav="onClickNav" bind:click-item="onClickItem" />
+    </van-popup>
+
     <view class="label">素材<text>已上传{{detailsData.attinfos.length}}个</text></view>
     <view class="file-list">
         <view class="file-box" wx:for="{{detailsData.attinfos}}" data-item="{{item}}" bindtap="openFile">
@@ -37,6 +42,6 @@
 </My_card>
 
 <view class="but-bom">
-    <van-button type="primary" custom-class='upload'>提交</van-button>
+    <van-button type="primary" custom-class='upload' disabled='{{!content.title}}' loading='{{loading}}' loading-text="保存中..." bindtap="submit">提交</van-button>
 </view>
 <view style="height: 130rpx;" />