viewPage.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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: 600000,
  84. success(res) {
  85. console.log("下载", res)
  86. that.saveVideo(res.filePath)
  87. },
  88. fail({
  89. errMsg
  90. }) {
  91. if (errMsg == 'downloadFile:fail exceed max file size') wx.showToast({
  92. title: '视频体积超大,无法保存!请尝试打开视频长按保存下载',
  93. icon: "none"
  94. })
  95. }
  96. })
  97. downloadTask.onProgressUpdate((res) => {
  98. wx.showLoading({
  99. title: `保存进度` + res.progress + `%`,
  100. mask: true
  101. })
  102. if (res.progress == 100) wx.hideLoading()
  103. })
  104. that.closeShow();
  105. },
  106. /* 文件下载 */
  107. dowmLoad() {
  108. const that = this,
  109. fileSelected = this.data.fileSelected;
  110. wx.setClipboardData({
  111. data: fileSelected.url,
  112. success: function () {
  113. wx.showToast({
  114. title: '复制成功,将链接放置到浏览器中便可下载文件',
  115. icon: "none",
  116. duration: 3000
  117. });
  118. that.closeShow();
  119. }
  120. })
  121. },
  122. saveVideo(filePath) {
  123. const that = this;
  124. wx.saveVideoToPhotosAlbum({
  125. filePath,
  126. success(res) {
  127. console.log("保存", res)
  128. wx.showModal({
  129. title: '提示',
  130. content: '视频已保存到系统相册',
  131. showCancel: false
  132. })
  133. wx.hideLoading()
  134. },
  135. fail(err) {
  136. console.log("保存失败", err)
  137. if (err.errno == 103) {
  138. wx.showModal({
  139. title: '提示',
  140. content: '未获取保存相册权限,无法保存!',
  141. confirmText: "前去授权",
  142. success({
  143. confirm
  144. }) {
  145. if (confirm) wx.openSetting({
  146. success(res) {
  147. console.log(res.authSetting["scope.writePhotosAlbum"])
  148. if (res.authSetting["scope.writePhotosAlbum"]) {
  149. that.saveVideo(filePath)
  150. } else {
  151. wx.showToast({
  152. title: '未获得授权',
  153. icon: "none"
  154. })
  155. }
  156. }
  157. })
  158. }
  159. })
  160. }
  161. }
  162. })
  163. },
  164. /* 获得列表 */
  165. getList(init = false) {
  166. if (init.detail != undefined) init = init.detail;
  167. if (init) this.setData({
  168. ['content.pageNumber']: 1
  169. })
  170. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  171. let content = this.data.content;
  172. if (content.parentid == '默认') content.parentid = wx.getStorageSync('siteP').salematerialfolderid;
  173. if (this.data.sort[0]) content.sort = this.data.sort;
  174. _Http.basic({
  175. "classname": "saletool.salematerial.salematerial",
  176. "method": (this.data.tabActiveTitle == '列表') ? "selectList" : "selectMyList",
  177. content
  178. }).then(res => {
  179. this.selectComponent('#ListBox').RefreshToComplete();
  180. if (res.msg != '成功') return wx.showToast({
  181. title: res.msg,
  182. icon: "none"
  183. })
  184. this.setData({
  185. list: (res.pageNumber == 1) ? MFT.fileList(res.data) : this.data.list.concat(MFT.fileList(res.data)),
  186. ['content.pageNumber']: res.pageNumber + 1,
  187. ['content.pageTotal']: res.pageTotal,
  188. inTotal: res.total,
  189. sort: res.sort
  190. })
  191. })
  192. },
  193. /* 搜索框输入 */
  194. searchInput({
  195. detail
  196. }) {
  197. clearTimeout(dowmCount);
  198. this.setData({
  199. ['content.where.condition']: detail.trim()
  200. })
  201. dowmCount = setTimeout(() => {
  202. this.getList(true)
  203. }, 1000);
  204. },
  205. /* 清除搜索输入 */
  206. searchClear() {
  207. this.setData({
  208. ['content.where.condition']: ""
  209. })
  210. },
  211. /* tab切换 */
  212. tabsChange({
  213. detail
  214. }) {
  215. this.setData({
  216. tabActiveTitle: detail.title
  217. })
  218. this.getList(true);
  219. },
  220. /* 开关切换 */
  221. changeSwitch({
  222. detail
  223. }) {
  224. this.setData({
  225. sort: detail
  226. })
  227. this.getList(true);
  228. },
  229. /* 修改ID */
  230. changeParentid(id) {
  231. this.setData({
  232. ['content.parentid']: id
  233. })
  234. },
  235. /* 修改选中ID */
  236. changeId({
  237. detail
  238. }) {
  239. this.setData({
  240. fileSelected: detail,
  241. show: true
  242. })
  243. },
  244. /* 关闭修改 */
  245. closeShow() {
  246. this.setData({
  247. show: false
  248. })
  249. setTimeout(() => {
  250. this.setData({
  251. fileSelected: {}
  252. })
  253. }, 150)
  254. },
  255. }
  256. })