daofu-applet/pages/emergency/y-a/index/index.js
2024-06-14 15:00:33 +08:00

157 lines
4.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/emergency/resourse/index/index.js
const app = getApp();
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
baseUrl: app.FILE_SERVER_URL,
condition: '',
curTab: 0,
tabs: [],
canChange: false,
freshIng: false,
page: 1,
pageSize: 10,
list: [],
},
pageLifetimes: {
show: function () {
this.getType();
},
},
/**
* 组件的方法列表
*/
methods: {
/**
* 搜索
*/
inputSearch: function (e) {
this.data.condition = e.detail.value;
this.refresh();
},
/**
* 切换筛选
*/
tabSelect: function (params) {
const index = Number.parseInt(params.currentTarget.dataset.index);
this.data.curTab = index;
this.setData(this.data)
this.refresh();
},
/**
* 刷新
* @param {*} params
*/
refresh: function (params) {
this.data.page = 1;
this.data.list = [];
this.setData(this.data)
this.getList();
},
/**
* 获取列表
*/
getList: function () {
const params = {
page: this.data.page,
limit: this.data.pageSize,
othtypeid: this.data.tabs[this.data.curTab].emerTypeId,
planname: this.data.condition,
userId: app.globalData.userInfo.userId
}
app.axios("GET", "app", "/Othplan/getOthplanPage", params, false).then(res => {
this.data.freshIng = false;
if (res.code == 1) {
let page = Number.parseInt(res.data.pageNum);
if (this.data.page == 1) {
this.data.list = res.data.list;
} else {
var list = this.data.list;
if (this.data.page == page) this.data.list = [...list, ...res.data.list]
}
if (res.data.list?.length > 0) this.data.page = page + 1
}
this.setData(this.data)
})
},
download :function (item) {
console.log(item,'item====>');
console.log(this.data.baseUrl+item.currentTarget.dataset.item.filePath);
//触发点击事件使用uni.showLoading()展示交互提示
wx.showLoading({
title: '正在下载……'
});
// 使用wx.downloadFile()开始下载文件
wx.downloadFile({
url: this.data.baseUrl+item.currentTarget.dataset.item.filePath, //url:请求的完整地址
success: function(res) {
wx.hideLoading() //调用结束,隐藏加载框
const filePath = res.tempFilePath //临时文件路径 (本地路径)
if (res.statusCode == 200) {
//判断后端数据接收成功时提示下载完成
wx.showToast({
icon: 'none',
mask: true,
title: '下载完成,正在打开文件...',
duration: 2000,
});
}
//设置定时器2秒后打开文件
setTimeout(() => {
//调用wx.openDocument()打开刚刚下载的文件
wx.openDocument({
filePath: filePath, //上一步存储的临时文件路径 (本地路径)
fileType: item.type, //要打开的文件类型,
showMenu: true, //是否显示右上角菜单
//下面的测试用了,写不写无所谓
success: function(res) {
},
complete: function(msg) {
}
})
}, 2000)
},
//文件下载失败会走这里具体可以把err打印出来看看有什么错误
fail: (err) => {
uni.showToast({
icon: 'none',
mask: true,
title: '文件下载失败',
});
},
})
},
/**
* 获取预案类型
*/
getType: function () {
app.axios("GET", "app", "/Othplan/getOthtypeList", {}, false).then(res => {
if (res.code == 1) {
console.log(res,'res==');
this.data.tabs = res.data;
this.setData(this.data)
}
this.setData(this.data)
})
}
}
})