123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- const getHeight = require("../../../../utils/getRheRemainingHeight");
- const _Http = getApp().globalData.http;
- const MFT = require("../../../../utils/matchingFeilType");
- let dowmCount = null;
- Component({
- properties: {
- padBot: {
- type: Boolean,
- value: true
- }
- },
- options: {
- addGlobalClass: true
- },
- lifetimes: {
- ready() {
- this.getList();
- getHeight.getHeight('.tabs', this).then(res => {
- this.setData({
- listHeight: res
- })
- });
- }
- },
- data: {
- listHeight: 0, //列表高度
- tabActiveTitle: "列表", //列表类型
- show: false, //显示底部弹出
- fileSelected: {}, //选中文件详情
- content: { //请求搜索条件
- "nocache": true,
- "pageNumber": 1,
- "pageSize": 20,
- "parentid": "默认",
- "pageTotal": 1,
- "where": {
- "condition": ""
- }
- },
- list: [], //文件列表
- inTotal: 0, //总计
- sort: [], //排序规则
- },
- methods: {
- /* 是否收藏 */
- changeCollect() {
- const {
- isCollect,
- attachmentid,
- rowindex
- } = this.data.fileSelected;
- _Http.basic({
- "classname": "system.attachment.MediaCenter",
- "method": isCollect == 0 ? "collectAttachment" : "uncollectAttachment",
- "content": {
- "collecttype": "营销物料",
- "attachmentid": attachmentid
- }
- }).then(res => {
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- wx.showToast({
- title: isCollect == 0 ? '收藏成功' : "已取消收藏",
- icon: "none"
- })
- let list = this.data.list,
- index = rowindex - 1;
- this.data.tabActiveTitle == '列表' ? list[index].isCollect = isCollect == 0 ? 1 : 0 : list.splice(index, 1);
- this.setData({
- list
- })
- this.closeShow();
- })
- },
- mySaveVideo() {
- const that = this,
- fileSelected = this.data.fileSelected;
- const downloadTask = wx.downloadFile({
- url: fileSelected.url,
- filePath: wx.env.USER_DATA_PATH + '/' + new Date().valueOf() + '.mp4',
- timeout: 600000,
- success(res) {
- console.log("下载", res)
- that.saveVideo(res.filePath)
- },
- fail({
- errMsg
- }) {
- if (errMsg == 'downloadFile:fail exceed max file size') wx.showToast({
- title: '视频体积超大,无法保存!请尝试打开视频长按保存下载',
- icon: "none"
- })
- }
- })
- downloadTask.onProgressUpdate((res) => {
- wx.showLoading({
- title: `保存进度` + res.progress + `%`,
- mask: true
- })
- if (res.progress == 100) wx.hideLoading()
- })
- that.closeShow();
- },
- /* 文件下载 */
- dowmLoad() {
- const that = this,
- fileSelected = this.data.fileSelected;
- wx.setClipboardData({
- data: fileSelected.url,
- success: function () {
- wx.showToast({
- title: '复制成功,将链接放置到浏览器中便可下载文件',
- icon: "none",
- duration: 3000
- });
- that.closeShow();
- }
- })
- },
- saveVideo(filePath) {
- const that = this;
- wx.saveVideoToPhotosAlbum({
- filePath,
- success(res) {
- console.log("保存", res)
- wx.showModal({
- title: '提示',
- content: '视频已保存到系统相册',
- showCancel: false
- })
- wx.hideLoading()
- },
- fail(err) {
- console.log("保存失败", err)
- if (err.errno == 103) {
- wx.showModal({
- title: '提示',
- content: '未获取保存相册权限,无法保存!',
- confirmText: "前去授权",
- success({
- confirm
- }) {
- if (confirm) wx.openSetting({
- success(res) {
- console.log(res.authSetting["scope.writePhotosAlbum"])
- if (res.authSetting["scope.writePhotosAlbum"]) {
- that.saveVideo(filePath)
- } else {
- wx.showToast({
- title: '未获得授权',
- icon: "none"
- })
- }
- }
- })
- }
- })
- }
- }
- })
- },
- /* 获得列表 */
- getList(init = false) {
- if (init.detail != undefined) init = init.detail;
- if (init) this.setData({
- ['content.pageNumber']: 1
- })
- if (this.data.content.pageNumber > this.data.content.pageTotal) return;
- let content = this.data.content;
- if (content.parentid == '默认') content.parentid = wx.getStorageSync('siteP').salematerialfolderid;
- if (this.data.sort[0]) content.sort = this.data.sort;
- _Http.basic({
- "classname": "saletool.salematerial.salematerial",
- "method": (this.data.tabActiveTitle == '列表') ? "selectList" : "selectMyList",
- content
- }).then(res => {
- this.selectComponent('#ListBox').RefreshToComplete();
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- this.setData({
- list: (res.pageNumber == 1) ? MFT.fileList(res.data) : this.data.list.concat(MFT.fileList(res.data)),
- ['content.pageNumber']: res.pageNumber + 1,
- ['content.pageTotal']: res.pageTotal,
- inTotal: res.total,
- sort: res.sort
- })
- })
- },
- /* 搜索框输入 */
- searchInput({
- detail
- }) {
- clearTimeout(dowmCount);
- this.setData({
- ['content.where.condition']: detail.trim()
- })
- dowmCount = setTimeout(() => {
- this.getList(true)
- }, 1000);
- },
- /* 清除搜索输入 */
- searchClear() {
- this.setData({
- ['content.where.condition']: ""
- })
- },
- /* tab切换 */
- tabsChange({
- detail
- }) {
- this.setData({
- tabActiveTitle: detail.title
- })
- this.getList(true);
- },
- /* 开关切换 */
- changeSwitch({
- detail
- }) {
- this.setData({
- sort: detail
- })
- this.getList(true);
- },
- /* 修改ID */
- changeParentid(id) {
- this.setData({
- ['content.parentid']: id
- })
- },
- /* 修改选中ID */
- changeId({
- detail
- }) {
- this.setData({
- fileSelected: detail,
- show: true
- })
- },
- /* 关闭修改 */
- closeShow() {
- this.setData({
- show: false
- })
- setTimeout(() => {
- this.setData({
- fileSelected: {}
- })
- }, 150)
- },
- }
- })
|