zhaoxiaohai 3 سال پیش
والد
کامیت
4b0a2e263f
4فایلهای تغییر یافته به همراه193 افزوده شده و 57 حذف شده
  1. 109 13
      components/My_Checkbox/index.js
  2. 2 2
      components/My_Checkbox/index.wxml
  3. 79 39
      pages/annunciate/newAndChange.js
  4. 3 3
      pages/annunciate/newAndChange.wxml

+ 109 - 13
components/My_Checkbox/index.js

@@ -24,6 +24,10 @@ Component({
             type: Array,
             value: []
         },
+        /* 是否全选 */
+        isAll: {
+            type: Number
+        },
         /* 回调 */
         saleprodChange: {
             type: Function
@@ -40,7 +44,7 @@ Component({
         }
     },
     lifetimes: {
-        attached: function () {
+        ready: function () {
             //查询类目列表
             if (this.data.isRequest) _Http.basic({
                 "accesstoken": wx.getStorageSync('userData').token,
@@ -48,7 +52,6 @@ Component({
                 "method": "query_typeselectList",
                 "content": {}
             }, false).then(res => {
-                console.log('asdasd')
                 if (res.msg != '成功') return;
                 let dataList = [];
                 for (let i = 0; i < res.data.length; i++) {
@@ -71,22 +74,72 @@ Component({
                 this.setData({
                     dataList
                 })
-            })
+            });
+            if (this.data.type == 'annunciate') {
+                _Http.basic({
+                    "accesstoken": wx.getStorageSync('userData').token,
+                    "classname": "customer.tagents.tagents",
+                    "method": "query_cooperation",
+                    "content": {
+                        "getdatafromdbanyway": true,
+                        "pageNumber": 1,
+                        "pageSize": 999,
+                        "where": {
+                            "condition": "",
+                            "ftype": "",
+                            "fstatus": ""
+                        }
+                    }
+                }, false).then(res => {
+                    if (res.msg != '成功') return wx.showToast({
+                        title: res.data,
+                        icon: "none"
+                    })
+                    let data = res.data,
+                        partnerCount = 0;
+                    if (this.data.isAll == 0) {
+                        for (let i = 0; i < data.length; i++) {
+                            data[i].index = i;
+                            data[i].checked = true;
+                            partnerCount = partnerCount + 1
+                        }
+                    } else {
+                        for (let i = 0; i < data.length; i++) {
+                            data[i].index = i;
+                            data[i].checked = false;
+                        }
+                    }
+                    this.setData({
+                        dataList: data,
+                        partnerCount,
+                        manual: this.data.isAll
+                    });
+                })
+            }
         },
     },
     observers: {
-        'dataList,saleprodclass': function (dataList, saleprodclass) {
-            console.log(dataList, saleprodclass)
-            console.log(this.data.dataList)
-            if (dataList.length == 0 || saleprodclass == 0) return;
+        'saleprodclass': function (saleprodclass) {
+            if (this.data.type != "annunciate") return;
+            setTimeout(() => {
+                let dataList = this.data.dataList;
+                for (let i = 0; i < dataList.length; i++) {
+                    if (saleprodclass.some((v) => v == dataList[i].tcooperationagentsid)) {
+                        dataList[i].checked = true;
+                    }
+                }
+                this.setData({
+                    dataList
+                })
+            }, 1000);
         }
     },
-
     /**
      * 组件的初始数据
      */
     data: {
         pitchOnList: [], //选中列表
+        manual: 0, //是否手动选择发布范围
     },
 
     /**
@@ -95,7 +148,34 @@ Component({
     methods: {
         /* 确定 */
         confirm() {
-            this.triggerEvent("saleprodChange", this.data.pitchOnList)
+            if (this.data.type == 'default') {
+                this.triggerEvent("saleprodChange", this.data.pitchOnList)
+            } else if (this.data.type == 'annunciate') {
+                let data = {
+                    isAll: this.data.isAll
+                };
+                if (this.data.isAll == 1) {
+                    let include = [], //选中的商户id
+                        list = this.data.dataList,
+                        deleteItem = [], //删除的商户id
+                        saleprodclass = this.data.saleprodclass;
+                    //选中商户id
+                    for (let i = 0; i < list.length; i++) {
+                        if (list[i].checked) include.push(list[i].tcooperationagentsid)
+                    };
+                    //删除商户id
+                    if (saleprodclass.length >= 1) {
+                        for (let i = 0; i < saleprodclass.length; i++) {
+                            if (!include.some((v) => v == saleprodclass[i])) {
+                                deleteItem.push(saleprodclass[i])
+                            }
+                        }
+                    };
+                    data.include = include;
+                    data.deleteItem = deleteItem;
+                };
+                this.triggerEvent("saleprodChange", JSON.stringify(data));
+            }
         },
         /* 多选框返回数值 */
         checkedChange(e) {
@@ -105,10 +185,23 @@ Component({
         },
         /* 添加背景色 */
         pitchOn(e) {
-            let dataList = this.data.dataList;
-            dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
+            let dataList = this.data.dataList,
+                index = e.currentTarget.dataset.index,
+                partnerCount = this.data.partnerCount,
+                isAll = 1;
+            //计数
+            if (dataList[index].checked) {
+                partnerCount = partnerCount - 1
+            } else {
+                partnerCount = partnerCount + 1
+            }
+            isAll = (partnerCount == dataList.length) ? isAll = 0 : isAll = 1; //是否指定范围
+            dataList[index].checked = !dataList[index].checked; //切换状态
+            if (this.data.manual == 1) isAll = 1;
             this.setData({
-                dataList
+                dataList,
+                isAll,
+                partnerCount
             })
         },
         /* 商户全选或指定范围 */
@@ -116,7 +209,10 @@ Component({
             const {
                 value
             } = e.detail;
-            console.log(value)
+            this.setData({
+                isAll: value,
+                manual: value
+            })
         }
     }
 })

+ 2 - 2
components/My_Checkbox/index.wxml

@@ -24,8 +24,8 @@
 </checkbox-group>
 <view class="checkbox_but">
     <radio-group wx:if="{{type=='annunciate'}}" class="radio" bindchange='allOrPart'>
-        <radio color='#4EBFCF' value="全部">全部</radio>
-        <radio color='#4EBFCF' value="指定" style="margin-left: 18rpx;">指定</radio>
+        <radio color='#4EBFCF' checked="{{isAll==0}}" value="0">全部</radio>
+        <radio color='#4EBFCF' checked="{{isAll==1}}" value="1" style="margin-left: 18rpx;">指定</radio>
     </radio-group>
     <view class="button">
         <van-button type="info" size="large" color="#4EBFCF" custom-class="customClass" bindtap="confirm">确定</van-button>

+ 79 - 39
pages/annunciate/newAndChange.js

@@ -18,6 +18,8 @@ Page({
         ftype: "", //通告类型
         popups: false,
         checkboxShow: false, //多选
+        fisspecifiedrange: 0, // 是否指定范围,0否 1 是
+        include: [], //包含范围
         partnerList: [], //合作商列表
         coverFiles: [], //封面
         defaultFiles: [], //附件
@@ -42,16 +44,16 @@ Page({
                     "tnoticeid": options.id
                 }
             }).then(res => {
+                console.log("详情", res)
                 if (res.msg != '成功') return wx.showToast({
                     title: res.data,
                     icon: "none"
                 });
-                console.log(res.data[0].fisspecifiedrange)
                 let data = res.data[0],
                     attinfos = res.data[0].attinfos,
                     coverFiles = [],
                     defaultFiles = [],
-                    ftype = (data.ftype == '商户') ? '商户公告' : '团队公告';
+                    ftype = (data.ftype == '商户') ? '合作商通告' : '团队通告';
                 for (let i = 0; i < attinfos.length; i++) {
                     let img = {
                         name: attinfos[i].serialnumber,
@@ -63,6 +65,30 @@ Page({
                     };
                     (img.ftype == "default") ? defaultFiles.push(img): coverFiles.push(img)
                 }
+                if (data.ftype == '商户' && data.fisspecifiedrange == 1) {
+                    //查询指定范围
+                    _Http.basic({
+                        "accesstoken": wx.getStorageSync('userData').token,
+                        "classname": "customer.noticemag.noticemag",
+                        "method": "query_noticeuserList",
+                        "content": {
+                            "tnoticeid": options.id
+                        }
+                    }).then(s => {
+                        console.log("查询范围", s)
+                        if (s.msg != '成功') return wx.showToast({
+                            title: res.data,
+                            icon: "none"
+                        });
+                        let include = [];
+                        for (let i = 0; i < s.data.length; i++) {
+                            include.push(s.data[i].tagentsid)
+                        }
+                        this.setData({
+                            include
+                        })
+                    })
+                }
                 this.setData({
                     tnoticeid: data.tnoticeid,
                     ftitle: data.ftitle,
@@ -70,11 +96,31 @@ Page({
                     fcontent: data.fcontent,
                     ftype: ftype,
                     coverFiles,
-                    defaultFiles
+                    defaultFiles,
+                    fisspecifiedrange: data.fisspecifiedrange
                 })
             })
         }
     },
+    //范围选择回调
+    scopeCallBack({
+        detail
+    }) {
+        let data = JSON.parse(detail);
+        if (data.isAll == 0) {
+            this.setData({
+                fisspecifiedrange: data.isAll,
+                checkboxShow: false
+            })
+        } else {
+            this.setData({
+                deleteList: data.deleteItem,
+                include: data.include,
+                fisspecifiedrange: data.isAll,
+                checkboxShow: false
+            })
+        }
+    },
     /* 修改图片回调 */
     imageChange(e) {
         const {
@@ -93,7 +139,7 @@ Page({
             defaultFiles: fileList
         })
     },
-    /* 提交代码 */
+    /* 提交 */
     submit() {
         if (!this.formVerify()) return wx.showToast({
             title: '请检查表单内容',
@@ -108,6 +154,7 @@ Page({
                 "tnoticeid": this.data.tnoticeid,
                 "ftype": ftype,
                 "ftitle": this.data.ftitle,
+                "fisspecifiedrange": this.data.fisspecifiedrange,
                 "fsummary": this.data.fsummary,
                 "fcontent": this.data.fcontent,
             }
@@ -128,6 +175,34 @@ Page({
             }).then(s => {
                 console.log("修改上架", s)
             })
+            //指定范围,删除
+            if (ftype == '商户') {
+                if (this.data.fisspecifiedrange == 1) {
+                    //默认新增
+                    let body = {
+                        "accesstoken": wx.getStorageSync('userData').token,
+                        "classname": "customer.noticemag.noticemag",
+                        "method": "adduser",
+                        "content": {
+                            "tnoticeid": res.data[0].tnoticeid,
+                            "tagentsid": this.data.include
+                        }
+                    }
+                    console.log(this.data.include)
+                    _Http.basic(body).then(res => {
+                        console.log("添加范围", res)
+                    });
+                    //删除
+                    let deleteList = this.data.deleteList;
+                    body.method = 'deleteuser';
+                    body.content.tagentsid = deleteList;
+                    if (deleteList.length >= 1) {
+                        _Http.basic(body).then(res => {
+                            console.log("删除", res)
+                        });
+                    }
+                }
+            }
             wx.showToast({
                 title: '保存成功',
             });
@@ -214,47 +289,12 @@ Page({
         detail
     }) {
         console.log(detail)
-        if (detail == '合作商通告') this.query_cooperation(1)
         this.setData({
             ftype: detail,
             popups: false,
             'errTips.ftype': false
         })
     },
-    /* 合作商列表 */
-    query_cooperation(count) {
-        if (this.data.partnerList.length > 0) return;
-        _Http.basic({
-            "accesstoken": wx.getStorageSync('userData').token,
-            "classname": "customer.tagents.tagents",
-            "method": "query_cooperation",
-            "content": {
-                "getdatafromdbanyway": true,
-                "pageNumber": 1,
-                "pageSize": 999,
-                "where": {
-                    "condition": "",
-                    "ftype": "",
-                    "fstatus": ""
-                }
-            }
-        }, false).then(res => {
-            console.log(res)
-            if (res.msg != '成功') {
-                if (count == 1) {
-                    return this.query_cooperation(2)
-                } else {
-                    wx.showToast({
-                        title: res.data,
-                        icon: "none"
-                    })
-                }
-            };
-            this.setData({
-                partnerList: res.data
-            });
-        })
-    },
     /* 打开类目选择 */
     showPop() {
         this.setData({

+ 3 - 3
pages/annunciate/newAndChange.wxml

@@ -22,8 +22,8 @@
         <My_GreyRectangleForm title="发布类型" required>
             <view class="clickPop {{ftype==''?'':'selected'}}" style="color: {{errTips.ftype?'#EF2C48':'#000'}};opacity:{{errTips.ftype?'1':'0.3'}} ;" bindtap="showPop">{{ftype?ftype:"点击选择"}}</view>
         </My_GreyRectangleForm>
-        <My_GreyRectangleForm title="发布范围">
-            <view class="clickPop {{ftype==''?'':'selected'}}" style="color: {{errTips.ftype?'#EF2C48':'#000'}};opacity:{{errTips.ftype?'1':'0.3'}} ;" bindtap="checkboxShowPop">{{ftype?ftype:"全部"}}</view>
+        <My_GreyRectangleForm wx:if="{{ftype=='合作商通告'}}" title="发布范围">
+            <view class="clickPop" style="color: #000; opacity: 1;" bindtap="checkboxShowPop">{{fisspecifiedrange==0?"全部":"指定范围"}}</view>
         </My_GreyRectangleForm>
     </view>
 </My_GeneralTemplate>
@@ -34,7 +34,7 @@
 </van-action-sheet>
 <!-- 发布范围弹出层 -->
 <van-action-sheet show="{{ checkboxShow }}" bind:close="checkboxShowPop">
-    <My_Checkbox type='annunciate' title="合作商" dataList='{{partnerList}}' isRequest='{{false}}' />
+    <My_Checkbox type='annunciate' title="合作商" saleprodclass='{{include}}' isAll="{{fisspecifiedrange}}" isRequest='{{false}}' bind:saleprodChange='scopeCallBack' />
 </van-action-sheet>
 <!-- 提交按钮 -->
 <view class="submit_but">