index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. })
  41. if (res.data.attinfos.length) this.selectComponent("#Yl_files").handleFiles(res.data.attinfos);
  42. this.data.content = Object.assign(res.data, options);
  43. })
  44. } else {
  45. options.sys_datafollowupid = 0;
  46. this.data.content = options;
  47. }
  48. },
  49. changeState({
  50. detail
  51. }) {
  52. this.setData({
  53. loading: detail
  54. })
  55. },
  56. onInput(e) {
  57. const {
  58. index
  59. } = e.target.dataset;
  60. this.data.list[index].value = e.detail.value;
  61. this.setData({
  62. list: this.data.list
  63. })
  64. },
  65. onVoiceInput(e) {
  66. let {
  67. index
  68. } = e.target.dataset;
  69. this.setData({
  70. [`list[${index}].value`]: e.detail
  71. })
  72. },
  73. /* 绑定媒体 */
  74. insertImgEdit({
  75. detail
  76. }) {
  77. this.handleFileLink(detail)
  78. },
  79. handleFileLink(attachmentids, ownertable = "temporary", ownerid = 1, data) {
  80. _Http.basic({
  81. "classname": "system.attachment.Attachment",
  82. "method": "createFileLink",
  83. "content": {
  84. ownertable,
  85. ownerid,
  86. usetype: 'default',
  87. attachmentids
  88. }
  89. }).then(res => {
  90. console.log('跟进记录绑定附件', res)
  91. if (res.code != '1') return wx.showToast({
  92. title: res.msg,
  93. icon: "none"
  94. })
  95. if (ownertable == 'temporary') {
  96. this.selectComponent("#Yl_files").handleFiles(res.data)
  97. } else {
  98. if (res.data.length) data.attinfos = res.data;
  99. this.changeItem(data)
  100. setTimeout(() => {
  101. wx.navigateBack()
  102. }, 500)
  103. }
  104. })
  105. },
  106. changeItem(data) {
  107. this.setData({
  108. loading: false
  109. })
  110. let page = getCurrentPages()[getCurrentPages().length - 2],
  111. isDetail = page.__route__ == 'packageA/setclient/modules/trace/detail/index';
  112. if (isDetail) {
  113. page.getDetail();
  114. page = getCurrentPages()[getCurrentPages().length - 3];
  115. }
  116. let model = page.selectComponent("#Trace");
  117. if (this.data.content.sys_datafollowupid == 0) {
  118. if (page) {
  119. if (model) model.getList(0, true)
  120. }
  121. } else {
  122. let list = model.data.list,
  123. index = list.findIndex(v => v.sys_datafollowupid == data.sys_datafollowupid);
  124. if (index != -1) list[index] = data;
  125. model.setData({
  126. list
  127. })
  128. }
  129. },
  130. submit() {
  131. this.setData({
  132. loading: true
  133. })
  134. let content = Object.assign(this.data.content, this.selectComponent("#Form").submit())
  135. content.content = this.data.list[0].value;
  136. _Http.basic({
  137. "id": 20220930121601,
  138. content
  139. }).then(res => {
  140. console.log("保存跟进内容", res)
  141. this.setData({
  142. loading: false
  143. })
  144. wx.showToast({
  145. title: getApp().globalData.Language.getMapText(res.code != 1 ? res.msg : content.sys_datafollowupid == 0 ? '保存成功' : '修改成功'),
  146. icon: "none",
  147. mask: res.code != 1
  148. });
  149. if (res.msg != '成功') return;
  150. let attachmentids = this.selectComponent("#Yl_files").getFiles().attachmentids;
  151. if (attachmentids.length) return this.handleFileLink(attachmentids, 'sys_datafollowup', res.data.sys_datafollowupid, res.data);
  152. this.changeItem(res.data)
  153. setTimeout(() => {
  154. wx.navigateBack()
  155. }, 500)
  156. })
  157. },
  158. onUnload() {
  159. if (this.data.content.sys_datafollowupid == 0) this.selectComponent("#Yl_files").deleteAll()
  160. }
  161. })