index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. loading: false,
  5. list: [{
  6. label: "跟进内容",
  7. key: "content",
  8. value: "",
  9. }],
  10. content: {
  11. }
  12. },
  13. onLoad(options) {
  14. getApp().globalData.Language.getLanguagePackage(this, '跟进');
  15. if (options.ownertable) {
  16. this.setData({
  17. ...options
  18. })
  19. };
  20. //编辑获取原信息,新建初始化模板
  21. if (options.sys_datafollowupid) {
  22. _Http.basic({
  23. "id": 20221026085601,
  24. "content": {
  25. "sys_datafollowupid": options.sys_datafollowupid
  26. },
  27. }).then(res => {
  28. console.log("跟进详情", res)
  29. if (res.code != '1') {
  30. wx.showToast({
  31. title: res.msg,
  32. icon: "none"
  33. })
  34. setTimeout(() => {
  35. wx.navigateBack()
  36. }, 300)
  37. };
  38. this.setData({
  39. [`list[0].value`]: res.data.content,
  40. resource: res.data.resource
  41. })
  42. if (res.data.attinfos.length) this.selectComponent("#Yl_files").handleFiles(res.data.attinfos);
  43. this.data.content = Object.assign(res.data, options);
  44. })
  45. } else {
  46. options.sys_datafollowupid = 0;
  47. this.data.content = options;
  48. }
  49. },
  50. changeState({
  51. detail
  52. }) {
  53. this.setData({
  54. loading: detail
  55. })
  56. },
  57. onInput(e) {
  58. const {
  59. index
  60. } = e.target.dataset;
  61. this.data.list[index].value = e.detail.value;
  62. this.setData({
  63. list: this.data.list
  64. })
  65. },
  66. onVoiceInput(e) {
  67. let {
  68. index
  69. } = e.target.dataset;
  70. this.setData({
  71. [`list[${index}].value`]: e.detail
  72. })
  73. },
  74. /* 绑定媒体 */
  75. insertImgEdit({
  76. detail
  77. }) {
  78. this.handleFileLink(detail)
  79. },
  80. handleFileLink(attachmentids, ownertable = "temporary", ownerid = 1, data) {
  81. _Http.basic({
  82. "classname": "system.attachment.Attachment",
  83. "method": "createFileLink",
  84. "content": {
  85. ownertable,
  86. ownerid,
  87. usetype: 'default',
  88. attachmentids
  89. }
  90. }).then(res => {
  91. console.log('跟进记录绑定附件', res)
  92. if (res.code != '1') return wx.showToast({
  93. title: res.msg,
  94. icon: "none"
  95. })
  96. if (ownertable == 'temporary') {
  97. this.selectComponent("#Yl_files").handleFiles(res.data)
  98. } else {
  99. if (res.data.length) data.attinfos = res.data;
  100. _Http.basic({
  101. "classname": "system.attachment.Attachment",
  102. "method": "createFileLink",
  103. "content": {
  104. ownertable: this.data.ownertable,
  105. ownerid: this.data.ownerid,
  106. usetype: 'default',
  107. attachmentids
  108. }
  109. })
  110. this.changeItem(data)
  111. setTimeout(() => {
  112. wx.navigateBack()
  113. }, 500)
  114. }
  115. })
  116. },
  117. changeItem(data) {
  118. this.setData({
  119. loading: false
  120. })
  121. let page = getCurrentPages()[getCurrentPages().length - 2],
  122. isDetail = page.__route__ == 'prsx/trace/detail/index';
  123. if (isDetail) {
  124. page.getDetail();
  125. page = getCurrentPages()[getCurrentPages().length - 3];
  126. }
  127. let model = page.selectComponent("#Trace");
  128. if (this.data.content.sys_datafollowupid == 0) {
  129. if (page) {
  130. if (model) model.getList(0, true)
  131. }
  132. } else {
  133. let list = model.data.list,
  134. index = list.findIndex(v => v.sys_datafollowupid == data.sys_datafollowupid);
  135. if (index != -1) list[index] = data;
  136. model.setData({
  137. list
  138. })
  139. }
  140. },
  141. submit() {
  142. this.setData({
  143. loading: true
  144. })
  145. let content = Object.assign(this.data.content, this.selectComponent("#Form").submit())
  146. content.content = this.data.list[0].value;
  147. content.resource = this.data.resource || ''
  148. _Http.basic({
  149. "id": 20220930121601,
  150. content
  151. }).then(res => {
  152. console.log("保存跟进内容", res)
  153. this.setData({
  154. loading: false
  155. })
  156. wx.showToast({
  157. title: getApp().globalData.Language.getMapText(res.code != 1 ? res.msg : content.sys_datafollowupid == 0 ? '保存成功' : '修改成功'),
  158. icon: "none",
  159. mask: res.code != 1
  160. });
  161. if (res.msg != '成功') return;
  162. let attachmentids = this.selectComponent("#Yl_files").getFiles().attachmentids;
  163. if (attachmentids.length) return this.handleFileLink(attachmentids, 'sys_datafollowup', res.data.sys_datafollowupid, res.data);
  164. this.changeItem(res.data)
  165. setTimeout(() => {
  166. wx.navigateBack()
  167. }, 500)
  168. })
  169. },
  170. onUnload() {
  171. if (this.data.content.sys_datafollowupid == 0) this.selectComponent("#Yl_files").deleteAll()
  172. }
  173. })