Ver código fonte

选择联系人

zhaoxiaohai 3 anos atrás
pai
commit
d715908b2b

+ 101 - 0
packageA/select/contacts/select.js

@@ -0,0 +1,101 @@
+const _Http = getApp().globalData.http;
+Page({
+    data: {
+        list: [],
+        result: [],
+        radio: false,
+    },
+    onLoad(options) {
+        if (options.item) {
+            let item = JSON.parse(options.item);
+            this.setData({
+                item,
+                params: item.params,
+                result: item.value.length ? item.value[1] : []
+            })
+        };
+        if (options.params) this.setData({
+            params: JSON.parse(params)
+        })
+        this.setData({
+            radio: options.radio ? true : false
+        })
+        this.getList();
+    },
+    /* 提交 */
+    submit() {
+        let pages = getCurrentPages(),
+            item = this.data.item,
+            result = this.data.result,
+            list = this.data.result.map(value => this.data.list.find(v => v.contactsid == value));
+        try {
+            let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
+            if (page) {
+                item.value = this.data.radio ? [list[0].name, result] : [list.map(v => v.name), result];
+                page.handleRoute(item);
+            } else {
+                pages[pages.length - 2].handleSelectContacts(this.data.result, list)
+            }
+        } catch (e) {
+            wx.showToast({
+                title: '操作失败',
+                icon: "none"
+            })
+        }
+    },
+    /* 开始搜索 */
+    onSearch({
+        detail
+    }) {
+        if (this.data.params.content.where.condition == detail) return;
+        this.setData({
+            'params.content.where.condition': detail
+        });
+        this.getList(true)
+    },
+    onClear() {
+        this.setData({
+            'params.content.where.condition': ""
+        });
+        this.getList(true)
+    },
+    /* 选中 */
+    onChange(e) {
+        const contactsid = e.currentTarget.dataset.item.contactsid + "";
+        if (!contactsid) return;
+        let result = this.data.result;
+        if (this.data.radio) {
+            result = [contactsid]
+        } else {
+            if (result.some(v => v == contactsid)) {
+                result = result.filter(v => v != contactsid)
+            } else {
+                result.push(contactsid)
+            }
+        }
+        this.setData({
+            result
+        })
+    },
+    //获取列表
+    getList(init = false) {
+        let params = this.data.params;
+        if (init) params.content.pageNumber = 1;
+        if (params.content.pageNumber > params.content.pageTotal) return;
+        _Http.basic(params).then(res => {
+            console.log("联系人", res)
+            if (res.msg != '成功') return wx.showToast({
+                title: res.data,
+                icon: "none"
+            });
+            this.setData({
+                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
+                "params.content.pageNumber": res.pageNumber + 1,
+                "params.content.pageTotal": res.pageTotal,
+            })
+        })
+    },
+    onReachBottom() {
+        this.getList();
+    }
+})

+ 4 - 0
packageA/select/contacts/select.json

@@ -0,0 +1,4 @@
+{
+    "usingComponents": {},
+    "navigationBarTitleText": "选择联系人"
+}