浏览代码

推广素材

zhaoxiaohai 3 年之前
父节点
当前提交
61d2d7cf7a
共有 3 个文件被更改,包括 137 次插入70 次删除
  1. 71 49
      pages/promotional/upload.js
  2. 47 10
      pages/promotional/upload.scss
  3. 19 11
      pages/promotional/upload.wxml

+ 71 - 49
pages/promotional/upload.js

@@ -1,4 +1,6 @@
-const _Http = getApp().globalData.http;
+const _Http = getApp().globalData.http,
+    MFT = require("../../utils/matchingFeilType"),
+    CF = require("../../utils/checkFile");
 Page({
 
     /**
@@ -18,7 +20,6 @@ Page({
         editRichText: false, //编辑富文本
         richTextFile: [],
     },
-
     /**
      * 生命周期函数--监听页面加载
      */
@@ -34,22 +35,41 @@ Page({
             })
         })
     },
-
-    titleInput({
+    getFile({
         detail
     }) {
-        this.setData({
-            "content.title": detail.value.trim()
+        _Http.basic({
+            "classname": "system.attachment.Attachment",
+            "method": "createFileLink",
+            "content": {
+                "ownertable": "SAT_SHAREMATERIAL",
+                "ownerid": this.data.detailsData.sat_sharematerialid,
+                "usetype": "default",
+                "attachmentids": detail
+            }
+        }).then(res => {
+            if (res.msg != '成功') return wx.showToast({
+                title: res.data,
+                icon: "none"
+            });
+            this.setData({
+                "detailsData.attinfos": this.data.detailsData.attinfos.concat(MFT.fileList(res.data))
+            })
         })
     },
-
-    notesInput({
+    titleInput({
         detail
     }) {
         this.setData({
-            "content.notes": detail.value.trim()
+            "content.title": detail.value.trim()
         })
     },
+    openFile(e) {
+        const {
+            item
+        } = e.currentTarget.dataset;
+        CF.checkFile(item);
+    },
     /* 打开编辑富文本 */
     openEditRichText() {
         this.setData({
@@ -60,32 +80,47 @@ Page({
     getRichText({
         detail
     }) {
-        console.log("富文本", detail)
         this.setData({
             "content.content": detail
         })
     },
-    /**
-     * 生命周期函数--监听页面初次渲染完成
-     */
-    onReady() {
-
-    },
 
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
+    deleteFile(e) {
+        const {
+            item,
+            index
+        } = e.currentTarget.dataset;
+        const that = this;
+        wx.showModal({
+            title: '提示',
+            content: "是否确认删除该文件?",
+            success: async s => {
+                if (!s.confirm) return;
+                let res = await that.handleDelete([item.linksid]);
+                if (res.msg != '成功') wx.showToast({
+                    title: res.data,
+                });
+                let attinfos = that.data.detailsData.attinfos;
+                attinfos.splice(index, 1);
+                that.setData({
+                    "detailsData.attinfos": attinfos
+                });
+            }
+        })
 
     },
-
-    /**
-     * 生命周期函数--监听页面隐藏
-     */
-    onHide() {
-
+    handleDelete(linksids) {
+        return _Http.basic({
+            "classname": "system.attachment.Attachment",
+            "method": "deleteFileLink",
+            "content": {
+                linksids
+            }
+        }).then(res => {
+            console.log('删除附件', res)
+            return res;
+        })
     },
-
     /**
      * 生命周期函数--监听页面卸载
      */
@@ -98,27 +133,14 @@ Page({
             }
         }).then(res => {
             console.log("删除", res)
-        })
+        });
+        let attinfos = this.data.detailsData.attinfos;
+        if (attinfos.length) {
+            let linksids = [];
+            for (let i = 0; i < attinfos.length; i++) {
+                linksids.push(attinfos[i].linksid)
+            };
+            this.handleDelete(linksids)
+        }
     },
-
-    /**
-     * 页面相关事件处理函数--监听用户下拉动作
-     */
-    onPullDownRefresh() {
-
-    },
-
-    /**
-     * 页面上拉触底事件的处理函数
-     */
-    onReachBottom() {
-
-    },
-
-    /**
-     * 用户点击右上角分享
-     */
-    onShareAppMessage() {
-
-    }
 })

+ 47 - 10
pages/promotional/upload.scss

@@ -28,7 +28,6 @@
         display: inline-block;
         width: 100% !important;
         font-size: 28rpx;
-        color: #BBBBBB;
     }
 }
 
@@ -47,26 +46,64 @@
     padding: 0 20rpx;
 }
 
-.upload {
-    width: 500rpx;
-    height: 90rpx;
-    background: #3874F6 !important;
-    border-radius: 45rpx !important;
-    margin-top: 100rpx;
-}
-
 /* 素材列表 */
 .file-list {
     display: flex;
     justify-content: space-between;
+    flex-wrap: wrap;
     width: 690rpx;
     margin: 20rpx auto 0;
 
     .file-box {
+        position: relative;
+        display: flex;
+        justify-content: center;
+        align-items: center;
         width: 336rpx;
         height: 170rpx;
         border-radius: 8rpx;
-        background-color: red;
         overflow: hidden;
+        box-sizing: border-box;
+        margin-bottom: 20rpx;
+        border: 1rpx solid #CCCCCC;
+
+        .delete {
+            position: absolute;
+            font-size: 40rpx;
+            color: #FF3B30;
+            top: 0rpx;
+            right: 0rpx;
+            z-index: 99999;
+            padding: 0 8rpx 0 5rpx;
+        }
+    }
+
+    .upload-file {
+        color: #999999;
+        text-align: center;
+        font-size: 24rpx;
+        font-family: PingFang SC-Regular, PingFang SC;
+
+        .iconfont {
+            font-size: 44rpx;
+            margin-bottom: 10rpx;
+        }
+    }
+}
+
+.but-bom {
+    position: fixed;
+    width: 750rpx;
+    text-align: center;
+    background: #FFFFFF;
+    box-shadow: 0px -4rpx 16rpx 2rpx rgba(150, 157, 165, 0.16);
+    padding: 20rpx 0;
+    bottom: 0;
+
+    .upload {
+        width: 500rpx;
+        height: 90rpx;
+        background: #3874F6 !important;
+        border-radius: 45rpx !important;
     }
 }

+ 19 - 11
pages/promotional/upload.wxml

@@ -2,33 +2,41 @@
     <view class="label">素材标题</view>
     <input class="input base" bindinput='titleInput' value="{{content.title}}" placeholder-style='font-size: 28rpx;' placeholder='请输入标题' />
 
-    <view class="label">素材备注</view>
-    <input class="input base" bindinput='notesInput' value="{{content.notes}}" placeholder-style='font-size: 28rpx;' placeholder='请输入备注' />
-
     <view class="label">素材内容</view>
     <view class="input base" style="display: flex; justify-content: space-between; color: #999;">
-        请输入内容 <text style="color: #3874F6;" catchtap="openEditRichText">编辑/预览</text>
+        编辑富文本 <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>
         <van-icon name="arrow-down" />
     </navigator>
 
-    <view class="label">素材<text>已上传2个</text></view>
+    <view class="label">素材<text>已上传{{detailsData.attinfos.length}}个</text></view>
     <view class="file-list">
-        <view class="file-box"></view>
-        <My_upload accept='media'>
-            <view class="file-box"></view>
+        <view class="file-box" wx:for="{{detailsData.attinfos}}" data-item="{{item}}" bindtap="openFile">
+            <view class="delete" catchtap="deleteFile" data-item="{{item}}" data-index="{{index}}">
+                <van-icon class="icon" name="clear" />
+            </view>
+            <image wx:if="{{item.fileType=='image'}}" src="{{item.cover}}" mode="aspectFit" />
+            <image wx:elif="{{item.fileType=='video'}}" style="width: 100rpx; height: 100rpx;" src="../../static/image/file/video.png" />
+        </view>
+        <My_upload accept='media' binduploadCallback='getFile'>
+            <navigator url="#" class="file-box upload-file">
+                <view>
+                    <view class="iconfont icon-a-tuiguangsucaishangchuan1"></view>
+                    <view>上传素材</view>
+                </view>
+            </navigator>
         </My_upload>
     </view>
 </My_card>
 
-<view style="width: 100%; text-align: center;">
+<view class="but-bom">
     <van-button type="primary" custom-class='upload'>提交</van-button>
-</view>
+</view>
+<view style="height: 130rpx;" />