upload.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const _Http = getApp().globalData.http,
  2. MFT = require("../../utils/matchingFeilType"),
  3. CF = require("../../utils/checkFile");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. "content": {
  10. "title": "",
  11. "sat_sharematerial_classid": 9999,
  12. "notes": "",
  13. "tag": [],
  14. "canfiledownload": 1,
  15. "content": "",
  16. "sat_sharematerialid": 0
  17. },
  18. detailsData: {},
  19. editRichText: false, //编辑富文本
  20. richTextFile: [],
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. _Http.basic({
  27. "classname": "webmanage.saletool.sharematerial.sharematerial",
  28. "method": "insertOrUpdate",
  29. content: this.data.content
  30. }).then(res => {
  31. console.log("新增", res)
  32. this.setData({
  33. detailsData: res.data[0]
  34. })
  35. })
  36. },
  37. getFile({
  38. detail
  39. }) {
  40. _Http.basic({
  41. "classname": "system.attachment.Attachment",
  42. "method": "createFileLink",
  43. "content": {
  44. "ownertable": "SAT_SHAREMATERIAL",
  45. "ownerid": this.data.detailsData.sat_sharematerialid,
  46. "usetype": "default",
  47. "attachmentids": detail
  48. }
  49. }).then(res => {
  50. if (res.msg != '成功') return wx.showToast({
  51. title: res.data,
  52. icon: "none"
  53. });
  54. this.setData({
  55. "detailsData.attinfos": this.data.detailsData.attinfos.concat(MFT.fileList(res.data))
  56. })
  57. })
  58. },
  59. titleInput({
  60. detail
  61. }) {
  62. this.setData({
  63. "content.title": detail.value.trim()
  64. })
  65. },
  66. openFile(e) {
  67. const {
  68. item
  69. } = e.currentTarget.dataset;
  70. CF.checkFile(item);
  71. },
  72. /* 打开编辑富文本 */
  73. openEditRichText() {
  74. this.setData({
  75. editRichText: !this.data.editRichText
  76. })
  77. },
  78. /* 得到编辑好的富文本内容 */
  79. getRichText({
  80. detail
  81. }) {
  82. this.setData({
  83. "content.content": detail
  84. })
  85. },
  86. deleteFile(e) {
  87. const {
  88. item,
  89. index
  90. } = e.currentTarget.dataset;
  91. const that = this;
  92. wx.showModal({
  93. title: '提示',
  94. content: "是否确认删除该文件?",
  95. success: async s => {
  96. if (!s.confirm) return;
  97. let res = await that.handleDelete([item.linksid]);
  98. if (res.msg != '成功') wx.showToast({
  99. title: res.data,
  100. });
  101. let attinfos = that.data.detailsData.attinfos;
  102. attinfos.splice(index, 1);
  103. that.setData({
  104. "detailsData.attinfos": attinfos
  105. });
  106. }
  107. })
  108. },
  109. handleDelete(linksids) {
  110. return _Http.basic({
  111. "classname": "system.attachment.Attachment",
  112. "method": "deleteFileLink",
  113. "content": {
  114. linksids
  115. }
  116. }).then(res => {
  117. console.log('删除附件', res)
  118. return res;
  119. })
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload() {
  125. if (this.data.detailsData.status == '新建') _Http.basic({
  126. "classname": "webmanage.saletool.sharematerial.sharematerial",
  127. "method": "delete",
  128. "content": {
  129. "sat_sharematerialid": this.data.detailsData.sat_sharematerialid
  130. }
  131. }).then(res => {
  132. console.log("删除", res)
  133. });
  134. let attinfos = this.data.detailsData.attinfos;
  135. if (attinfos.length) {
  136. let linksids = [];
  137. for (let i = 0; i < attinfos.length; i++) {
  138. linksids.push(attinfos[i].linksid)
  139. };
  140. this.handleDelete(linksids)
  141. }
  142. },
  143. })