upload.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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' + wx.getStorageSync('userMsg').userid) 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. this.setData({
  93. loading: false
  94. })
  95. if (res.msg != '成功') return wx.showToast({
  96. title: res.msg,
  97. icon: "none"
  98. });
  99. this.setData({
  100. detailsData: res.data
  101. })
  102. wx.showToast({
  103. title: "保存成功",
  104. });
  105. this.setData({
  106. "detailsData.status": "审核"
  107. })
  108. setTimeout(() => {
  109. let pages = getCurrentPages();
  110. let prevPage = pages[pages.length - 2];
  111. prevPage.getList(true);
  112. wx.navigateBack({
  113. delta: 0,
  114. })
  115. }, 300)
  116. })
  117. },
  118. openSelect() {
  119. this.setData({
  120. selectShow: true
  121. })
  122. },
  123. onClose() {
  124. this.setData({
  125. selectShow: false
  126. })
  127. },
  128. /* 查询分类 */
  129. selectMenu(index = 0, res) {
  130. if (index == 5) return wx.showToast({
  131. title: res.msg,
  132. icon: "none"
  133. });
  134. _Http.basic({
  135. "classname": "saletool.sharematerial.sharematerial",
  136. "method": "select",
  137. "content": {
  138. "nocache": true,
  139. "parentid": 0
  140. }
  141. }).then(res => {
  142. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  143. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  144. this.setData({
  145. items: JSON.parse(str)
  146. });
  147. });
  148. },
  149. /* 切换分类 */
  150. onClickItem({
  151. detail = {}
  152. }) {
  153. this.setData({
  154. "content.sat_sharematerial_classid": detail.id,
  155. activeName: detail.text
  156. });
  157. this.onClose();
  158. },
  159. onClickNav({
  160. detail = {}
  161. }) {
  162. this.setData({
  163. mainActiveIndex: detail.index || 0,
  164. });
  165. },
  166. /* 上传文件 */
  167. getFile({
  168. detail
  169. }) {
  170. _Http.basic({
  171. "classname": "system.attachment.Attachment",
  172. "method": "createFileLink",
  173. "content": {
  174. "ownertable": "SAT_SHAREMATERIAL",
  175. "ownerid": this.data.detailsData.sat_sharematerialid,
  176. "usetype": "default",
  177. "attachmentids": detail
  178. }
  179. }).then(res => {
  180. console.log("上传成功", res)
  181. if (res.msg != '成功') return wx.showToast({
  182. title: res.msg,
  183. icon: "none"
  184. });
  185. this.setData({
  186. "detailsData.attinfos": this.data.detailsData.attinfos.concat(MFT.fileList(res.data))
  187. })
  188. })
  189. },
  190. titleInput({
  191. detail
  192. }) {
  193. this.setData({
  194. "content.title": deleteMark.queryStr(detail.value).trim()
  195. })
  196. },
  197. openFile(e) {
  198. const {
  199. item
  200. } = e.currentTarget.dataset;
  201. CF.checkFile(item);
  202. },
  203. /* 打开编辑富文本 */
  204. openEditRichText() {
  205. this.setData({
  206. editRichText: !this.data.editRichText
  207. })
  208. },
  209. /* 得到编辑好的富文本内容 */
  210. getRichText({
  211. detail
  212. }) {
  213. this.setData({
  214. "content.content": detail
  215. })
  216. },
  217. deleteFile(e) {
  218. const {
  219. item,
  220. index
  221. } = e.currentTarget.dataset;
  222. const that = this;
  223. wx.showModal({
  224. title: '提示',
  225. content: "是否确认删除该文件?",
  226. success: async s => {
  227. if (!s.confirm) return;
  228. let res = await that.handleDelete([item.linksid]);
  229. if (res.msg != '成功') wx.showToast({
  230. title: res.msg,
  231. });
  232. let attinfos = that.data.detailsData.attinfos;
  233. attinfos.splice(index, 1);
  234. that.setData({
  235. "detailsData.attinfos": attinfos
  236. });
  237. }
  238. })
  239. },
  240. handleDelete(linksids) {
  241. return _Http.basic({
  242. "classname": "system.attachment.Attachment",
  243. "method": "deleteFileLink",
  244. "content": {
  245. linksids: linksids
  246. }
  247. }).then(res => {
  248. console.log('删除附件', res)
  249. return res;
  250. })
  251. },
  252. /**
  253. * 生命周期函数--监听页面卸载
  254. */
  255. onUnload() {
  256. console.log(this.data.detailsData.sat_sharematerial_classid)
  257. if (this.data.detailsData.sat_sharematerial_classid != '9999' + wx.getStorageSync('userMsg').userid) return;
  258. _Http.basic({
  259. "classname": "webmanage.saletool.sharematerial.sharematerial",
  260. "method": "delete",
  261. "content": {
  262. "sat_sharematerialid": [this.data.detailsData.sat_sharematerialid]
  263. }
  264. }).then(res => {
  265. console.log("删除", res)
  266. });
  267. let attinfos = this.data.detailsData.attinfos;
  268. if (attinfos.length) {
  269. let linksids = [];
  270. for (let i = 0; i < attinfos.length; i++) {
  271. linksids.push(attinfos[i].linksid)
  272. };
  273. this.handleDelete(linksids)
  274. }
  275. },
  276. })