|
|
@@ -1,83 +1,34 @@
|
|
|
-// packageA/contacts/index.js
|
|
|
-let dowmCount = null,
|
|
|
- _Http = getApp().globalData.http,
|
|
|
- dMark = require('../../utils/deleteMark')
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
+import Dialog from '@vant/weapp/dialog/dialog';
|
|
|
Page({
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
data: {
|
|
|
- systemGroup: [], //系统分组
|
|
|
- myGroup: [], //自定义分组
|
|
|
- groupName: '',
|
|
|
- sys_phonebookgroupid: 0,
|
|
|
- dialogShow: false
|
|
|
+ active: "联系人",
|
|
|
+ allGroup: [],
|
|
|
+ defaultGroup: [],
|
|
|
+ myGroup: [],
|
|
|
+ updateGroup: {
|
|
|
+ "sys_phonebookgroupid": 0,
|
|
|
+ "groupname": ""
|
|
|
+ }
|
|
|
},
|
|
|
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("123123", res.data)
|
|
|
- if (condition != '') return res.data;
|
|
|
-
|
|
|
- res.data = res.data.map(v => {
|
|
|
- delete(v.phonebook)
|
|
|
- return v
|
|
|
- })
|
|
|
- let systemGroup = [],
|
|
|
- myGroup = [];
|
|
|
- res.data.forEach(v => ['默认群组', '客户联系人', '项目联系人'].includes(v.groupname) ? systemGroup.push(v) : myGroup.push(v));
|
|
|
- this.setData({
|
|
|
- systemGroup,
|
|
|
- myGroup
|
|
|
- })
|
|
|
- })
|
|
|
+ this.getList(true);
|
|
|
+ this.getGroup(true);
|
|
|
},
|
|
|
- toCheckList(e) {
|
|
|
- const {
|
|
|
- groupname
|
|
|
- } = e.currentTarget.dataset;
|
|
|
- wx.navigateTo({
|
|
|
- url: './list?groupname=' + groupname,
|
|
|
- })
|
|
|
+ onInput(e) {
|
|
|
+ this.data.updateGroup.groupname = e.detail.value;
|
|
|
},
|
|
|
- /* 删除自定义分组 */
|
|
|
deleteGroup(e) {
|
|
|
- const {
|
|
|
+ let {
|
|
|
item
|
|
|
} = e.currentTarget.dataset,
|
|
|
that = this;
|
|
|
- if (item.count) return wx.showToast({
|
|
|
- title: '当前状态不可删除',
|
|
|
- icon: "none"
|
|
|
- });
|
|
|
wx.showModal({
|
|
|
- title: "提示",
|
|
|
- content: `是否确认删除 "${item.groupname}"`,
|
|
|
- success({
|
|
|
+ title: '提示',
|
|
|
+ content: `是否确定删除“${item.groupname}”`,
|
|
|
+ complete: ({
|
|
|
confirm
|
|
|
- }) {
|
|
|
+ }) => {
|
|
|
if (confirm) _Http.basic({
|
|
|
"id": "20220831164403",
|
|
|
"version": 1,
|
|
|
@@ -85,114 +36,141 @@ Page({
|
|
|
"sys_phonebookgroupid": item.sys_phonebookgroupid
|
|
|
}
|
|
|
}).then(res => {
|
|
|
- if (res.msg != '成功') return wx.showToast({
|
|
|
- title: res.msg,
|
|
|
+ console.log("删除群组", res)
|
|
|
+ wx.showToast({
|
|
|
+ title: res.msg != '成功' ? res.msg : '删除成功',
|
|
|
icon: "none"
|
|
|
})
|
|
|
- const myGroup = that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid);
|
|
|
- that.setData({
|
|
|
- myGroup
|
|
|
- })
|
|
|
- wx.showToast({
|
|
|
- title: '删除成功',
|
|
|
+ if (res.msg == '成功') that.setData({
|
|
|
+ myGroup: that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid)
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
|
|
|
},
|
|
|
- /* 开始搜索 */
|
|
|
- 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),
|
|
|
- })
|
|
|
- }
|
|
|
+ editGroup(e) {
|
|
|
+ this.setData({
|
|
|
+ updateGroup: e.currentTarget.dataset.item
|
|
|
})
|
|
|
+ this.showDialog();
|
|
|
},
|
|
|
- onClose(event) {
|
|
|
- const {
|
|
|
- instance
|
|
|
- } = event.detail;
|
|
|
- instance.close();
|
|
|
+ insertGroup() {
|
|
|
+ this.setData({
|
|
|
+ updateGroup: {
|
|
|
+ "sys_phonebookgroupid": 0,
|
|
|
+ "groupname": ""
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.showDialog();
|
|
|
},
|
|
|
- openDialog(e) {
|
|
|
- console.log(e)
|
|
|
- if (e.currentTarget.dataset.item) {
|
|
|
- this.setData({
|
|
|
- dialogShow: true,
|
|
|
- groupName: e.currentTarget.dataset.item.groupname,
|
|
|
- sys_phonebookgroupid: e.currentTarget.dataset.item.sys_phonebookgroupid
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.setData({
|
|
|
- dialogShow: true,
|
|
|
- groupName: "",
|
|
|
- sys_phonebookgroupid: 0
|
|
|
- })
|
|
|
- }
|
|
|
+ showDialog() {
|
|
|
+ Dialog.confirm({
|
|
|
+ beforeClose: (action) =>
|
|
|
+ new Promise((resolve) => {
|
|
|
+ if (action === 'confirm') {
|
|
|
+ let content = this.data.updateGroup;
|
|
|
+ if (content.groupname == "") {
|
|
|
+ wx.showToast({
|
|
|
+ title: '群组名称不可为空',
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ resolve(false);
|
|
|
+ } else {
|
|
|
+ _Http.basic({
|
|
|
+ "id": "20220831164203",
|
|
|
+ "version": 1,
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ let operate = content.sys_phonebookgroupid == 0 ? "新建" : '编辑';
|
|
|
+ console.log(operate + '群组', res)
|
|
|
+ if (res.msg != '成功') {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ resolve(false);
|
|
|
+ } else {
|
|
|
+ this.getGroup(true).then(() => {
|
|
|
+ resolve(true)
|
|
|
+ wx.showToast({
|
|
|
+ title: operate + '成功',
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resolve(true);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
},
|
|
|
- inputName({
|
|
|
- detail
|
|
|
- }) {
|
|
|
+ onChange(e) {
|
|
|
+ const active = e.detail.name;
|
|
|
this.setData({
|
|
|
- groupName: dMark.queryStr(detail.value)
|
|
|
- })
|
|
|
+ active
|
|
|
+ });
|
|
|
+ this.updatedb(active == '群组' && this.data.defaultGroup.length == 0)
|
|
|
},
|
|
|
- handleAddGroup() {
|
|
|
- let name = this.data.groupName.trim()
|
|
|
- if (name.length == 0) return wx.showToast({
|
|
|
- title: '群组名称不可为空',
|
|
|
- icon: "none"
|
|
|
- })
|
|
|
- _Http.basic({
|
|
|
- "id": "20220831164203",
|
|
|
- "version": 1,
|
|
|
- "content": {
|
|
|
- "sys_phonebookgroupid": this.data.sys_phonebookgroupid,
|
|
|
- "groupname": name
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if (res.msg != '成功') {
|
|
|
- wx.showToast({
|
|
|
- title: res.data,
|
|
|
+ async updatedb(init = false) {
|
|
|
+ if (init.detail != undefined) init = init.detail;
|
|
|
+ await this[this.data.active == '联系人' ? 'getList' : 'getGroup'](init)
|
|
|
+ this.selectComponent('#ListBox').RefreshToComplete();
|
|
|
+ },
|
|
|
+ getList(init) {
|
|
|
+ return this.selectComponent("#list").getList(init);
|
|
|
+ },
|
|
|
+ getGroup(init) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ if (!init) return resolve();
|
|
|
+ _Http.basic({
|
|
|
+ "id": "20220831164303",
|
|
|
+ "content": {
|
|
|
+ nocache: true,
|
|
|
+ type: 1,
|
|
|
+ pageSize: 9999,
|
|
|
+ where: {
|
|
|
+ condition: ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ resolve();
|
|
|
+ console.log("群组", res)
|
|
|
+ if (res.msg != '成功') return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
icon: "none"
|
|
|
+ });
|
|
|
+ let myGroup = [],
|
|
|
+ defaultGroup = [];
|
|
|
+ myGroup = res.data.filter(v => {
|
|
|
+ if (v.sys_phonebookgroupid == 0) defaultGroup.push(v)
|
|
|
+ return v.sys_phonebookgroupid
|
|
|
})
|
|
|
- };
|
|
|
- this.getGroup();
|
|
|
- wx.showToast({
|
|
|
- title: this.data.sys_phonebookgroupid == 0 ? '添加成功' : '修改成功',
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- groupName: "",
|
|
|
- sys_phonebookgroupid: 0
|
|
|
+ this.setData({
|
|
|
+ defaultGroup,
|
|
|
+ myGroup
|
|
|
+ })
|
|
|
+ let page = this.selectComponent("#list");
|
|
|
+ if (page) {
|
|
|
+ page.data.filtratelist.unshift({
|
|
|
+ label: "群组",
|
|
|
+ index: null,
|
|
|
+ showName: "groupname", //显示字段
|
|
|
+ valueKey: "group", //传参 代表选着字段 不传参返回整个选择对象
|
|
|
+ value: "", //选中值
|
|
|
+ list: res.data
|
|
|
+ });
|
|
|
+ page.setData({
|
|
|
+ filtratelist: page.data.filtratelist
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- onCancel() {
|
|
|
- this.setData({
|
|
|
- dialogShow: false
|
|
|
- })
|
|
|
+ onReady() {
|
|
|
+ this.selectComponent("#ListBox").setHeight(".linear", this);
|
|
|
},
|
|
|
- onShareAppMessage() {
|
|
|
-
|
|
|
- }
|
|
|
-})
|
|
|
+})
|
|
|
+// ,
|