index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const _Http = getApp().globalData.http;
  2. import Dialog from '@vant/weapp/dialog/dialog';
  3. Page({
  4. data: {
  5. active: "群组",
  6. allGroup: [],
  7. defaultGroup: [],
  8. myGroup: [],
  9. updateGroup: {
  10. "sys_phonebookgroupid": 0,
  11. "groupname": ""
  12. }
  13. },
  14. onLoad(options) {
  15. this.setData({
  16. active: "联系人"
  17. })
  18. this.getList(true);
  19. this.getGroup(true);
  20. _Http.getGroup = this.getGroup.bind(this);
  21. },
  22. onInput(e) {
  23. this.data.updateGroup.groupname = e.detail.value;
  24. },
  25. deleteGroup(e) {
  26. let {
  27. item
  28. } = e.currentTarget.dataset,
  29. that = this;
  30. wx.showModal({
  31. title: '提示',
  32. content: `是否确定删除“${item.groupname}”`,
  33. complete: ({
  34. confirm
  35. }) => {
  36. if (confirm) _Http.basic({
  37. "id": "20220831164403",
  38. "version": 1,
  39. "content": {
  40. "sys_phonebookgroupid": item.sys_phonebookgroupid
  41. }
  42. }).then(res => {
  43. console.log("删除群组", res)
  44. wx.showToast({
  45. title: res.msg != '成功' ? res.msg : '删除成功',
  46. icon: "none"
  47. })
  48. if (res.msg == '成功') that.setData({
  49. myGroup: that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid)
  50. })
  51. })
  52. }
  53. })
  54. },
  55. editGroup(e) {
  56. this.setData({
  57. updateGroup: e.currentTarget.dataset.item
  58. })
  59. this.showDialog();
  60. },
  61. insertGroup() {
  62. this.setData({
  63. updateGroup: {
  64. "sys_phonebookgroupid": 0,
  65. "groupname": ""
  66. }
  67. });
  68. this.showDialog();
  69. },
  70. showDialog() {
  71. Dialog.confirm({
  72. beforeClose: (action) =>
  73. new Promise((resolve) => {
  74. if (action === 'confirm') {
  75. let content = this.data.updateGroup;
  76. if (content.groupname == "") {
  77. wx.showToast({
  78. title: '群组名称不可为空',
  79. icon: "none"
  80. })
  81. resolve(false);
  82. } else {
  83. _Http.basic({
  84. "id": "20220831164203",
  85. "version": 1,
  86. content
  87. }).then(res => {
  88. let operate = content.sys_phonebookgroupid == 0 ? "新建" : '编辑';
  89. console.log(operate + '群组', res)
  90. if (res.msg != '成功') {
  91. wx.showToast({
  92. title: res.msg,
  93. icon: "none"
  94. })
  95. resolve(false);
  96. } else {
  97. this.getGroup(true).then(() => {
  98. resolve(true)
  99. wx.showToast({
  100. title: operate + '成功',
  101. icon: "none"
  102. })
  103. })
  104. }
  105. })
  106. }
  107. } else {
  108. resolve(true);
  109. }
  110. })
  111. });
  112. },
  113. onChange(e) {
  114. const active = e.detail.name;
  115. if (active == this.data.active) return;
  116. this.setData({
  117. active
  118. });
  119. this.updatedb(active == '群组' && this.data.defaultGroup.length == 0)
  120. },
  121. async updatedb(init = false) {
  122. if (init.detail != undefined) init = init.detail;
  123. await this[this.data.active == '联系人' ? 'getList' : 'getGroup'](init)
  124. this.selectComponent('#ListBox').RefreshToComplete();
  125. },
  126. getList(init) {
  127. return this.selectComponent("#list").getList(init);
  128. },
  129. getGroup(init) {
  130. return new Promise((resolve) => {
  131. if (!init) return resolve();
  132. _Http.basic({
  133. "id": "20220831164303",
  134. "content": {
  135. nocache: true,
  136. type: 1,
  137. pageSize: 9999,
  138. where: {
  139. condition: ""
  140. }
  141. }
  142. }).then(res => {
  143. resolve();
  144. console.log("群组", res)
  145. if (res.msg != '成功') return wx.showToast({
  146. title: res.msg,
  147. icon: "none"
  148. });
  149. let myGroup = [],
  150. defaultGroup = [];
  151. myGroup = res.data.filter(v => {
  152. if (v.sys_phonebookgroupid == 0) defaultGroup.push(v)
  153. return v.sys_phonebookgroupid
  154. })
  155. this.setData({
  156. defaultGroup,
  157. myGroup
  158. })
  159. let page = this.selectComponent("#list");
  160. if (page) {
  161. page.data.filtratelist.unshift({
  162. label: "群组",
  163. index: null,
  164. showName: "groupname", //显示字段
  165. valueKey: "group", //传参 代表选着字段 不传参返回整个选择对象
  166. value: "", //选中值
  167. list: res.data
  168. });
  169. page.setData({
  170. filtratelist: page.data.filtratelist
  171. })
  172. }
  173. })
  174. })
  175. },
  176. onReady() {
  177. this.selectComponent("#ListBox").setHeight(".linear", this);
  178. },
  179. onUnload() {
  180. delete(_Http.updateList)
  181. delete(_Http.getGroup)
  182. },
  183. })