ts_aimz/pages/copyright/applyRepair/applyRepair.js

270 lines
7.6 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: ''
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)
},
//获取可以补正的项目列表
getCanRepairList(isShow) {
const _self = this
wx.showLoading({
title: '加载中...',
})
const data = {
page: 1,
rows: 30
}
ProApi.doGetCanProRepairList(data)
.then(res => {
wx.hideLoading()
if (res.rows && res.rows.length > 0) {
_self.setData({
proList: res.rows,
showSelPro: isShow,
tempSelPro: _self.data.selPro
})
} else {
_self.setData({
msgHint: '您暂无可以补正的软著',
msgType: 'error',
msgShow: true
})
}
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgHint: err.msg ? err.msg : '网络错误,请稍后重试',
msgType: 'error',
msgShow: true
})
})
},
//显示补正软著选择
showSelProDialog() {
const _self = this
if (_self.data.proList.length <= 0) {
_self.getCanRepairList(true)
} else {
_self.setData({
showSelPro: true,
tempSelPro: _self.data.selPro
})
}
},
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({
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({
msgHint: '提交成功,请耐心等待审核',
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];
beforePage.doRefreshList()
wx.navigateBack()
}
2025-05-08 08:57:38 +08:00
})