index.js 5.9 KB

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