Browse Source

上传图片逻辑修改

zhaoxiaohai 4 years ago
parent
commit
e6a8a2efd3

+ 1 - 1
components/My_MultipleChoice/index.js

@@ -37,7 +37,7 @@ Component({
                     let checked = false;
                     if (res.data[i] == this.data.pitchOnItem) checked = true;
                     dataList.push({
-                        value: res.data[i],
+                        value: res.data[i].ftype,
                         index: i,
                         checked: checked
                     })

+ 145 - 128
components/My_UploadFiles/index.js

@@ -11,10 +11,6 @@ Component({
         fileList: {
             type: Array
         },
-        /* 父页面传递图片 */
-        attinfos: {
-            type: Object
-        },
         /* 上传类型 Logo-品牌logo userImage-用户头像  productImage-产品图片 SupplyAndDemand-供需*/
         upType: {
             type: String
@@ -47,10 +43,6 @@ Component({
         imageChange: {
             type: Function
         },
-        /* 产品ID */
-        tagents_productid: {
-            type: String
-        },
         /* 图片尺寸 */
         previewSize: {
             type: String,
@@ -61,16 +53,47 @@ Component({
             type: Boolean,
             value: false
         },
+        /* 供需产品id */
         tsupplyanddemand: {
             type: Number
         }
     },
+    /* 生命周期 */
+    lifetimes: {
+        attached: function () {
+            // 图片临时 id = 数字类型的 userid + 去掉前五位的时间戳
+            const forTheTimeId = parseInt(wx.getStorageSync('userData').userid + (Date.parse(new Date()).toString().slice(5)));
+            this.setData({
+                forTheTimeId
+            })
+        },
+        detached: function () {
+            // 在组件实例被从页面节点树移除时执行
+            if (this.data.ExitTheDelete) return;
+            const data = this.data.fileList.filter((value) => value.ownerid == 0);
+            for (let i = 0; i < data.length; i++) {
+                _Http.basic({
+                    "accesstoken": wx.getStorageSync('userData').token,
+                    "classname": "system.system.docManage",
+                    "method": "deleteDoc",
+                    "content": {
+                        "ownertable": data[i].ownertable,
+                        "ownerid": data[i].ownerid,
+                        "tattachmentid": data[i].tattachmentid
+                    }
+                }).then((res) => {
+                    if (res.msg != "成功") return;
+                    console.log("附件删除成功")
+                })
+            };
+        },
+    },
 
     /**
      * 组件的初始数据
      */
     data: {
-
+        ExitTheDelete: false,
     },
 
     /**
@@ -79,7 +102,6 @@ Component({
     methods: {
         /* 文件校验 */
         beforeRead(event) {
-            console.log("文件校验")
             const {
                 file,
                 callback
@@ -110,20 +132,81 @@ Component({
         /* 上传图片 */
         afterRead(event) {
             // 初始化数据
-            var that = this;
-            const {
-                file
-            } = event.detail;
+            let that = this,
+                data = this.requestType(event.detail.file);
+            //发送请求
+            wx.getFileSystemManager().readFile({
+                filePath: event.detail.file.url,
+                success: result => {
+                    //返回临时文件路径
+                    const fileData = result.data
+                    _Http.basic(data).then(res => {
+                        that.uploadFile(res, fileData)
+                    }).catch(err => {})
+                },
+                fail: console.error
+            })
+        },
+        /* 上传成功反馈 */
+        uploadFile(res, data) {
+            var that = this
+            wx.request({
+                url: res.data.obsuploadurl,
+                method: "PUT",
+                data: data,
+                header: {
+                    'content-type': 'application/octet-stream' // 默认值
+                },
+                success() {
+                    _Http.basic({
+                        "accesstoken": wx.getStorageSync('userData').token,
+                        "classname": "system.system.docManage",
+                        "method": "uploadSuccess",
+                        "content": {
+                            "obsfilename": res.data.obsfilename
+                        }
+                    }).then(res => {
+                        console.log(res)
+                        if (res.msg != "成功") return;
+                        let fileList = that.data.fileList;
+                        for (let i = 0; i < res.data.length; i++) {
+                            let arr = {
+                                url: res.data[i].fobsurl,
+                                ownerid: res.data[i].ownerid,
+                                tattachmentid: res.data[i].tattachmentid,
+                                ownertable: res.data[i].ownertable,
+                                fdocument: res.data[i].fdocument,
+                            }
+                            fileList.push(arr)
+                        };
+                        // 用户头像 先删除 在修改
+                        if (that.data.upType == "userImage" && fileList.length >= 2) {
+                            that.dleeteDealWith(0);
+                        }
+                        that.setData({
+                            fileList
+                        });
+                        /* 返回数据 */
+                        that.triggerEvent("imageChange", {
+                            fileList
+                        })
+                    }).catch(err => {
+                        console.log(err)
+                    })
+                }
+            })
+        },
+        /* 请求类型 */
+        requestType(file) {
             //获取文件后缀
             var index = file.url.lastIndexOf(".");
             var ext = file.url.substr(index + 1);
             //文件名称
             const timestamp = Date.parse(new Date());;
-            let data = {};
             //不同类型图片数据
             if (this.data.upType == 'Logo') {
                 //logo上传
-                data = {
+                return {
                     "accesstoken": wx.getStorageSync('userData').token,
                     "classname": "system.system.docManage",
                     "method": "getFileName",
@@ -137,7 +220,7 @@ Component({
                 }
             } else if (this.data.upType == 'userImage') {
                 //头像上传
-                data = {
+                return {
                     "accesstoken": wx.getStorageSync('userData').token,
                     "classname": "system.system.docManage",
                     "method": "getFileName",
@@ -151,98 +234,33 @@ Component({
                 }
             } else if (this.data.upType == 'productImage') {
                 //产品图片上传
-                data = {
+                return {
                     "accesstoken": wx.getStorageSync('userData').token,
                     "classname": "system.system.docManage",
                     "method": "getFileName",
                     "content": {
                         "filename": timestamp,
                         "filetype": ext,
-                        "ownertable": "tagents_product",
-                        "ownerid": this.data.tagents_productid,
+                        "ownertable": this.data.forTheTimeId,
+                        "ownerid": 0,
                         "ftype": "default"
                     }
                 }
             } else if (this.data.upType == "SupplyAndDemand") {
                 //供需附件上传
-                data = {
+                return {
                     "accesstoken": wx.getStorageSync('userData').token,
                     "classname": "system.system.docManage",
                     "method": "getFileName",
                     "content": {
                         "filename": timestamp,
                         "filetype": ext,
-                        "ownertable": "tsupplyanddemand",
-                        "ownerid": this.data.tsupplyanddemand,
+                        "ownertable": this.data.forTheTimeId,
+                        "ownerid": 0,
                         "ftype": "default"
                     }
                 }
             }
-            //发送请求
-            wx.getFileSystemManager().readFile({
-                filePath: file.url,
-                success: result => {
-                    //返回临时文件路径
-                    const fileData = result.data
-                    _Http.basic(data).then(res => {
-                        that.uploadFile(res, fileData)
-                    }).catch(err => {})
-                },
-                fail: console.error
-            })
-        },
-        /* 上传成功反馈 */
-        uploadFile(res, data) {
-            var that = this
-            wx.request({
-                url: res.data.obsuploadurl,
-                method: "PUT",
-                data: data,
-                header: {
-                    'content-type': 'application/octet-stream' // 默认值
-                },
-                success() {
-                    _Http.basic({
-                        "accesstoken": wx.getStorageSync('userData').token,
-                        "classname": "system.system.docManage",
-                        "method": "uploadSuccess",
-                        "content": {
-                            "obsfilename": res.data.obsfilename
-                        }
-                    }).then(res => {
-                        console.log(res)
-                        if (res.msg != "成功") return;
-                        let fileList = that.data.fileList;
-                        for (let i = 0; i < res.data.length; i++) {
-                            let arr = {
-                                url: res.data[i].fobsurl,
-                                ownerid: res.data[i].ownerid,
-                                tattachmentid: res.data[i].tattachmentid
-                            }
-                            fileList.push(arr)
-                        };
-                        if (that.data.upType != "userImage") {
-                            //普通返回
-                            that.setData({
-                                fileList
-                            });
-                            that.triggerEvent("imageChange", {
-                                fileList
-                            })
-                        } else {
-                            // 需要返回到父组件中 userImage
-                            if (that.data.attinfos != null) {
-                                that.dleeteDealWith();
-                            }
-                            that.triggerEvent("imageChange", {
-                                fileList
-                            })
-                        }
-                    }).catch(err => {
-                        console.log(err)
-                    })
-                }
-            })
         },
         /* 删除文件 */
         imagesDelete(e) {
@@ -261,55 +279,54 @@ Component({
                 }
             })
         },
+        /* 保存退出,修改附件位置 */
+        saveTheChanges(obj) {
+            const data = this.data.fileList.filter((value) => value.ownerid == 0);
+            this.setData({
+                ExitTheDelete: true
+            })
+            for (let i = 0; i < data.length; i++) {
+                obj.tattachmentid = data[i].tattachmentid;
+                _Http.basic({
+                    "accesstoken": wx.getStorageSync('userData').token,
+                    "classname": "system.system.docManage",
+                    "method": "changeFilesData",
+                    "content": {
+                        "files": [{
+                            "tattachmentid": data[i].tattachmentid,
+                            "fdocument": data[i].fdocument,
+                            "ownertable": obj.ownertable,
+                            "ownerid": obj.ownerid
+                        }]
+                    }
+                }).then(res => {
+                    console.log(res)
+                })
+            }
+        },
         /* 处理删除 */
         dleeteDealWith(index) {
             const that = this;
-            let ownertable = '';
-            if (that.data.upType == 'Logo') {
-                //品牌logo
-                ownertable = "tagents"
-            } else if (that.data.upType == 'userImage') {
-                //用户头像
-                ownertable = "tenterprise_users"
-            } else if (that.data.upType == "SupplyAndDemand") {
-                ownertable = "tsupplyanddemand"
-            };
-            let content = {}
-            if (that.data.upType != "userImage") {
-                //图片在本页面
-                content = {
-                    "ownertable": ownertable,
-                    "ownerid": that.data.fileList[index].ownerid,
-                    "tattachmentid": that.data.fileList[index].tattachmentid
-                }
-            } else {
-                //图片在父组件
-                content = {
-                    "ownertable": ownertable,
-                    "ownerid": that.data.attinfos.ownerid,
-                    "tattachmentid": that.data.attinfos.tattachmentid
-                }
-            }
+            const type = that.data.fileList[index];
             _Http.basic({
                 "accesstoken": wx.getStorageSync('userData').token,
                 "classname": "system.system.docManage",
                 "method": "deleteDoc",
-                "content": content
+                "content": {
+                    "ownertable": type.ownertable,
+                    "ownerid": type.ownerid,
+                    "tattachmentid": type.tattachmentid
+                }
             }).then(s => {
                 if (s.msg != '成功') return;
-                if (that.data.upType != "userImage") {
-                    let fileList = that.data.fileList;
-                    fileList.splice(index - 1, 1);
-                    // 需要返回到父组件中 userImage
-                    that.triggerEvent("imageChange", {
-                        fileList
-                    })
-                    that.setData({
-                        fileList
-                    })
-                } else {
-                    console.log("删除成功")
-                }
+                let fileList = that.data.fileList;
+                fileList.splice(index, 1);
+                that.triggerEvent("imageChange", {
+                    fileList
+                })
+                that.setData({
+                    fileList
+                })
                 console.log("删除成功")
             })
         },

+ 1 - 1
components/My_UploadFiles/index.wxml

@@ -1,4 +1,4 @@
-<van-uploader file-list="{{ fileList }}" disabled="{{fisadministrator}}" preview-size='{{previewSize}}' max-count="{{maxCount}}" bind:after-read="afterRead" deletable="{{ true }}" use-before-read bind:before-read="beforeRead" bind:delete="imagesDelete">
+<van-uploader file-list="{{ upType!='userImage'?fileList:'' }}" disabled="{{fisadministrator}}" preview-size='{{previewSize}}' max-count="{{maxCount}}" bind:after-read="afterRead" deletable="{{ true }}" use-before-read bind:before-read="beforeRead" bind:delete="imagesDelete">
     <!-- 默认样式 -->
     <view wx:if="{{UploadShow}}" style="height: 100%; display: flex; align-items: center;">
         <view class="upImage_ltem">

+ 35 - 2
pages/announceDemand/index.js

@@ -34,9 +34,35 @@ Page({
     onLoad: function (options) {
         this.setTime()
         if (options.data != undefined) {
-            console.log("修改返回数据")
+            const data = JSON.parse(options.data);
+            let attinfos = [];
+            for (let i = 0; i < data.attinfos.length; i++) {
+                let arr = {
+                    url: data.attinfos[i].fobsurl,
+                    ownerid: data.attinfos[i].ownerid,
+                    tattachmentid: data.attinfos[i].tattachmentid,
+                    ownertable: data.attinfos[i].ownertable,
+                    fdocument: data.attinfos[i].fdocument
+                }
+                attinfos.push(arr)
+            };
+            this.setData({
+                ftype: data.ftype, //供需类型
+                ftitle: data.ftitle, //供需标题
+                fcontent: data.fcontent, //需求内容	
+                fenddate: data.fenddate, //截止日期
+                attinfos, //附件列表
+                tsupplyanddemandid: data.tsupplyanddemandid, //ID 0为新增
+            })
         }
     },
+    /* 添加图片 */
+    imageChange(data) {
+        this.setData({
+            attinfos: data.detail.fileList
+        })
+    },
+    /* 设置下架时间范围 */
     setTime() {
         this.setData({
             maxDate: Date.parse(new Date()) + 1000 * 60 * 60 * 24 * 31,
@@ -101,7 +127,14 @@ Page({
                 "fissupply": 0
             }
         }).then(res => {
-            if (res.msg != "成功") return
+            if (res.msg != "成功") return;
+            console.log(res)
+            let content = {
+                ownerid: res.data[0].tsupplyanddemandid,
+                ownertable: "tsupplyanddemand",
+                tattachmentid: 0
+            };
+            this.selectComponent("#UploadFiles").saveTheChanges(content);
             wx.showToast({
                 title: '保存成功',
             })

+ 1 - 6
pages/announceDemand/index.wxml

@@ -4,24 +4,19 @@
             <view style="width: 100%; height: 100%; z-index: 999; position: absolute;" bindtap="showPop"></view>
             <van-field autosize model:value="{{ ftype }}" data-name="ftype" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.ftype}}" input-class="input-class" placeholder="点击设置" border="{{ false }}" />
         </My_GreyRectangleForm>
-
         <My_GreyRectangleForm title="需求标题" required>
             <van-field autosize model:value="{{ ftitle }}" data-name="ftitle" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.ftitle}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
         </My_GreyRectangleForm>
-
         <My_GreyRectangleForm title="需求内容" required>
             <van-field autosize model:value="{{ fcontent }}" data-name="fcontent" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.fcontent}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
         </My_GreyRectangleForm>
-
         <My_GreyRectangleForm title="产品图">
-            <My_UploadFiles fileList="{{attinfos}}" upType="SupplyAndDemand" UploadShow="{{true}}" maxCount="3" tsupplyanddemand="{{tsupplyanddemand}}" previewSize="65px"></My_UploadFiles>
+            <My_UploadFiles id="UploadFiles" fileList="{{attinfos}}" upType="SupplyAndDemand" UploadShow="{{true}}" maxCount="3" tsupplyanddemand="{{tsupplyanddemand}}" previewSize="65px" bindimageChange="imageChange"></My_UploadFiles>
         </My_GreyRectangleForm>
-
         <My_GreyRectangleForm title="下架日期">
             <view style="width: 100%; height: 100%; z-index: 999; position: absolute;" bindtap="setDate"></view>
             <van-field autosize model:value="{{ fenddate }}" input-class="input-class" placeholder="点击设置" border="{{ false }}" />
         </My_GreyRectangleForm>
-
     </view>
 </My_GeneralTemplate>
 

+ 12 - 2
pages/login/index.js

@@ -13,8 +13,9 @@ Page({
      */
     data: {
         popups: false, //弹出层控制
-        pageType: "login", //页面类型 login 手机登录页面 signin 注册页面 firm 商户认证 changeUser 切换用户
+        pageType: "firm", //页面类型 login 手机登录页面 signin 注册页面 firm 商户认证 changeUser 切换用户
         butText: "", //按钮文本
+        attinfos: [], //logo
         /* 登录 */
         fphonenumber: 17757394388, //手机号码
         password: null, //验证码
@@ -186,7 +187,7 @@ Page({
             verify = false;
         };
         // 验证图片是否上传
-        if (!this.selectComponent('#loadFiles').VerifyThere()) {
+        if (!this.selectComponent('#UploadFiles').VerifyThere()) {
             errTips.logoTips = true;
             verify = false;
         }
@@ -215,6 +216,12 @@ Page({
         })
         return verify;
     },
+    /* 添加图片 */
+    imageChange(data) {
+        this.setData({
+            attinfos: data.detail.fileList
+        })
+    },
     /* 商户认证提交表单 */
     merchantsToSubmit() {
         // 验证
@@ -318,6 +325,9 @@ Page({
             "phonenumber": this.data.fphonenumber
         }).then(res => {
             console.log(res)
+            this.setData({
+                password: res.msg.substring(res.msg.length - 6)
+            })
             wx.showToast({
                 title: res.msg.substring(res.msg.length - 6),
                 icon: "none",

+ 1 - 1
pages/login/index.wxml

@@ -61,7 +61,7 @@
             <!-- 品牌LOGO -->
             <view class="input_text_title">品牌LOGO<text>*</text></view>
             <view class="box_mar_bot">
-                <My_UploadFiles id="loadFiles" UploadShow="{{true}}" upType="Logo" maxCount='1' logoTips="{{errTips.logoTips}}" size="65px" Tips="请上传logo图片"></My_UploadFiles>
+                <My_UploadFiles id="UploadFiles" fileList="{{attinfos}}" UploadShow="{{true}}" upType="Logo" maxCount='1' logoTips="{{errTips.logoTips}}" size="65px" Tips="请上传logo图片" bindimageChange="imageChange"></My_UploadFiles>
             </view>
             <!-- 经营类目 -->
             <view style="position: relative; margin-bottom: 15rpx;">

+ 22 - 14
pages/productManagement/change.js

@@ -26,35 +26,30 @@ Page({
             showSaleprod: false,
         }
     },
-
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
         if (options.data) {
             const data = JSON.parse(options.data)
-            let imageList = []
             console.log(data)
-            /* 格式化图片列表 */
+            let attinfos = [];
             for (let i = 0; i < data.attinfos.length; i++) {
-                let obj = {
+                let arr = {
                     url: data.attinfos[i].fobsurl,
                     ownerid: data.attinfos[i].ownerid,
-                    tattachmentid: data.attinfos[i].tattachmentid
+                    tattachmentid: data.attinfos[i].tattachmentid,
+                    ownertable: data.attinfos[i].ownertable,
+                    fdocument: data.attinfos[i].fdocument
                 }
-                imageList.push(obj)
+                attinfos.push(arr)
             };
             /* 是否上架 */
-            if (data.fisonsale == 1) {
-                this.setData({
-                    checked: true
-                })
-            }
+            const checked = (data.fisonsale == 1) ? true : false
             let showSaleprod = "",
                 ftag = data.ftag
             /* 空标签转换为数组格式 */
             if (data.ftag == null || data.ftag == '') {
-                console.log(21)
                 ftag = []
             } else {
                 /* 字符串数组转换数组 */
@@ -66,12 +61,13 @@ Page({
             this.setData({
                 fprodname: data.fprodname, //产品名称
                 fprodnum: data.fprodnum, //产品编码
-                attinfos: imageList, //附件列表
+                attinfos, //附件列表
                 fintroduction: data.fintroduction, //产品说明
                 fisonsale: data.fisonsale, //是否上架
                 ftag: ftag, //产品标签
                 tagents_productid: data.tagents_productid, //识别产品ID
                 showSaleprod, // 显示标签
+                checked, //是否上架
             });
         }
     },
@@ -81,6 +77,12 @@ Page({
      */
     onReady: function () {
 
+    },
+    /* 添加图片 */
+    imageChange(data) {
+        this.setData({
+            attinfos: data.detail.fileList
+        })
     },
     /* 上架开关 */
     switchChange() {
@@ -89,6 +91,7 @@ Page({
             checked
         });
         const fisonsale = (checked) ? 1 : 0;
+        if (this.data.tagents_productid == 0) return;
         _Http.basic({
             "accesstoken": wx.getStorageSync('userData').token,
             "classname": "customer.products.products",
@@ -148,7 +151,12 @@ Page({
         }).then(res => {
             console.log(res)
             if (res.msg != "成功") return;
-            //非新增项目
+            let content = {
+                ownerid: res.data[0].tagents_productid,
+                ownertable: "tagents_product",
+                tattachmentid: 0
+            };
+            this.selectComponent("#UploadFiles").saveTheChanges(content);
             wx.showToast({
                 title: '保存成功',
             })

+ 1 - 1
pages/productManagement/change.wxml

@@ -9,7 +9,7 @@
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="产品图" required>
-            <My_UploadFiles fileList="{{attinfos}}" upType="productImage" UploadShow="{{true}}" maxCount="3" tagents_productid="{{tagents_productid}}" previewSize="65px"></My_UploadFiles>
+            <My_UploadFiles id="UploadFiles" fileList="{{attinfos}}" upType="productImage" UploadShow="{{true}}" maxCount="3" tagents_productid="{{tagents_productid}}" previewSize="65px" bindimageChange="imageChange"></My_UploadFiles>
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="标签">

+ 19 - 9
pages/storeMessage/index.js

@@ -73,6 +73,12 @@ Page({
             };
         })
     },
+    /* 添加图片 */
+    imageChange(data) {
+        this.setData({
+            attinfos: data.detail.fileList
+        })
+    },
     /* 选择类目回调 */
     saleprodChange(arr) {
         let {
@@ -89,14 +95,18 @@ Page({
     },
     /* 返回数据 */
     returnData(data) {
-        let imageData = [];
-        if (data.attinfos.length >= 1) {
-            imageData = [{
-                url: data.attinfos[0].fobsurl,
-                ownerid: data.attinfos[0].ownerid,
-                tattachmentid: data.attinfos[0].tattachmentid
-            }];
-        }
+        let attinfos = [];
+        for (let i = 0; i < data.attinfos.length; i++) {
+            let arr = {
+                url: data.attinfos[i].fobsurl,
+                ownerid: data.attinfos[i].ownerid,
+                tattachmentid: data.attinfos[i].tattachmentid,
+                ownertable: data.attinfos[i].ownertable,
+                fdocument: data.attinfos[i].fdocument
+            }
+            attinfos.push(arr)
+        };
+
         //格式化经营类目
         if (data.saleprodclass.length >= 1) {
             this.saleprodChange({
@@ -112,7 +122,7 @@ Page({
             fagentname: data.fagentname,
             faddress: data.faddress,
             fdutyparagraph: data.fdutyparagraph,
-            attinfos: imageData,
+            attinfos,
             isLogo: imageData
         })
     },

+ 1 - 1
pages/storeMessage/index.wxml

@@ -6,7 +6,7 @@
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="品牌LOGO" required>
-            <My_UploadFiles id="loadFiles" UploadShow="{{true}}" fisadministrator="{{!fisadministrator}}" fileList="{{attinfos}}" bind:imageChange="logoChange" previewSize="65px" upType="Logo" maxCount='1' Tips="请上传logo图片"></My_UploadFiles>
+            <My_UploadFiles id="UploadFiles" UploadShow="{{true}}" fisadministrator="{{!fisadministrator}}" fileList="{{attinfos}}" bind:imageChange="logoChange" previewSize="65px" upType="Logo" maxCount='1' Tips="请上传logo图片" bindimageChange="imageChange"></My_UploadFiles>
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="经营类目" required>

+ 96 - 17
pages/tabbar-pages/supplyAndDemand/index.js

@@ -12,6 +12,11 @@ Page({
         pageNumber: 1, //获取第几页
         pageTotal: 2, //全部分页数量
         active: 0, //tabs 选中下标
+        ftypeList: [], //分类列表
+        ftype: "", //当前查询分类
+        /* 供需列表 */
+        productList: [],
+        //轮播图列表
         swiperBannerList: [{
             id: "001",
             url: "/static/userImage.png",
@@ -24,7 +29,7 @@ Page({
             id: "003",
             url: "/static/userImage.png",
             src: ''
-        }], //轮播图列表
+        }],
         /* 宫格列表 */
         gridList: [{
             id: '001',
@@ -82,13 +87,55 @@ Page({
      */
     onShow: function () {
         this.getTabBar().init();
-        //获取所有信息
-        this.getSupplyAndDemand();
+        //获取列表
+        this.getList();
+    },
+    /* tabs切换接口 */
+    getList() {
+        if (this.data.active == 0) return this.getSupplyAndDemand();
+        if (this.data.active == 2) return this.myNeed();
+    },
+    /* 供需下架 */
+    soldOut(e) {
+        const {
+            index
+        } = e.target.dataset
+        console.log(index)
+        _Http.basic({
+            "accesstoken": wx.getStorageSync('userData').token,
+            "classname": "customer.supplyanddemand.supplyanddemand",
+            "method": "deletesupplyanddemand",
+            "content": {
+                "tsupplyanddemandid": this.data.productList[index].tsupplyanddemandid
+            }
+        }).then(res => {
+            console.log(res)
+            if (res.msg != "成功") {
+                wx.showToast({
+                    title: res.data,
+                    icon: "error"
+                })
+            } else {
+                console.log("删除产品")
+            }
+        })
     },
     /* 获取供需列表 */
-    getSupplyAndDemand() {
-        let ftype = "",
-            condition = ""
+    getSupplyAndDemand(fstatus) {
+        let condition = "";
+        let where = {
+            "condition": condition, //模糊搜索
+            "ftype": this.data.ftype, //数据类型
+            "fissupply": "" // 0需 1供
+        };
+        if (fstatus) {
+            where = {
+                "condition": condition, //模糊搜索
+                "ftype": this.data.ftype, //数据类型
+                "fissupply": 0, // 0需 1供
+                "fstatus": "对接中"
+            }
+        };
         _Http.basic({
             "accesstoken": wx.getStorageSync('userData').token,
             "classname": "customer.supplyanddemand.supplyanddemand",
@@ -97,27 +144,34 @@ Page({
                 "getdatafromdbanyway": true,
                 "pageNumber": 1,
                 "pageSize": 20,
-                "where": {
-                    "condition": condition, //模糊搜索
-                    "ftype": ftype, //数据类型
-                    "fissupply": "" // 0需 1供
-                }
+                "where": where
             }
         }).then(res => {
             console.log(res)
+            if (res.msg != "成功") return;
+            //替换或拼接
+            if (this.data.pageNumber == 1) {
+                //第一页直接替换list
+                this.setData({
+                    productList: res.data
+                })
+            } else {
+                //第二页开始拼接列表
+                let productList = this.data.productList.concat(res.data);
+                this.setData({
+                    productList
+                })
+            }
         })
     },
-    /* tabs切换 */
+    /* tabs */
     tabsChange(even) {
-        const {
-            title
-        } = even.detail;
         this.setData({
             active: even.detail.index
         })
         /* 初始化分页 */
         this.InitializeDataPaging();
-        if (title == '我的需求') return this.myNeed();
+        this.getList();
     },
     /* 我的需求 */
     myNeed() {
@@ -139,9 +193,34 @@ Page({
             }
         }).then(res => {
             console.log(res);
+            if (res.msg != "成功") return;
+            //替换或拼接
+            if (this.data.pageNumber == 1) {
+                //第一页直接替换list
+                this.setData({
+                    productList: res.data
+                })
+            } else {
+                //第二页开始拼接列表
+                let productList = this.data.productList.concat(res.data);
+                this.setData({
+                    productList
+                })
+            }
             this.PageDemanding(res.pageTotal)
         })
     },
+    /* 我的需求编辑按钮跳转 */
+    productEdit(e) {
+        console.log(e)
+        const {
+            index
+        } = e.currentTarget.dataset
+        const data = JSON.stringify(this.data.productList[index])
+        wx.navigateTo({
+            url: '/pages/announceDemand/index?data=' + data,
+        })
+    },
     /* 我的需求搜索框获得焦点 */
     needSearchFocus() {
         this.setData({
@@ -207,7 +286,7 @@ Page({
      * 页面上拉触底事件的处理函数
      */
     onReachBottom: function () {
-        if (this.data.active == 2) this.myNeed(); //我的需求
+        this.getList();
     },
 
     /**

+ 6 - 6
pages/tabbar-pages/supplyAndDemand/index.wxml

@@ -20,12 +20,12 @@
                 </van-grid>
             </view>
             <!-- 列表 -->
-            <My_SupplyAndDemandItemBox wx:for="{{5}}" title="【窗帘布】各位老板看下有以下面料的联系" time="2021-11-10 14:23:43">
+            <My_SupplyAndDemandItemBox wx:for="{{productList}}" title="【{{item.ftitle}}】{{item.fcontent}}" time="{{item.checkdate}}">
                 <!-- 内容信息插槽 -->
                 <view slot="dataAndBut">
                     <view class="dataAndBut">
                         <view class="dataAndBut_data">
-                            浏览次数:245次<text>意向沟通人数</text>:134次
+                            浏览次数:245次 意向沟通人数:134次
                         </view>
                         <view class="dataAndBut_but">
                             <van-button color="#4DC2D4" style="margin-left: 16rpx;" custom-class="custom-slotBut">一键联系</van-button>
@@ -55,10 +55,10 @@
                 </view>
             </view>
             <!-- 列表 -->
-            <My_SupplyAndDemandItemBox wx:for="{{5}}" title="【窗帘布】各位老板看下有以下面料的联系" time="2021-11-10 14:23:43">
+            <My_SupplyAndDemandItemBox wx:for="{{productList}}" title="【{{item.ftitle}}】{{item.fcontent}}" time="{{item.checkdate}}">
                 <!-- 下架按钮插槽 -->
                 <view slot="soldOutBut">
-                    <van-button plain color="#4DC2D4" custom-class="soldOutBut">下架</van-button>
+                    <van-button data-index="{{index}}" plain color="#4DC2D4" custom-class="soldOutBut" bindtap="soldOut">下架</van-button>
                 </view>
                 <!-- 内容信息插槽 -->
                 <view slot="dataAndBut">
@@ -67,8 +67,8 @@
                             浏览次数:245次<text>意向沟通人数</text>:134次
                         </view>
                         <view class="dataAndBut_but">
-                            <van-button color="#4DC2D4" custom-class="custom-slotBut">编辑</van-button>
-                            <van-button color="#4DC2D4" style="margin-left: 16rpx;" custom-class="custom-slotBut">正在对接</van-button>
+                            <van-button color="#4DC2D4" data-index="{{index}}" custom-class="custom-slotBut" bindtap="productEdit">编辑</van-button>
+                            <van-button color="#4DC2D4" style="margin-left: 16rpx;" custom-class="custom-slotBut">{{item.fstatus}}</van-button>
                         </view>
                     </view>
                 </view>

+ 10 - 11
pages/userCenter/index.js

@@ -12,7 +12,7 @@ Page({
      * 页面的初始数据
      */
     data: {
-        userMessage: {}, //头像
+        attinfos: [], //头像
         fname: "",
         fphonenumber: "",
         fsex: "",
@@ -34,11 +34,15 @@ Page({
      */
     onLoad: function (options) {
         const userMessage = JSON.parse(options.data);
-        const attinfos = {
-            attinfos: userMessage.attinfos
-        }
+        let attinfos = [{
+            url: userMessage.attinfos[0].fobsurl,
+            ownerid: userMessage.attinfos[0].ownerid,
+            tattachmentid: userMessage.attinfos[0].tattachmentid,
+            ownertable: userMessage.attinfos[0].ownertable,
+            fdocument: userMessage.attinfos[0].fdocument
+        }];
         this.setData({
-            userMessage: attinfos,
+            attinfos,
             fname: userMessage.fname,
             fphonenumber: userMessage.fphonenumber,
             fsex: userMessage.fsex,
@@ -141,13 +145,8 @@ Page({
     },
     /* 修改用户头像 */
     userImageChange(data) {
-        const attinfos = [{
-            ownerid: data.detail.fileList[0].ownerid,
-            tattachmentid: data.detail.fileList[0].tattachmentid,
-            fobsurl: data.detail.fileList[0].url
-        }]
         this.setData({
-            'userMessage.attinfos': attinfos
+            attinfos: data.detail.fileList
         })
     },
     /**

+ 2 - 2
pages/userCenter/index.wxml

@@ -4,11 +4,11 @@
         <view class="user_header_msg">
             <!-- 头像 -->
             <view class="user_headPortrait">
-                <image wx:if="{{userMessage.attinfos[0].fobsurl}}" src="{{userMessage.attinfos[0].fobsurl}}" mode="aspectFill"></image>
+                <image wx:if="{{attinfos[0].url}}" src="{{attinfos[0].url}}" mode="aspectFill"></image>
                 <image wx:else src="/static/userImage.png" mode="aspectFit"></image>
             </view>
             <!-- 修改头像 -->
-            <My_UploadFiles upType="userImage" bind:imageChange="userImageChange" attinfos="{{userMessage.attinfos[0]}}" UploadShow='{{false}}' lineHeight="130rpx">
+            <My_UploadFiles id="UploadFiles" upType="userImage" bind:imageChange="userImageChange" fileList="{{attinfos}}" UploadShow='{{false}}' lineHeight="130rpx">
                 <view class="changeImage">修改头像</view>
             </My_UploadFiles>
         </view>

+ 0 - 6
project.private.config.json

@@ -54,12 +54,6 @@
                     "query": "",
                     "scene": null
                 },
-                {
-                    "name": "发布需求",
-                    "pathName": "pages/announceDemand/index",
-                    "query": "",
-                    "scene": null
-                },
                 {
                     "name": "商户管理",
                     "pathName": "pages/storeMessage/index",