index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. options: {
  4. addGlobalClass: true
  5. },
  6. properties: {
  7. ownertable: {
  8. type: String
  9. },
  10. ownerid: {
  11. type: String
  12. },
  13. disabled: {
  14. type: Boolean,
  15. value: true
  16. }
  17. },
  18. lifetimes: {
  19. attached: function () {
  20. _Http.traceHandleDelete = this.handleDelete.bind(this);
  21. },
  22. detached: function () {
  23. delete _Http.traceHandleDelete
  24. },
  25. },
  26. data: {
  27. content: {
  28. nocache: true,
  29. pageNumber: 1,
  30. pageSize: 10,
  31. pageTotal: 1,
  32. total: null,
  33. where: {
  34. condition: ""
  35. }
  36. },
  37. list: [],
  38. showSearch: false,
  39. focus: false,
  40. condition: ""
  41. },
  42. methods: {
  43. toSearch() {
  44. if (this.data.showSearch && this.data.content.where.condition) {
  45. this.data.content.where.condition = '';
  46. this.getList("", true);
  47. } else if (this.data.condition) {
  48. this.data.content.where.condition = this.data.condition;
  49. this.setData({
  50. condition: this.data.condition
  51. })
  52. this.getList("", true);
  53. }
  54. this.setData({
  55. showSearch: !this.data.showSearch
  56. })
  57. setTimeout(() => {
  58. this.setData({
  59. focus: this.data.showSearch
  60. })
  61. }, 300)
  62. },
  63. onChange({
  64. detail
  65. }) {
  66. this.data.condition = detail;
  67. },
  68. onSearch({
  69. detail
  70. }) {
  71. this.data.content.where.condition = detail;
  72. this.getList("", true)
  73. },
  74. getList(id, init = false) {
  75. let content = {
  76. ...this.data.content,
  77. "ownertable": this.data.ownertable,
  78. "ownerid": this.data.ownerid,
  79. };
  80. if (init) {
  81. content.pageNumber = 1
  82. content.pageTotal = 1
  83. }
  84. _Http.basic({
  85. "id": 20220930121501,
  86. content
  87. }).then(res => {
  88. console.log("跟进动态", res)
  89. if (res.msg != '成功') return wx.showToast({
  90. title: res.data,
  91. icon: "none"
  92. });
  93. let deleteList = res.data.filter(v => v.content == "" && v.type == ""),
  94. list = res.data.filter(v => v.content != "" || !v.type == "");
  95. this.handleDeleteList(deleteList);
  96. this.setData({
  97. "content.pageNumber": res.pageNumber + 1,
  98. "content.pageTotal": res.pageTotal,
  99. "content.total": res.total - deleteList.length,
  100. list: res.pageNumber == 1 ? list : this.data.list.concat(list)
  101. })
  102. })
  103. },
  104. /* 批量删除空模板 */
  105. handleDeleteList(list) {
  106. list.forEach(v => {
  107. _Http.basic({
  108. "id": 20220930121701,
  109. "content": {
  110. "sys_datafollowupid": v.sys_datafollowupid,
  111. "deletereason": "系统删除空模板"
  112. }
  113. }, false).then(res => {
  114. console.log(res)
  115. })
  116. })
  117. },
  118. /* 去添加 */
  119. toAdd() {
  120. wx.navigateTo({
  121. url: `/packageA/setclient/modules/trace/add/index?ownertable=${this.data.ownertable}&ownerid=${this.data.ownerid}`,
  122. })
  123. },
  124. //跟进组件设置删除
  125. setDelete(id) {
  126. this.setData({
  127. list: this.data.list.filter(v => v.sys_datafollowupid != id)
  128. });
  129. wx.showToast({
  130. title: '作废成功!',
  131. icon: "none"
  132. })
  133. this.changeTotal()
  134. },
  135. changeTotal() {
  136. this.setData({
  137. "content.total": this.data.content.total - 1
  138. })
  139. },
  140. handleDelete(item) {
  141. let that = this;
  142. return new Promise((resolve) => {
  143. wx.showModal({
  144. title: '提示',
  145. content: '是否确定删除该跟进动态',
  146. complete: ({
  147. confirm
  148. }) => {
  149. if (confirm) {
  150. _Http.basic({
  151. "id": 20220930121701,
  152. "content": {
  153. "sys_datafollowupid": item.sys_datafollowupid,
  154. "ownertable": that.data.ownertable,
  155. "ownerid": that.data.ownerid,
  156. deletereason: ""
  157. }
  158. }).then(res => {
  159. console.log("删除", res);
  160. wx.showToast({
  161. title: res.msg != '成功' ? res.msg : "删除成功",
  162. icon: "none"
  163. });
  164. resolve(res.code)
  165. if (res.msg != '成功') return;
  166. that.setData({
  167. list: that.data.list.filter(v => v.sys_datafollowupid != item.sys_datafollowupid),
  168. 'content.total': that.data.content.total - 1
  169. })
  170. })
  171. } else {
  172. resolve(0)
  173. }
  174. }
  175. })
  176. })
  177. },
  178. }
  179. })