viewPage.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. const getHeight = require("../../../../utils/getRheRemainingHeight");
  2. const _Http = getApp().globalData.http;
  3. const MFT = require("../../../../utils/matchingFeilType");
  4. let dowmCount = null;
  5. Component({
  6. properties: {
  7. padBot: {
  8. type: Boolean,
  9. value: true
  10. }
  11. },
  12. options: {
  13. addGlobalClass: true
  14. },
  15. lifetimes: {
  16. ready() {
  17. this.getList();
  18. getHeight.getHeight('.tabs', this).then(res => {
  19. this.setData({
  20. listHeight: res
  21. })
  22. });
  23. }
  24. },
  25. data: {
  26. listHeight: 0, //列表高度
  27. tabActiveTitle: "列表", //列表类型
  28. show: false, //显示底部弹出
  29. fileSelected: {}, //选中文件详情
  30. content: { //请求搜索条件
  31. "nocache": true,
  32. "pageNumber": 1,
  33. "pageSize": 20,
  34. "parentid": "默认",
  35. "pageTotal": 1,
  36. "where": {
  37. "condition": ""
  38. }
  39. },
  40. list: [], //文件列表
  41. inTotal: 0, //总计
  42. sort: [], //排序规则
  43. },
  44. methods: {
  45. /* 是否收藏 */
  46. changeCollect() {
  47. const {
  48. isCollect,
  49. attachmentid,
  50. rowindex
  51. } = this.data.fileSelected;
  52. _Http.basic({
  53. "classname": "system.attachment.MediaCenter",
  54. "method": isCollect == 0 ? "collectAttachment" : "uncollectAttachment",
  55. "content": {
  56. "collecttype": "营销物料",
  57. "attachmentid": attachmentid
  58. }
  59. }).then(res => {
  60. if (res.msg != '成功') return wx.showToast({
  61. title: res.msg,
  62. icon: "none"
  63. })
  64. wx.showToast({
  65. title: isCollect == 0 ? '收藏成功' : "已取消收藏",
  66. icon: "none"
  67. })
  68. let list = this.data.list,
  69. index = rowindex - 1;
  70. this.data.tabActiveTitle == '列表' ? list[index].isCollect = isCollect == 0 ? 1 : 0 : list.splice(index, 1);
  71. this.setData({
  72. list
  73. })
  74. this.closeShow();
  75. })
  76. },
  77. mySaveVideo() {
  78. const that = this,
  79. fileSelected = this.data.fileSelected;
  80. const downloadTask = wx.downloadFile({
  81. url: fileSelected.url,
  82. // filePath: wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4',
  83. timeout: 6000000,
  84. success(res) {
  85. console.log("下载", res)
  86. // that.saveVideo(res.filePath)
  87. // 下载完成后转发
  88. wx.shareVideoMessage({
  89. videoPath: res.tempFilePath,
  90. fail(err) {
  91. console.log("转发", err)
  92. wx.showToast({
  93. title: `转发失败:${err.errMsg}`,
  94. icon: "none"
  95. })
  96. }
  97. })
  98. },
  99. fail(err) {
  100. console.log("下载失败", err)
  101. wx.showToast({
  102. title: `下载失败:${err.errMsg}`,
  103. icon: "none"
  104. })
  105. if (err.errMsg == 'downloadFile:fail exceed max file size') wx.showToast({
  106. title: '视频体积超大,无法保存!请尝试打开视频长按保存下载',
  107. icon: "none"
  108. })
  109. }
  110. })
  111. downloadTask.onProgressUpdate((res) => {
  112. wx.showLoading({
  113. title: res.progress + `%`,
  114. mask: true
  115. })
  116. if (res.progress == 100) wx.hideLoading()
  117. })
  118. that.closeShow();
  119. /* const downloadTask = wx.downloadFile({
  120. url: fileSelected.url,
  121. filePath: wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4',
  122. timeout: 6000000,
  123. success(res) {
  124. console.log("下载", res)
  125. that.saveVideo(res.filePath)
  126. },
  127. fail(err) {
  128. console.log("下载失败", err)
  129. wx.showModal({
  130. title: '提示',
  131. content: `下载失败:${err}`,
  132. })
  133. if (err.errMsg == 'downloadFile:fail exceed max file size') wx.showToast({
  134. title: '视频体积超大,无法保存!请尝试打开视频长按保存下载',
  135. icon: "none"
  136. })
  137. }
  138. })
  139. downloadTask.onProgressUpdate((res) => {
  140. wx.showLoading({
  141. title: `保存进度` + res.progress + `%`,
  142. mask: true
  143. })
  144. if (res.progress == 100) wx.hideLoading()
  145. })
  146. that.closeShow(); */
  147. },
  148. /* 文件下载 */
  149. dowmLoad() {
  150. const that = this,
  151. fileSelected = this.data.fileSelected;
  152. wx.setClipboardData({
  153. data: fileSelected.url,
  154. success: function () {
  155. wx.showToast({
  156. title: '复制成功,将链接放置到浏览器中便可下载文件',
  157. icon: "none",
  158. duration: 3000
  159. });
  160. that.closeShow();
  161. },fail(err){
  162. console.log("复制文件报错",err)
  163. }
  164. })
  165. },
  166. saveVideo(filePath) {
  167. const that = this;
  168. wx.saveVideoToPhotosAlbum({
  169. filePath,
  170. success(res) {
  171. console.log("保存", res)
  172. wx.showModal({
  173. title: '提示',
  174. content: '视频已保存到系统相册',
  175. showCancel: false
  176. })
  177. wx.hideLoading()
  178. },
  179. fail(err) {
  180. console.log("保存失败", err)
  181. if (err.errno == 103) {
  182. wx.showModal({
  183. title: '提示',
  184. content: '未获取保存相册权限,无法保存!',
  185. confirmText: "前去授权",
  186. success({
  187. confirm
  188. }) {
  189. if (confirm) wx.openSetting({
  190. success(res) {
  191. console.log(res.authSetting["scope.writePhotosAlbum"])
  192. if (res.authSetting["scope.writePhotosAlbum"]) {
  193. that.saveVideo(filePath)
  194. } else {
  195. wx.showToast({
  196. title: '未获得授权',
  197. icon: "none"
  198. })
  199. }
  200. }
  201. })
  202. }
  203. })
  204. } else {
  205. wx.showToast({
  206. title: err,
  207. icon: "none"
  208. })
  209. }
  210. }
  211. })
  212. },
  213. /* 获得列表 */
  214. getList(init = false) {
  215. if (init.detail != undefined) init = init.detail;
  216. if (init) this.setData({
  217. ['content.pageNumber']: 1
  218. })
  219. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  220. let content = this.data.content;
  221. if (content.parentid == '默认') content.parentid = wx.getStorageSync('siteP').salematerialfolderid;
  222. if (this.data.sort[0]) content.sort = this.data.sort;
  223. _Http.basic({
  224. "classname": "saletool.salematerial.salematerial",
  225. "method": (this.data.tabActiveTitle == '列表') ? "selectList" : "selectMyList",
  226. content
  227. }).then(res => {
  228. console.log("文件列表", res)
  229. this.selectComponent('#ListBox').RefreshToComplete();
  230. if (res.msg != '成功') return wx.showToast({
  231. title: res.msg,
  232. icon: "none"
  233. })
  234. this.setData({
  235. list: (res.pageNumber == 1) ? MFT.fileList(res.data) : this.data.list.concat(MFT.fileList(res.data)),
  236. ['content.pageNumber']: res.pageNumber + 1,
  237. ['content.pageTotal']: res.pageTotal,
  238. inTotal: res.total,
  239. sort: res.sort
  240. })
  241. })
  242. },
  243. /* 搜索框输入 */
  244. searchInput({
  245. detail
  246. }) {
  247. clearTimeout(dowmCount);
  248. this.setData({
  249. ['content.where.condition']: detail.trim()
  250. })
  251. dowmCount = setTimeout(() => {
  252. this.getList(true)
  253. }, 1000);
  254. },
  255. /* 清除搜索输入 */
  256. searchClear() {
  257. this.setData({
  258. ['content.where.condition']: ""
  259. })
  260. },
  261. /* tab切换 */
  262. tabsChange({
  263. detail
  264. }) {
  265. this.setData({
  266. tabActiveTitle: detail.title
  267. })
  268. this.getList(true);
  269. },
  270. /* 开关切换 */
  271. changeSwitch({
  272. detail
  273. }) {
  274. this.setData({
  275. sort: detail
  276. })
  277. this.getList(true);
  278. },
  279. /* 修改ID */
  280. changeParentid(id) {
  281. this.setData({
  282. ['content.parentid']: id
  283. })
  284. },
  285. /* 修改选中ID */
  286. changeId({
  287. detail
  288. }) {
  289. this.setData({
  290. fileSelected: detail,
  291. show: true
  292. })
  293. },
  294. /* 关闭修改 */
  295. closeShow() {
  296. this.setData({
  297. show: false
  298. })
  299. setTimeout(() => {
  300. this.setData({
  301. fileSelected: {}
  302. })
  303. }, 150)
  304. },
  305. }
  306. })