upload.js 8.7 KB

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