ts_aimz/pages/copyright/refund/refund.js
2025-05-14 09:48:02 +08:00

362 lines
11 KiB
JavaScript

// pages/copyright/refund/refund.js
import ProApi from '../../../net/api/projectApi'
import {
previewUrl
} from '../../../net/http'
const app = getApp()
const jsonData = require('../../../utils/data')
const Cache = require('../../../utils/storage')
Page({
/**
* 页面的初始数据
*/
data: {
pageData: {
page: 1,
rows: 10,
applyStatus: '', //状态
projName: '' //项目名称
},
keywords: '',
stateList: jsonData.stateList,
selectState: '',
tempSelState: '',
msgHint: '',
msgType: 'error',
msgShow: false,
loadingState: 'loading',
listRefreshTrig: false,
isLoadMore: false,
hasMore: true,
refundList: [],
slideBtns: app.globalData.cancelEditBtns,
showHint: false,
buttons: [{
text: '关闭'
}],
tempItem: null,
isShowOptions: false,
needRefresh: false, //是否需要刷新
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '退款项目',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
this.getRefundList(true)
},
onShow() {
const _self = this
if (_self.data.needRefresh) {
_self.setData({
needRefresh: false
})
_self.doRefreshList()
}
},
chooseOptions() {
this.setData({
isShowOptions: !this.data.isShowOptions,
tempSelState: this.data.selectState
})
},
//取消条件
cancelChooseOption() {
this.setData({
isShowOptions: false,
tempSelState: ''
})
},
//清除条件
clearChooseOption() {
this.setData({
isShowOptions: false,
selectState: '',
tempSelState: ''
})
this.doRefreshList()
},
//确定条件
confirmChooseOption() {
this.setData({
selectState: this.data.tempSelState,
isShowOptions: false,
tempSelState: ''
})
this.doRefreshList()
},
//去退款
applyRefund() {
wx.navigateTo({
url: '/pages/copyright/applyRefund/applyRefund',
})
},
inputKeywords(e) {
this.setData({
keywords: e.detail.value
})
},
clearSearch() {
this.setData({
keywords: ''
})
this.doRefreshList()
},
doSearchKeyWord() {
this.doRefreshList()
},
chooseState(e) {
const value = e.currentTarget.dataset.value
this.setData({
tempSelState: value
})
},
doRefreshList() {
console.log('正在刷新...')
const _self = this
_self.setData({
listRefreshTrig: true,
loadingState: 'loading',
hasMore: true,
'pageData.page': 1,
'pageData.projName': _self.data.keywords,
'pageData.applyStatus': _self.data.selectState,
isLoadMore: false
})
_self.getRefundList(true)
},
doLoadMore() {
//判断是否正在加载中 与是否存在更多数据
const _self = this
if (_self.data.isLoadMore || !_self.data.hasMore) {
return
}
_self.setData({
isLoadMore: true,
'pageData.page': ++_self.data.pageData.page,
'pageData.projName': _self.data.keywords,
'pageData.applyStatus': _self.data.selectState,
})
_self.getRefundList(false)
},
getRefundList(isRefresh) {
const _self = this
_self.setData({
refundList: isRefresh ? [] : _self.data.refundList,
loadingState: isRefresh ? 'loading' : ''
})
ProApi.doGetMineRefundProList(_self.data.pageData)
.then(res => {
console.log(res)
var status = 'success'
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
_self.setData({
loadingState: isRefresh ? status : '',
refundList: _self.data.refundList.concat(res.rows),
listRefreshTrig: false,
isLoadMore: false
})
_self.setData({
hasMore: _self.data.refundList.length < res.total
})
_self.showEditDel()
}, err => {
_self.setData({
loadingState: 'error',
listRefreshTrig: false,
isLoadMore: false,
hasMore: true
})
})
},
show(e) {
console.log('显示', e)
//判断状态
const _self = this
const value = e.currentTarget.dataset.value
const id = e.currentTarget.id
if (value.applyStatus != 'PENDING') {
//通过 或 取消 后不能撤销
const item = _self.selectComponent(`#${id}`)
if (item) {
item.setData({
show: false
})
}
}
},
slideButtonTap(e) {
const index = e.detail.index
const item = e.currentTarget.dataset.value
console.log(e)
if (index == 0) {
//取消
this.showCancel(item)
}
},
showCancel(item) {
const _self = this
wx.showModal({
title: '警告',
content: '您确定要撤销申请吗?',
complete: (res) => {
if (res.confirm) {
_self.doCancel(item)
}
}
})
},
doCancel(item) {
const _self = this
wx.showLoading({
title: '取消中...',
})
ProApi.doCancelRefundPro(item.projRefundApplyId)
.then(res => {
wx.hideLoading()
_self.setData({
msgType: 'success',
msgHint: '撤销成功',
msgShow: true
})
_self.doRefreshList()
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgType: 'error',
msgHint: err.msg ? err.msg : '撤销失败,请稍后重试',
msgShow: true
})
})
},
showReason(e) {
const item = e.currentTarget.dataset.value
item.refundVoucherFileKVs.map(value => {
value.url = previewUrl + value.key
return value
})
const _self = this
_self.setData({
tempItem: item,
showHint: true
})
},
closeHint(e) {
this.setData({
showHint: false,
tempItem: null
})
},
previewImg(e) {
const _self = this
const current = e.currentTarget.dataset.value
//判断是pdf还是图片
if (current.value.toLowerCase().endsWith('.pdf')) {
//文件,下载文件
_self.doDownloadApprovePdf(current)
} else {
//图片
const urls = [current.url]
wx.previewImage({
urls: urls,
})
}
},
doDownloadApprovePdf(item) {
const _self = this
_self.setData({
showHint: false
})
wx.showLoading({
title: '加载中...',
})
const token = Cache.get('token')
const header = {}
if (token) {
header.Auth = `Bearer ${token}`;
}
wx.downloadFile({
url: item.url,
header: header,
success: res => {
wx.hideLoading()
if (res.statusCode === 200) {
// 从响应头中获取文件名
let fileName = item.value;
if (fileName) {
// 保存文件时使用获取到的文件名
wx.getFileSystemManager().saveFile({
tempFilePath: res.tempFilePath,
filePath: wx.env.USER_DATA_PATH + '/' + fileName,
success: function (res) {
const savedFilePath = res.savedFilePath;
console.log('文件下载并保存成功', savedFilePath);
if (savedFilePath.endsWith(".txt")) {
wx.navigateTo({
url: '/pages/readTxt/readTxt?filePath=' + savedFilePath,
})
} else {
wx.openDocument({
filePath: savedFilePath,
showMenu: true
})
}
},
fail: function (err) {
console.error('文件保存失败', err);
_self.showErr('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。')
}
})
} else {
console.error('未从响应头中获取到文件名');
_self.showErr('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。')
}
} else {
_self.showErr('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。')
}
},
fail: err => {
_self.showErr('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。')
console.log(`下载失败${err}`)
}
})
},
//显示错误信息
showErr(msg) {
const _self = this
_self.setData({
msgHint: msg,
msgType: 'error',
msgShow: true,
showDownloadDialog: false,
downloading: false,
downloadProgress: 0
})
},
showEditDel() {
const _self = this
const isFirst = Cache.get('refundFirst', '0')
if (isFirst == '0') {
const item = _self.selectComponent('#mp-slide-0')
if (item) {
item.setData({
show: true
})
Cache.set('refundFirst', '1')
}
}
},
})