index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. isNew: false, //是否为新增
  5. ownerid: null,
  6. ownertable: null,
  7. sys_datafollowupid: 0, //数据ID
  8. type: "",
  9. content: "",
  10. user: {}, //联系人
  11. actions: [{
  12. name: "上门拜访"
  13. }, {
  14. name: "电话拜访"
  15. }, {
  16. name: "微信联系"
  17. }, {
  18. name: "QQ联系"
  19. }],
  20. show: false
  21. },
  22. onLoad(options) {
  23. if (options.ownertable) {
  24. this.setData({
  25. ...options
  26. })
  27. };
  28. //编辑获取原信息,新建初始化模板
  29. if (options.sys_datafollowupid) {
  30. _Http.basic({
  31. "id": 20221026085601,
  32. "content": {
  33. "sys_datafollowupid": options.sys_datafollowupid
  34. }
  35. }).then(res => {
  36. console.log("跟进详情", res)
  37. if (res.msg != '成功') {
  38. wx.showToast({
  39. title: res.data,
  40. icon: "none"
  41. })
  42. setTimeout(() => {
  43. wx.navigateBack()
  44. }, 300)
  45. };
  46. this.selectComponent("#Yl_files").handleFiles(res.data.attinfos)
  47. this.setData({
  48. type: res.data.type,
  49. content: res.data.content
  50. })
  51. })
  52. } else {
  53. this.initTemplate()
  54. }
  55. },
  56. /* 绑定媒体 */
  57. insertImgEdit({
  58. detail
  59. }) {
  60. _Http.basic({
  61. "classname": "system.attachment.Attachment",
  62. "method": "createFileLink",
  63. "content": {
  64. "ownertable": "sys_datafollowup",
  65. "ownerid": this.data.sys_datafollowupid,
  66. "usetype": "default",
  67. "attachmentids": detail
  68. }
  69. }).then(res => {
  70. console.log('跟进记录绑定附件', res)
  71. if (res.msg != '成功') return wx.showToast({
  72. title: res.msg,
  73. icon: "none"
  74. })
  75. this.selectComponent("#Yl_files").handleFiles(res.data)
  76. })
  77. },
  78. /* 初始化模板 */
  79. initTemplate() {
  80. _Http.basic({
  81. "id": 20220930121601,
  82. content: {
  83. type: this.data.type,
  84. content: this.data.content,
  85. ownerid: this.data.ownerid,
  86. ownertable: this.data.ownertable,
  87. sys_datafollowupid: this.data.sys_datafollowupid
  88. }
  89. }).then(res => {
  90. this.setData({
  91. sys_datafollowupid: res.data.sys_datafollowupid,
  92. isNew: true
  93. })
  94. })
  95. },
  96. //开始选择跟进方式
  97. openSelect() {
  98. this.setData({
  99. show: true
  100. })
  101. },
  102. //取消选择
  103. onCancel() {
  104. this.setData({
  105. show: false
  106. })
  107. },
  108. //确定选择
  109. onSelect({
  110. detail
  111. }) {
  112. this.setData({
  113. type: detail.name
  114. })
  115. this.onCancel();
  116. },
  117. //文本域输入
  118. onInput(e) {
  119. this.setData({
  120. content: e.detail.value
  121. })
  122. },
  123. submit() {
  124. const content = {
  125. type: this.data.type,
  126. content: this.data.content,
  127. ownerid: this.data.ownerid,
  128. ownertable: this.data.ownertable,
  129. sys_datafollowupid: this.data.sys_datafollowupid
  130. };
  131. if (!content.content) return;
  132. _Http.basic({
  133. "id": 20220930121601,
  134. content
  135. }).then(res => {
  136. if (res.msg != '成功') return wx.showToast({
  137. title: res.data,
  138. icon: "none"
  139. });
  140. wx.showToast({
  141. title: '保存成功',
  142. icon: "none"
  143. });
  144. this.setData({
  145. isNew: false
  146. })
  147. setTimeout(() => {
  148. getCurrentPages().forEach(v => {
  149. //详情界面更新数据
  150. if (['packageA/setclient/modules/trace/detail/index'].includes(v.__route__)) v.getDetail();
  151. //列表页更新数据
  152. if (v.selectComponent("#Trace")) {
  153. let page = v.selectComponent("#Trace"),
  154. list = page.data.list,
  155. index = list.findIndex(value => value.sys_datafollowupid == res.data.sys_datafollowupid);
  156. if (index != -1) {
  157. //列表中存在说明是编辑,返回上一级页面并更新数据
  158. list[index] = res.data;
  159. page.setData({
  160. list
  161. });
  162. wx.navigateBack();
  163. } else {
  164. //列表中不存在说明是新增,返回上一级页面更新数据 并进入详情
  165. list.push(res.data);
  166. page.setData({
  167. list,
  168. "content.total": page.data.content.total + 1
  169. });
  170. wx.navigateBack();
  171. wx.navigateTo({
  172. url: `/packageA/setclient/modules/trace/detail/index?data=` + JSON.stringify({
  173. "sys_datafollowupid": res.data.sys_datafollowupid,
  174. "ownertable": this.data.ownertable,
  175. "ownerid": this.data.ownerid
  176. }),
  177. })
  178. }
  179. };
  180. });
  181. }, 300)
  182. })
  183. },
  184. onUnload() {
  185. if (this.data.isNew) _Http.basic({
  186. "id": 20220930121701,
  187. "content": {
  188. "sys_datafollowupid": this.data.sys_datafollowupid,
  189. "deletereason": "系统删除"
  190. }
  191. }).then(res => {
  192. console.log("初始化模板后未保存删除", res)
  193. })
  194. }
  195. })