454 lines
15 KiB
JavaScript
454 lines
15 KiB
JavaScript
// pages/copyright/repair/repair.js
|
|
import ProApi from '../../../net/api/projectApi'
|
|
import {
|
|
previewUrl,
|
|
copyrightUrl
|
|
}
|
|
from '../../../net/http.js'
|
|
const jsonData = require('../../../utils/data')
|
|
const Cache = require('../../../utils/storage')
|
|
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
keywords: '',
|
|
pageData: {
|
|
page: 1,
|
|
rows: 10,
|
|
projName: '',
|
|
type: '',
|
|
correctionType: '',
|
|
applyStatus: ''
|
|
},
|
|
msgShow: false,
|
|
msgHint: '',
|
|
msgType: 'error',
|
|
loadingState: 'loading',
|
|
listRefreshTrig: false,
|
|
isLoadMore: false,
|
|
hasMore: true,
|
|
repairList: [], //开票记录
|
|
typeList: jsonData.typeList,
|
|
selectType: '',
|
|
kindList: jsonData.kindList,
|
|
selectKind: '',
|
|
stateList: jsonData.stateList,
|
|
selectState: '',
|
|
buttons: [{
|
|
text: '关闭'
|
|
}],
|
|
showHint: false,
|
|
approveImgs: [],
|
|
approveTime: '',
|
|
approveDesc: '',
|
|
preUrl: previewUrl,
|
|
approveStatus: false, //是否显示编辑提示
|
|
slideBtns: app.globalData.cancelEditBtns,
|
|
showDownloadDialog: false,
|
|
downloadProgress: 0, //下载文件进度
|
|
downloading: false, //下载文件中
|
|
tempDownloadPro: null, //下载的item
|
|
approveReason: '', //补正原因
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
wx.setNavigationBarTitle({
|
|
title: '补正项目',
|
|
})
|
|
wx.setNavigationBarColor({
|
|
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
|
|
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
|
|
animation: { // 可选项
|
|
duration: 500,
|
|
timingFunc: 'easeIn'
|
|
}
|
|
})
|
|
this.doRefreshList()
|
|
},
|
|
chooseType(e) {
|
|
const value = e.currentTarget.dataset.value
|
|
this.setData({
|
|
selectType: value == this.data.selectType ? '' : value
|
|
})
|
|
this.doRefreshList()
|
|
},
|
|
chooseKind(e) {
|
|
const value = e.currentTarget.dataset.value
|
|
this.setData({
|
|
selectKind: value == this.data.selectKind ? '' : value
|
|
})
|
|
this.doRefreshList()
|
|
},
|
|
chooseState(e) {
|
|
const value = e.currentTarget.dataset.value
|
|
this.setData({
|
|
selectState: value == this.data.selectState ? '' : value
|
|
})
|
|
this.doRefreshList()
|
|
},
|
|
inputKeywords(e) {
|
|
this.setData({
|
|
keywords: e.detail.value
|
|
})
|
|
},
|
|
//清除搜索内容
|
|
clearSearch() {
|
|
const _self = this
|
|
_self.setData({
|
|
keywords: ''
|
|
})
|
|
_self.doRefreshList()
|
|
},
|
|
//发起搜索
|
|
doSearchKeyWord() {
|
|
const _self = this
|
|
_self.doRefreshList()
|
|
},
|
|
doRefreshList() {
|
|
console.log('正在刷新...')
|
|
const _self = this
|
|
_self.setData({
|
|
listRefreshTrig: true,
|
|
loadingState: 'loading',
|
|
hasMore: true,
|
|
'pageData.page': 1,
|
|
'pageData.projName': _self.data.keywords,
|
|
'pageData.type': _self.data.selectType,
|
|
'pageData.correctionType': _self.data.selectKind,
|
|
'pageData.applyStatus': _self.data.selectState,
|
|
isLoadMore: false
|
|
})
|
|
_self.doGetRepairList(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.type': _self.data.selectType,
|
|
'pageData.correctionType': _self.data.selectKind,
|
|
'pageData.applyStatus': _self.data.selectState,
|
|
})
|
|
_self.doGetRepairList(false)
|
|
},
|
|
//加载列表
|
|
doGetRepairList(isRefresh) {
|
|
const _self = this
|
|
_self.setData({
|
|
repairList: isRefresh ? [] : _self.data.repairList,
|
|
loadingState: isRefresh ? 'loading' : ''
|
|
})
|
|
ProApi.doGetMineRepairList(_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 : '',
|
|
repairList: _self.data.repairList.concat(res.rows),
|
|
listRefreshTrig: false,
|
|
isLoadMore: false
|
|
})
|
|
_self.setData({
|
|
hasMore: _self.data.repairList.length < res.total
|
|
})
|
|
}, 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.doCancelProrepair(item.projCorrectionApplyId)
|
|
.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
|
|
const _self = this
|
|
item.correctionVoucherFileKVs.map(value => {
|
|
value.url = _self.data.preUrl + value.key
|
|
return value
|
|
})
|
|
_self.setData({
|
|
approveImgs: item.correctionVoucherFileKVs,
|
|
approveTime: item.gmtReview,
|
|
approveDesc: item.reviewReason,
|
|
approveReason: item.correctionReason,
|
|
approveStatus: item.applyStatus == 'APPROVED' ? false : true,
|
|
showHint: true
|
|
})
|
|
},
|
|
//预览图片
|
|
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}`)
|
|
}
|
|
})
|
|
},
|
|
closeDialog(e) {
|
|
this.setData({
|
|
showDownloadDialog: false
|
|
})
|
|
},
|
|
//下载文件
|
|
downloadFile(e) {
|
|
const item = e.currentTarget.dataset.value
|
|
console.log(item.correctionType)
|
|
|
|
this.setData({
|
|
tempDownloadPro: item,
|
|
showDownloadDialog: true
|
|
})
|
|
},
|
|
closeHint(e) {
|
|
this.setData({
|
|
approveImgs: [],
|
|
approveTime: '',
|
|
approveDesc: '',
|
|
showHint: false,
|
|
approveStatus: false
|
|
})
|
|
},
|
|
//去申请补正
|
|
applyRepair() {
|
|
wx.navigateTo({
|
|
url: '/pages/copyright/applyRepair/applyRepair',
|
|
})
|
|
},
|
|
download(e) {
|
|
const _self = this
|
|
_self.setData({
|
|
downloadProgress: 0,
|
|
downloading: true, //显示下载进度
|
|
showDownloadDialog: false, //关闭底部弹窗
|
|
})
|
|
const path = e.currentTarget.dataset.path
|
|
const url = copyrightUrl + path + _self.data.tempDownloadPro.projId
|
|
const token = Cache.get('token')
|
|
const header = {}
|
|
if (token) {
|
|
header.Auth = `Bearer ${token}`;
|
|
}
|
|
const downloadTask = wx.downloadFile({
|
|
url: url,
|
|
header: header,
|
|
success(res) {
|
|
console.log('下载成功', res)
|
|
_self.setData({
|
|
downloadProgress: 0,
|
|
downloading: false
|
|
})
|
|
if (res.statusCode === 200) {
|
|
_self.setData({
|
|
successHint: '下载成功',
|
|
showSuccess: true
|
|
})
|
|
// 从响应头中获取文件名
|
|
const contentDisposition = res.header['Content-Disposition'];
|
|
let fileName = '';
|
|
if (contentDisposition) {
|
|
const match = contentDisposition.match(/filename=(.*)/);
|
|
if (match && match[1]) {
|
|
fileName = match[1].replace(/['"]/g, '');
|
|
}
|
|
}
|
|
|
|
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}`)
|
|
}
|
|
})
|
|
downloadTask.onProgressUpdate(res => {
|
|
console.log(res.progress)
|
|
_self.setData({
|
|
downloadProgress: res.progress
|
|
})
|
|
});
|
|
},
|
|
//显示错误信息
|
|
showErr(msg) {
|
|
const _self = this
|
|
_self.setData({
|
|
msgHint: msg,
|
|
msgType: 'error',
|
|
msgShow: true,
|
|
showDownloadDialog: false,
|
|
downloading: false,
|
|
downloadProgress: 0
|
|
})
|
|
}
|
|
}) |