upload.js 8.8 KB

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