ts_aimz/pages/copyright/applyRepair/applyRepair.js

314 lines
8.8 KiB
JavaScript
Raw Normal View History

2025-05-08 08:57:38 +08:00
// pages/copyright/applyRepair/applyRepair.js
2025-05-08 12:03:16 +08:00
import {
uploadImgUrl
} from '../../../net/http'
import ProApi from '../../../net/api/projectApi'
const Cache = require('../../../utils/storage')
const data = require('../../../utils/data')
2025-05-08 08:57:38 +08:00
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
imgAssets: app.globalData.imgAssetsUrl,
msgHint: '',
msgType: '',
msgShow: false,
2025-05-08 12:03:16 +08:00
selPro: null,
selType: null,
2025-05-08 08:57:38 +08:00
files: [],
2025-05-08 12:03:16 +08:00
proList: [],
tempSelPro: null,
typeList: data.kindList,
showSelPro: false,
showSelType: false,
tempSelType: null,
remark: '',
proKeywords: '',
proPageData: {
page: 1,
rows: 10,
keywords: ''
},
listRefreshTrig: false,
loadingState: 'loading',
hasMore: true,
2025-05-08 08:57:38 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '申请补正',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
2025-05-08 12:03:16 +08:00
this.setData({
selectFile: this.selectFile.bind(this),
uploadFile: this.uploadFile.bind(this)
})
//获取可以申请补正的列表
this.getCanRepairList(false)
},
inputKeywords(e) {
this.setData({
proKeywords: e.detail.value
})
},
clearSearch() {
this.setData({
proKeywords: ''
})
this.doRefreshList()
},
//搜索项目
doSearchKeyWord() {
this.doRefreshList()
},
doRefreshList() {
2025-05-08 12:03:16 +08:00
const _self = this
_self.setData({
listRefreshTrig: true,
loadingState: 'loading',
hasMore: true,
isLoadMore: false,
'proPageData.page': 1,
'proPageData.keywords': _self.data.proKeywords
2025-05-08 12:03:16 +08:00
})
_self.getCanRepairList(true)
},
doLoadMore() {
//判断是否正在加载中 与是否存在更多数据
const _self = this
if (_self.data.isLoadMore || !_self.data.hasMore) {
return
2025-05-08 12:03:16 +08:00
}
_self.setData({
isLoadMore: true,
'proPageData.page': ++_self.data.proPageData.page,
'proPageData.keywords': _self.data.proKeywords
})
_self.getCanRepairList(false)
},
//获取可以补正的项目列表
getCanRepairList(isRefresh) {
const _self = this
_self.setData({
proList: isRefresh ? [] : _self.data.proList,
loadingState: isRefresh ? 'loading' : ''
})
ProApi.doGetCanProRepairList(_self.data.proPageData)
2025-05-08 12:03:16 +08:00
.then(res => {
console.log(res)
var status = 'success'
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
_self.setData({
loadingState: isRefresh ? status : '',
proList: _self.data.proList.concat(res.rows),
listRefreshTrig: false,
isLoadMore: false
})
_self.setData({
hasMore: _self.data.proList.length < res.total
})
2025-05-08 12:03:16 +08:00
})
.catch(err => {
_self.setData({
loadingState: 'error',
listRefreshTrig: false,
isLoadMore: false,
hasMore: true
2025-05-08 12:03:16 +08:00
})
})
},
//显示补正软著选择
showSelProDialog() {
const _self = this
2025-05-23 17:12:44 +08:00
_self.doRefreshList()
_self.setData({
showSelPro: true,
tempSelPro: _self.data.selPro
})
2025-05-08 12:03:16 +08:00
},
chooseType(e) {
this.setData({
tempSelType: e.currentTarget.dataset.value
})
},
choosePro(e) {
this.setData({
tempSelPro: e.currentTarget.dataset.value
})
},
//关闭补正软件选择
closeDialog(e) {
this.setData({
showSelPro: false,
showSelType: false
})
},
showSelTypeDialog() {
this.setData({
2025-05-09 17:11:32 +08:00
tempSelType: this.data.selType,
2025-05-08 12:03:16 +08:00
showSelType: true,
})
},
confirmSelType() {
this.setData({
showSelType: false,
selType: this.data.tempSelType,
tempSelType: null
})
},
//确定选择补正软著
confirmSelPro() {
this.setData({
showSelPro: false,
selPro: this.data.tempSelPro,
tempSelPro: null
})
},
inputRemark(e) {
this.setData({
remark: e.detail.value
})
2025-05-08 08:57:38 +08:00
},
deleteImage: function (e) {
var index = e.detail.index;
this.data.files.splice(index, 1);
},
2025-05-08 12:03:16 +08:00
previewImage(e) {
wx.previewImage({
current: e.currentTarget.id,
urls: this.data.files
})
},
selectFile(files) {
console.log('files', files)
},
uploadFile(files) {
console.log(files)
const tempFilePaths = files.tempFilePaths;
const token = Cache.get('token')
const header = {}
if (token) {
header.Auth = `Bearer ${token}`;
}
var that = this
for (let i = 0; i < tempFilePaths.length; i++) {
wx.uploadFile({
url: uploadImgUrl,
header: header,
filePath: tempFilePaths[i],
name: 'image',
success(res) {
console.log(res)
let result = JSON.parse(res.data)
that.data.files.push(result.data)
},
fail(err) {
console.log(err);
}
})
}
// 文件上传的函数返回一个promise
return new Promise((resolve, reject) => {
var result = {};
result['urls'] = tempFilePaths;
resolve(result);
})
},
//提交
doApply() {
const legal = this.checkParams()
if (legal) {
const _self = this
wx.showLoading({
title: '提交中...',
})
const ids = _self.data.files.map(item => item.fileId).join(',');
const data = {
correctionReason: _self.data.remark,
correctionType: _self.data.selType.value,
correctionVoucher: ids,
projId: _self.data.selPro.projId
}
ProApi.doApplyProRepair(data)
.then(res => {
wx.hideLoading()
_self.setData({
2025-05-09 17:11:32 +08:00
msgHint: '提交操作已顺利完成,我们会尽快审核,还请耐心等待',
2025-05-08 12:03:16 +08:00
msgType: 'success',
msgShow: true
})
setTimeout(() => {
_self.backPageRefresh()
}, 2000);
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgHint: err.msg ? err.msg : '提交失败,请稍后重试',
msgType: 'error',
msgShow: true
})
})
}
},
//校验参数
checkParams() {
const _self = this
if (_self.data.selPro == null) {
_self.setData({
msgHint: '请选择补正软著',
msgType: 'error',
msgShow: true
})
return false
}
if (_self.data.selType == null) {
_self.setData({
msgHint: '请选择补正种类',
msgType: 'error',
msgShow: true
})
return false
}
if (_self.data.remark == '') {
_self.setData({
msgHint: '请输入补正原因',
msgType: 'error',
msgShow: true
})
return false
}
if (_self.data.files.length <= 0) {
_self.setData({
msgHint: '请上传补正凭证',
msgType: 'error',
msgShow: true
})
return false
}
return true
},
backPageRefresh() {
const _self = this
let pages = getCurrentPages();
let beforePage = pages[pages.length - 2];
2025-05-14 09:48:02 +08:00
beforePage.setData({
needRefresh: true
})
2025-05-08 12:03:16 +08:00
wx.navigateBack()
}
2025-05-08 08:57:38 +08:00
})