zhaoxiaohai преди 2 години
родител
ревизия
76047836bc
променени са 4 файла, в които са добавени 217 реда и са изтрити 6 реда
  1. 113 2
      packageA/contacts/index.js
  2. 5 1
      packageA/contacts/index.json
  3. 64 1
      packageA/contacts/index.scss
  4. 35 2
      packageA/contacts/index.wxml

+ 113 - 2
packageA/contacts/index.js

@@ -1,20 +1,131 @@
 // packageA/contacts/index.js
+let dowmCount = null,
+    _Http = getApp().globalData.http;
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-
+        systemGroup: [], //系统分组
+        myGroup: [], //自定义分组
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-
+        this.getGroup();
+    },
+    toAddContacts() {
+        wx.navigateTo({
+            url: './edit',
+        })
+    },
+    /* 获取分组 */
+    getGroup(condition = '') {
+        return _Http.basic({
+            "id": "20220831164603",
+            "version": 1,
+            "content": {
+                "nocache": true,
+                "where": {
+                    condition
+                }
+            }
+        }).then(res => {
+            if (res.msg != '成功') return wx.showToast({
+                title: res.msg,
+                icon: "none"
+            })
+            console.log(res.data)
+            if (condition != '') return res.data;
+            let systemGroup = [],
+                myGroup = [];
+            res.data.forEach(v => ['默认群组', '客户联系人', '项目联系人'].includes(v.groupname) ? systemGroup.push(v) : myGroup.push(v));
+            this.setData({
+                systemGroup,
+                myGroup
+            })
+        })
     },
+    toCheckList(e) {
+        const {
+            item
+        } = e.currentTarget.dataset;
+        wx.navigateTo({
+            url: './list?item=' + JSON.stringify(item),
+        })
+    },
+    /* 删除自定义分组 */
+    deleteGroup(e) {
+        const {
+            item
+        } = e.currentTarget.dataset,
+            that = this;
+        if (item.count) return wx.showToast({
+            title: '当前状态不可删除',
+            icon: "none"
+        });
+        wx.showModal({
+            title: "提示",
+            content: `是否确认删除 "${item.groupname}"`,
+            success({
+                confirm
+            }) {
+                if (confirm) _Http.basic({
+                    "id": "20220831164403",
+                    "version": 1,
+                    "content": {
+                        "sys_phonebookgroupid": item.sys_phonebookgroupid
+                    }
+                }).then(res => {
+                    if (res.msg != '成功') return wx.showToast({
+                        title: res.msg,
+                        icon: "none"
+                    })
+                    const myGroup = that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid);
+                    that.setData({
+                        myGroup
+                    })
+                })
+            }
+        })
 
+    },
+    /* 开始搜索 */
+    startSearch({
+        detail
+    }) {
+        this.getGroup(detail.trim()).then(res => {
+            let item = {
+                groupname: "搜索",
+                phonebook: [],
+                sys_phonebookgroupid: 0
+            };
+            res.forEach(v => {
+                if (v.phonebook.length != 0) {
+                    item.phonebook = item.phonebook.concat(v.phonebook)
+                }
+            });
+            if (item.phonebook.length == 0) {
+                wx.showToast({
+                    title: `未找到与'${detail.trim()}'有关内容`,
+                    icon: "none"
+                })
+            } else {
+                wx.navigateTo({
+                    url: './list?item=' + JSON.stringify(item),
+                })
+            }
+        })
+    },
+    onClose(event) {
+        const {
+            instance
+        } = event.detail;
+        instance.close();
+    },
     /**
      * 生命周期函数--监听页面初次渲染完成
      */

+ 5 - 1
packageA/contacts/index.json

@@ -1,3 +1,7 @@
 {
-    "usingComponents": {}
+    "usingComponents": {
+        "add": "./modules/add/index",
+        "van-swipe-cell": "@vant/weapp/swipe-cell/index"
+    },
+    "navigationBarTitleText": "联系人"
 }

+ 64 - 1
packageA/contacts/index.scss

@@ -1 +1,64 @@
-/* packageA/contacts/index.wxss */
+/* 组 */
+.group-box {
+    width: 100vw;
+    background-color: #fff;
+    margin-top: 20rpx;
+    padding-bottom: 15rpx;
+
+    .title {
+        height: 42rpx;
+        font-size: 30rpx;
+        font-family: PingFang SC-Bold, PingFang SC;
+        font-weight: bold;
+        color: #000000;
+        padding: 30rpx;
+        padding-bottom: 15rpx;
+    }
+
+    .group {
+        display: flex;
+        width: 100vw;
+        padding: 15rpx 30rpx;
+        box-sizing: border-box;
+
+        >view {
+            height: 84rpx;
+        }
+
+        .icon {
+            width: 84rpx;
+            border-radius: 16rpx;
+            margin-right: 20rpx;
+        }
+
+        .text {
+            flex: 1;
+
+            .name {
+                height: 40rpx;
+                font-size: 28rpx;
+                font-family: PingFang SC-Regular, PingFang SC;
+                color: #333333;
+            }
+
+            .count {
+                height: 34rpx;
+                font-size: 24rpx;
+                font-family: PingFang SC-Regular, PingFang SC;
+                color: #999999;
+                margin-top: 6rpx;
+            }
+        }
+    }
+
+    /* 滑动 */
+    .slide {
+        display: flex;
+        height: 84rpx;
+        width: 240rpx;
+        margin-top: 15rpx;
+        .but{
+            border-radius: 0 !important;
+        }
+    }
+}

+ 35 - 2
packageA/contacts/index.wxml

@@ -1,2 +1,35 @@
-<!--packageA/contacts/index.wxml-->
-<text>packageA/contacts/index.wxml</text>
+<van-search value="{{ condition }}" shape="round" background="var(--primary)" bind:search='startSearch' placeholder="搜索联系人" />
+<add isGroup bind:callBack='toAddContacts' />
+<!-- 系统分组 -->
+<view class="group-box">
+    <view class="title">系统群组</view>
+    <navigator url="#" class="group" wx:for="{{systemGroup}}" wx:key="item.groupname" bindtap="toCheckList" data-item="{{item}}">
+        <view class="icon" style="background: #FA8C16;">
+        </view>
+        <view class="text">
+            <view class="name">{{item.groupname}}</view>
+            <view class="count">已有 {{item.count}} 人</view>
+        </view>
+        <van-icon size='14' color='#D2D2D2' name="arrow" />
+    </navigator>
+</view>
+<!-- 自定义分组 -->
+<view class="group-box">
+    <view class="title">自定义群组</view>
+    <van-swipe-cell id="swipe-cell" async-close bind:close="onClose" right-width="{{ 120 }}" wx:for="{{myGroup}}" wx:key="item.groupname" bind:close="onClose">
+        <van-cell-group>
+            <navigator url="#" class="group" bindtap="toCheckList" data-item="{{item}}">
+                <view class="icon" style="background: #52C41A;"></view>
+                <view class="text">
+                    <view class="name">{{item.groupname}}</view>
+                    <view class="count">已有 {{item.count}} 人</view>
+                </view>
+                <van-icon size='14' color='#D2D2D2' name="arrow" />
+            </navigator>
+        </van-cell-group>
+        <view slot="right" class="slide">
+            <van-button custom-class='but' color="#FA8C16">编辑</van-button>
+            <van-button custom-class='but' color="#FF3B30" bindtap="deleteGroup" data-item="{{item}}">删除</van-button>
+        </view>
+    </van-swipe-cell>
+</view>