305 lines
8.5 KiB
JavaScript
305 lines
8.5 KiB
JavaScript
|
// pages/copyright/applyRepair/applyRepair.js
|
|||
|
import {
|
|||
|
uploadImgUrl
|
|||
|
} from '../../../net/http'
|
|||
|
import ProApi from '../../../net/api/projectApi'
|
|||
|
const Cache = require('../../../utils/storage')
|
|||
|
const data = require('../../../utils/data')
|
|||
|
const app = getApp()
|
|||
|
Page({
|
|||
|
/**
|
|||
|
* 页面的初始数据
|
|||
|
*/
|
|||
|
data: {
|
|||
|
imgAssets: app.globalData.imgAssetsUrl,
|
|||
|
msgHint: '',
|
|||
|
msgType: '',
|
|||
|
msgShow: false,
|
|||
|
selPro: null,
|
|||
|
selType: null,
|
|||
|
files: [],
|
|||
|
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,
|
|||
|
},
|
|||
|
|
|||
|
/**
|
|||
|
* 生命周期函数--监听页面加载
|
|||
|
*/
|
|||
|
onLoad(options) {
|
|||
|
wx.setNavigationBarTitle({
|
|||
|
title: '退款申请',
|
|||
|
})
|
|||
|
wx.setNavigationBarColor({
|
|||
|
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
|
|||
|
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
|
|||
|
animation: { // 可选项
|
|||
|
duration: 500,
|
|||
|
timingFunc: 'easeIn'
|
|||
|
}
|
|||
|
})
|
|||
|
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() {
|
|||
|
const _self = this
|
|||
|
_self.setData({
|
|||
|
listRefreshTrig: true,
|
|||
|
loadingState: 'loading',
|
|||
|
hasMore: true,
|
|||
|
isLoadMore: false,
|
|||
|
'proPageData.page': 1,
|
|||
|
'proPageData.keywords': _self.data.proKeywords
|
|||
|
})
|
|||
|
_self.getCanRepairList(true)
|
|||
|
},
|
|||
|
doLoadMore() {
|
|||
|
//判断是否正在加载中 与是否存在更多数据
|
|||
|
const _self = this
|
|||
|
if (_self.data.isLoadMore || !_self.data.hasMore) {
|
|||
|
return
|
|||
|
}
|
|||
|
_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.doGetCanRefundProList(_self.data.proPageData)
|
|||
|
.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
|
|||
|
})
|
|||
|
})
|
|||
|
.catch(err => {
|
|||
|
_self.setData({
|
|||
|
loadingState: 'error',
|
|||
|
listRefreshTrig: false,
|
|||
|
isLoadMore: false,
|
|||
|
hasMore: 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
|
|||
|
})
|
|||
|
},
|
|||
|
deleteImage: function (e) {
|
|||
|
var index = e.detail.index;
|
|||
|
this.data.files.splice(index, 1);
|
|||
|
},
|
|||
|
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 = {
|
|||
|
projId: _self.data.selPro.projId,
|
|||
|
refundReason: _self.data.remark,
|
|||
|
refundVoucher: ids
|
|||
|
}
|
|||
|
ProApi.doApplyRefundPro(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.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()
|
|||
|
}
|
|||
|
})
|