upload.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. items: [],
  22. activeName: "",
  23. activeId: "",
  24. selectShow: false,
  25. loading: false
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. if (options.item) {
  32. this.setData({
  33. items: JSON.parse(options.item)
  34. })
  35. } else {
  36. this.selectMenu();
  37. };
  38. _Http.basic({
  39. "classname": "webmanage.saletool.sharematerial.sharematerial",
  40. "method": "insertOrUpdate",
  41. content: this.data.content
  42. }).then(res => {
  43. console.log("新增", res)
  44. this.setData({
  45. detailsData: res.data[0],
  46. "content.sat_sharematerialid": res.data[0].sat_sharematerialid
  47. })
  48. })
  49. },
  50. submit() {
  51. let content = this.data.content;
  52. if (content.title == '' || content.sat_sharematerial_classid == 9999) return wx.showToast({
  53. title: '请检查素材标题或所属分类',
  54. icon: "none"
  55. });
  56. if (this.data.loading || this.data.detailsData.status == "审核") return wx.showToast({
  57. title: '正在提交中',
  58. icon: "none"
  59. });
  60. this.setData({
  61. loading: true
  62. })
  63. content.content = encodeURIComponent(content.content);
  64. _Http.basic({
  65. "classname": "webmanage.saletool.sharematerial.sharematerial",
  66. "method": "insertOrUpdate",
  67. content: content
  68. }).then(res => {
  69. if (res.msg != '成功') {
  70. wx.showToast({
  71. title: res.data,
  72. icon: "none"
  73. });
  74. this.setData({
  75. loading: false
  76. })
  77. return;
  78. }
  79. this.setData({
  80. detailsData: res.data[0]
  81. })
  82. _Http.basic({
  83. "classname": "webmanage.saletool.sharematerial.sharematerial",
  84. "method": "audit",
  85. "content": {
  86. "sat_sharematerialid": res.data[0].sat_sharematerialid,
  87. "type": 1
  88. }
  89. }).then(s => {
  90. this.setData({
  91. loading: false
  92. })
  93. if (res.msg != '成功') return wx.showToast({
  94. title: "保存失败,请重新尝试",
  95. icon: "none"
  96. });
  97. wx.showToast({
  98. title: "修改成功",
  99. });
  100. this.setData({
  101. "detailsData.status": "审核"
  102. })
  103. let pages = getCurrentPages();
  104. let prevPage = pages[pages.length - 2];
  105. prevPage.getList(true);
  106. setTimeout(() => {
  107. wx.navigateBack({
  108. delta: 0,
  109. })
  110. }, 300)
  111. })
  112. })
  113. },
  114. openSelect() {
  115. this.setData({
  116. selectShow: true
  117. })
  118. },
  119. onClose() {
  120. this.setData({
  121. selectShow: false
  122. })
  123. },
  124. /* 查询分类 */
  125. selectMenu(index = 0, res) {
  126. if (index == 5) return wx.showToast({
  127. title: res.data,
  128. icon: "none"
  129. });
  130. _Http.basic({
  131. "classname": "saletool.sharematerial.sharematerial",
  132. "method": "select",
  133. "content": {
  134. "parentid": 0
  135. }
  136. }).then(res => {
  137. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  138. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  139. this.setData({
  140. items: JSON.parse(str)
  141. });
  142. });
  143. },
  144. /* 切换分类 */
  145. onClickItem({
  146. detail = {}
  147. }) {
  148. this.setData({
  149. "content.sat_sharematerial_classid": detail.id,
  150. activeName: detail.text
  151. });
  152. this.onClose();
  153. },
  154. onClickNav({
  155. detail = {}
  156. }) {
  157. this.setData({
  158. mainActiveIndex: detail.index || 0,
  159. });
  160. },
  161. /* 上传文件 */
  162. getFile({
  163. detail
  164. }) {
  165. _Http.basic({
  166. "classname": "system.attachment.Attachment",
  167. "method": "createFileLink",
  168. "content": {
  169. "ownertable": "SAT_SHAREMATERIAL",
  170. "ownerid": this.data.detailsData.sat_sharematerialid,
  171. "usetype": "default",
  172. "attachmentids": detail
  173. }
  174. }).then(res => {
  175. console.log("上传成功", res)
  176. if (res.msg != '成功') return wx.showToast({
  177. title: res.msg,
  178. icon: "none"
  179. });
  180. this.setData({
  181. "detailsData.attinfos": this.data.detailsData.attinfos.concat(MFT.fileList(res.data))
  182. })
  183. })
  184. },
  185. titleInput({
  186. detail
  187. }) {
  188. this.setData({
  189. "content.title": detail.value.trim()
  190. })
  191. },
  192. openFile(e) {
  193. const {
  194. item
  195. } = e.currentTarget.dataset;
  196. CF.checkFile(item);
  197. },
  198. /* 打开编辑富文本 */
  199. openEditRichText() {
  200. this.setData({
  201. editRichText: !this.data.editRichText
  202. })
  203. },
  204. /* 得到编辑好的富文本内容 */
  205. getRichText({
  206. detail
  207. }) {
  208. this.setData({
  209. "content.content": detail
  210. })
  211. },
  212. deleteFile(e) {
  213. const {
  214. item,
  215. index
  216. } = e.currentTarget.dataset;
  217. const that = this;
  218. wx.showModal({
  219. title: '提示',
  220. content: "是否确认删除该文件?",
  221. success: async s => {
  222. if (!s.confirm) return;
  223. let res = await that.handleDelete([item.linksid]);
  224. if (res.msg != '成功') wx.showToast({
  225. title: res.data,
  226. });
  227. let attinfos = that.data.detailsData.attinfos;
  228. attinfos.splice(index, 1);
  229. that.setData({
  230. "detailsData.attinfos": attinfos
  231. });
  232. }
  233. })
  234. },
  235. handleDelete(linksids) {
  236. return _Http.basic({
  237. "classname": "system.attachment.Attachment",
  238. "method": "deleteFileLink",
  239. "content": {
  240. linksids
  241. }
  242. }).then(res => {
  243. console.log('删除附件', res)
  244. return res;
  245. })
  246. },
  247. /**
  248. * 生命周期函数--监听页面卸载
  249. */
  250. onUnload() {
  251. if (this.data.detailsData.status != '新建') return;
  252. _Http.basic({
  253. "classname": "webmanage.saletool.sharematerial.sharematerial",
  254. "method": "delete",
  255. "content": {
  256. "sat_sharematerialid": this.data.detailsData.sat_sharematerialid
  257. }
  258. }).then(res => {
  259. console.log("删除", res)
  260. });
  261. let attinfos = this.data.detailsData.attinfos;
  262. if (attinfos.length) {
  263. let linksids = [];
  264. for (let i = 0; i < attinfos.length; i++) {
  265. linksids.push(attinfos[i].linksid)
  266. };
  267. this.handleDelete(linksids)
  268. }
  269. },
  270. })