index.js 6.9 KB

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