index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // packageA/contacts/index.js
  2. let dowmCount = null,
  3. _Http = getApp().globalData.http,
  4. dMark = require('../../utils/deleteMark')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. systemGroup: [], //系统分组
  11. myGroup: [], //自定义分组
  12. groupName: '',
  13. sys_phonebookgroupid: 0,
  14. dialogShow: false
  15. },
  16. onLoad(options) {
  17. this.getGroup();
  18. },
  19. toAddContacts() {
  20. wx.navigateTo({
  21. url: './edit',
  22. })
  23. },
  24. /* 获取分组 */
  25. getGroup(condition = '') {
  26. return _Http.basic({
  27. "id": "20220831164603",
  28. "version": 1,
  29. "content": {
  30. "nocache": true,
  31. "where": {
  32. condition
  33. }
  34. }
  35. }).then(res => {
  36. if (res.msg != '成功') return wx.showToast({
  37. title: res.msg,
  38. icon: "none"
  39. })
  40. console.log(res.data)
  41. if (condition != '') return res.data;
  42. let systemGroup = [],
  43. myGroup = [];
  44. res.data.forEach(v => ['默认群组', '客户联系人', '项目联系人'].includes(v.groupname) ? systemGroup.push(v) : myGroup.push(v));
  45. this.setData({
  46. systemGroup,
  47. myGroup
  48. })
  49. })
  50. },
  51. toCheckList(e) {
  52. const {
  53. item
  54. } = e.currentTarget.dataset;
  55. wx.navigateTo({
  56. url: './list?item=' + JSON.stringify(item),
  57. })
  58. },
  59. /* 删除自定义分组 */
  60. deleteGroup(e) {
  61. const {
  62. item
  63. } = e.currentTarget.dataset,
  64. that = this;
  65. if (item.count) return wx.showToast({
  66. title: '当前状态不可删除',
  67. icon: "none"
  68. });
  69. wx.showModal({
  70. title: "提示",
  71. content: `是否确认删除 "${item.groupname}"`,
  72. success({
  73. confirm
  74. }) {
  75. if (confirm) _Http.basic({
  76. "id": "20220831164403",
  77. "version": 1,
  78. "content": {
  79. "sys_phonebookgroupid": item.sys_phonebookgroupid
  80. }
  81. }).then(res => {
  82. if (res.msg != '成功') return wx.showToast({
  83. title: res.msg,
  84. icon: "none"
  85. })
  86. const myGroup = that.data.myGroup.filter(v => v.sys_phonebookgroupid != item.sys_phonebookgroupid);
  87. that.setData({
  88. myGroup
  89. })
  90. wx.showToast({
  91. title: '删除成功',
  92. })
  93. })
  94. }
  95. })
  96. },
  97. /* 开始搜索 */
  98. startSearch({
  99. detail
  100. }) {
  101. this.getGroup(detail.trim()).then(res => {
  102. let item = {
  103. groupname: "搜索",
  104. phonebook: [],
  105. sys_phonebookgroupid: 0
  106. };
  107. res.forEach(v => {
  108. if (v.phonebook.length != 0) {
  109. item.phonebook = item.phonebook.concat(v.phonebook)
  110. }
  111. });
  112. if (item.phonebook.length == 0) {
  113. wx.showToast({
  114. title: `未找到与'${detail.trim()}'有关内容`,
  115. icon: "none"
  116. })
  117. } else {
  118. wx.navigateTo({
  119. url: './list?item=' + JSON.stringify(item),
  120. })
  121. }
  122. })
  123. },
  124. onClose(event) {
  125. const {
  126. instance
  127. } = event.detail;
  128. instance.close();
  129. },
  130. openDialog(e) {
  131. console.log(e)
  132. if (e.currentTarget.dataset.item) {
  133. this.setData({
  134. dialogShow: true,
  135. groupName: e.currentTarget.dataset.item.groupname,
  136. sys_phonebookgroupid: e.currentTarget.dataset.item.sys_phonebookgroupid
  137. })
  138. } else {
  139. this.setData({
  140. dialogShow: true,
  141. groupName: "",
  142. sys_phonebookgroupid: 0
  143. })
  144. }
  145. },
  146. inputName({
  147. detail
  148. }) {
  149. this.setData({
  150. groupName: dMark.queryStr(detail.value)
  151. })
  152. },
  153. handleAddGroup() {
  154. let name = this.data.groupName.trim()
  155. if (name.length == 0) return wx.showToast({
  156. title: '群组名称不可为空',
  157. icon: "none"
  158. })
  159. _Http.basic({
  160. "id": "20220831164203",
  161. "version": 1,
  162. "content": {
  163. "sys_phonebookgroupid": this.data.sys_phonebookgroupid,
  164. "groupname": name
  165. }
  166. }).then(res => {
  167. if (res.msg != '成功') {
  168. wx.showToast({
  169. title: res.data,
  170. icon: "none"
  171. })
  172. };
  173. this.getGroup();
  174. wx.showToast({
  175. title: this.data.sys_phonebookgroupid == 0 ? '添加成功' : '修改成功',
  176. })
  177. this.setData({
  178. groupName: "",
  179. sys_phonebookgroupid: 0
  180. })
  181. })
  182. },
  183. onCancel() {
  184. this.setData({
  185. dialogShow: false
  186. })
  187. },
  188. onShareAppMessage() {
  189. }
  190. })