add.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. const _Http = getApp().globalData.http,
  2. MFT = require("../../../../utils/matchingFeilType");
  3. Page({
  4. data: {
  5. detail: null,
  6. isFollow: false,
  7. isSubmit: true, //是否可以提交
  8. files: {
  9. images: [],
  10. viewImages: [],
  11. videos: [],
  12. viewVideos: [],
  13. files: []
  14. },
  15. },
  16. onLoad(options) {
  17. this.setData({
  18. detail: JSON.parse(options.data),
  19. isFollow: options.isFollow == 'true'
  20. });
  21. if (this.data.detail.attinfos.length != 0) this.handleFiles(MFT.fileList(this.data.detail.attinfos))
  22. if (this.data.detail.notes != '' && this.data.isFollow) this.setData({
  23. isSubmit: false
  24. })
  25. },
  26. /* 删除文件 */
  27. deleteFile({
  28. detail
  29. }) {
  30. let e = detail,
  31. item = e.detail.attachmentid ? e.detail : e.currentTarget.dataset.item;
  32. _Http.basic({
  33. "classname": "system.attachment.Attachment",
  34. "method": "deleteFileLink",
  35. "content": {
  36. "linksids": [item.linksid]
  37. }
  38. }).then(res => {
  39. if (res.msg != '成功') return wx.showToast({
  40. title: res.data,
  41. icon: "none"
  42. });
  43. let files = this.data.files;
  44. switch (item.fileType) {
  45. case "image":
  46. files.images = files.images.filter(v => v.url != item.url);
  47. files.viewImages = files.viewImages.filter(v => v.url != item.url);
  48. break;
  49. case "video":
  50. files.videos = files.videos.filter(v => v.url != item.url);
  51. files.viewVideos = files.viewVideos.filter(v => v.url != item.url);
  52. break;
  53. default:
  54. files.files = files.files.filter(v => v.attachmentid != item.attachmentid);
  55. break;
  56. };
  57. this.setData({
  58. files,
  59. "detail.attinfos": this.data.detail.attinfos.filter(v => v.url != item.url)
  60. });
  61. this.changeFile();
  62. })
  63. },
  64. //文本域输入
  65. onInput(e) {
  66. this.setData({
  67. "detail.notes": e.detail.value
  68. })
  69. },
  70. /* 绑定媒体 */
  71. insertImgEdit({
  72. detail
  73. }) {
  74. _Http.basic({
  75. "classname": "system.attachment.Attachment",
  76. "method": "createFileLink",
  77. "content": {
  78. "ownertable": "sa_project_stagework",
  79. "ownerid": this.data.detail.sa_project_stageworkid,
  80. "usetype": "default",
  81. "attachmentids": detail
  82. }
  83. }).then(res => {
  84. console.log('跟进记录绑定附件', res)
  85. if (res.msg != '成功') return wx.showToast({
  86. title: res.data,
  87. icon: "none"
  88. })
  89. this.handleFiles(MFT.fileList(res.data));
  90. this.data.detail.attinfos.push(res.data[0])
  91. this.changeFile();
  92. })
  93. },
  94. /* 处理附件 */
  95. handleFiles(list) {
  96. let files = this.data.files;
  97. list.forEach(v => {
  98. switch (v.fileType) {
  99. case "video":
  100. files.videos.push(v)
  101. files.viewVideos.push({
  102. url: v.url,
  103. type: "video",
  104. poster: v.subfiles[0].url
  105. })
  106. break;
  107. case "image":
  108. files.images.push(v)
  109. files.viewImages.push({
  110. url: v.url,
  111. type: "image"
  112. })
  113. break;
  114. default:
  115. files.files.push(v)
  116. break;
  117. }
  118. });
  119. this.setData({
  120. files
  121. })
  122. },
  123. /* 修改源文件附件 */
  124. changeFile() {
  125. let pages = getCurrentPages(),
  126. page = pages[pages.length - 2].selectComponent("#Task"),
  127. i = page.data.list[page.data.viewIndex].work.findIndex(v => v.sa_project_stageworkid == this.data.detail.sa_project_stageworkid);
  128. page.setData({
  129. [`list[${page.data.viewIndex}].work[${i}].attinfos`]: this.data.detail.attinfos
  130. })
  131. },
  132. /* 保存 */
  133. save() {
  134. _Http.basic({
  135. "id": 20221024160202,
  136. "content": {
  137. sa_project_stageworkid: this.data.detail.sa_project_stageworkid,
  138. notes: this.data.detail.notes,
  139. }
  140. }).then(res => {
  141. wx.showToast({
  142. title: res.msg == '成功' ? '保存成功' : res.data,
  143. icon: "none"
  144. });
  145. if (res.msg != '成功') return;
  146. this.setData({
  147. isSubmit: false
  148. })
  149. let pages = getCurrentPages(),
  150. page = pages[pages.length - 2].selectComponent("#Task"),
  151. i = page.data.list[page.data.viewIndex].work.findIndex(v => v.sa_project_stageworkid == this.data.detail.sa_project_stageworkid);
  152. page.setData({
  153. [`list[${page.data.viewIndex}].work[${i}].notes`]: this.data.detail.notes
  154. })
  155. })
  156. },
  157. /* 提交 */
  158. submit() {
  159. let that = this;
  160. wx.showModal({
  161. title: '提示',
  162. content: `是否提交该任务,提交后将计算分值(仅可提交一次)`,
  163. complete: ({
  164. confirm
  165. }) => {
  166. if (confirm) _Http.basic({
  167. "id": 20221024160302,
  168. "content": {
  169. "sa_project_stageworkid": that.data.detail.sa_project_stageworkid
  170. }
  171. }).then(res => {
  172. console.log("任务提交", res)
  173. if (res.msg != '成功') return wx.showToast({
  174. title: res.data,
  175. icon: "none"
  176. });
  177. let pages = getCurrentPages(),
  178. page = pages[pages.length - 2].selectComponent("#Task");
  179. pages[pages.length - 2].getDetail();
  180. page.getList();
  181. wx.showToast({
  182. title: '提交成功',
  183. icon: "none"
  184. });
  185. that.setData({
  186. "detail.finished": 1
  187. })
  188. })
  189. }
  190. })
  191. }
  192. })