upload.js 8.7 KB

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