| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- const _Http = getApp().globalData.http;
- import Dialog from '@vant/weapp/dialog/dialog';
- Page({
- data: {
- active: "群组",
- allGroup: [],
- defaultGroup: [],
- myGroup: [],
- updateGroup: {
- "sys_phonebookgroupid": 0,
- "groupname": ""
- }
- },
- onLoad(options) {
- this.setData({
- active: "联系人"
- })
- this.getList(true);
- this.getGroup(true);
- _Http.getGroup = this.getGroup.bind(this);
- },
- onInput(e) {
- this.data.updateGroup.groupname = e.detail.value;
- },
- deleteGroup(e) {
- let {
- item
- } = e.currentTarget.dataset,
- that = this;
- wx.showModal({
- title: '提示',
- content: `是否确定删除“${item.groupname}”`,
- complete: ({
- confirm
- }) => {
- if (confirm) _Http.basic({
- "id": "20220831164403",
- "version": 1,
- "content": {
- "sys_phonebookgroupid": item.sys_phonebookgroupid
- }
- }).then(res => {
- console.log("删除群组", res)
- wx.showToast({
- title: res.msg != '成功' ? res.msg : '删除成功',
- icon: "none"
- })
- if (res.msg == '成功') that.setData({
- myGroup: that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid)
- })
- })
- }
- })
- },
- editGroup(e) {
- this.setData({
- updateGroup: e.currentTarget.dataset.item
- })
- this.showDialog();
- },
- insertGroup() {
- this.setData({
- updateGroup: {
- "sys_phonebookgroupid": 0,
- "groupname": ""
- }
- });
- this.showDialog();
- },
- 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);
- }
- })
- });
- },
- onChange(e) {
- const active = e.detail.name;
- if (active == this.data.active) return;
- this.setData({
- active
- });
- this.updatedb(active == '群组' && this.data.defaultGroup.length == 0)
- },
- 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.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
- })
- }
- })
- })
- },
- onReady() {
- this.selectComponent("#ListBox").setHeight(".linear", this);
- },
- onUnload() {
- delete(_Http.updateList)
- delete(_Http.getGroup)
- },
- })
|