upload.js 8.9 KB

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