Commit 249a005f by 郑艺斌

优化完成维修

parent f3c4019d
......@@ -6,14 +6,13 @@ Page({
* 页面的初始数据
*/
data: {
formData:{
remarks:''
formData: {
remarks: ''
},
tags:[
],
originFiles:[
tags: [
],
originFiles: [],
gridConfig: {
column: 3,
width: 220,
......@@ -22,17 +21,17 @@ Page({
config: {
count: 6,
},
id:'',
tagText:'',
id: '',
tagText: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if(options && options.id){
if (options && options.id) {
this.setData({
id:options.id
id: options.id
})
}
},
......@@ -43,7 +42,7 @@ Page({
onReady() {
this.getTabs()
},
getTabs(){
getTabs() {
const that = this
wx.request({
url: baseUrl + '/api/emaint/problem-base/showLabel',
......@@ -58,84 +57,92 @@ Page({
success: function (res) {
console.log(res);
if(res.data.statusCode === 200){
if (res.data.statusCode === 200) {
console.log(res);
that.setData({
tags:res.data.responseResult
tags: res.data.responseResult
})
}
}})
}
})
},
addTag(){
addTag() {
const that = this
let pattern1 = /^\s+/g;
let pattern2 = /\s+$/g;
let tagText = this.data.tagText
if(pattern1.test(tagText)){
wx.showToast({
title: `文字前不能包含空格!`,
icon: 'none',
duration: 2000
})
return
}else if(pattern2.test(tagText)){
wx.showToast({
title: `文字后不能包含空格!`,
icon: 'none',
duration: 2000
})
return
}
// let pattern1 = /^\s+/g;
// let pattern2 = /\s+$/g;
// let tagText = this.data.tagText
// if (pattern1.test(tagText)) {
// wx.showToast({
// title: `文字前不能包含空格!`,
// icon: 'none',
// duration: 2000
// })
// return
// } else if (pattern2.test(tagText)) {
// wx.showToast({
// title: `文字后不能包含空格!`,
// icon: 'none',
// duration: 2000
// })
// return
// }
wx.request({
url: baseUrl + '/api/emaint/problem-base/addLabel',
data: {
id: that.data.id,
problem:that.data.tagText
problem: that.data.tagText
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
"Content-Type": "application/x-www-form-urlencoded",
}, // 设置请求的 header
success: function (res) {
if(res.data.statusCode === 200){
if (res.data.statusCode === 200) {
that.setData({
tagText:''
tagText: ''
})
that.getTabs()
}else{
} else {
wx.showToast({
title: res.data.responseResult,
icon: 'none',
duration: 2000
})
}
}})
}
})
},
onInput(e){
const { value } = e.detail
onInput(e) {
const {
value
} = e.detail
this.setData({
tagText:value
tagText: value
})
},
// 点击标签
onTag(item){
onTag(item) {
const that = this
let value = item.target.dataset
console.log(value);
that.setData({
[`tags[${value.index}].checked`]:!value.checked
[`tags[${value.index}].checked`]: !value.checked
})
},
onRemarks(e){
const { value } = e.detail
onRemarks(e) {
const {
value
} = e.detail
this.setData({
[`formData.remarks`]:value
[`formData.remarks`]: value
})
},
// 上传图片接口
handleChange(e){
handleChange(e) {
const that = this
const {currentSelectedFiles, files} = e.detail
const {
currentSelectedFiles,
files
} = e.detail
currentSelectedFiles[0].forEach(item => {
wx.uploadFile({
url: baseUrl + '/api/file/upload',
......@@ -146,54 +153,87 @@ Page({
},
success: function (res) {
console.log(res);
if(res.statusCode === 200){
if (res.statusCode === 200) {
var isimg = JSON.parse(res.data).responseResult
console.log(isimg);
that.data.originFiles.push({url:item.url,img:isimg})
that.data.originFiles.push({
url: item.url,
img: isimg
})
that.setData({
originFiles: that.data.originFiles,
});
}
}
}
})
})
},
// 删除图片回调函数
handleRemove(e) {
const { index } = e.detail;
const { originFiles } = this.data;
const {
index
} = e.detail;
const {
originFiles
} = this.data;
originFiles.splice(index, 1);
this.setData({
originFiles,
});
},
submit(){
submit() {
const that = this
let arr = []
let imgs = []
let pattern1 = /^\s+/g;
let pattern2 = /\s+$/g;
let tagText = this.data.tagText
this.data.tags.forEach(item => {
if(item.checked){
if (item.checked) {
arr.push(item.problem)
}
})
if(arr.length<=0){
wx.showToast({
title: '请至少选择一个解决办法!',
icon: 'none',
duration: 2000
})
return
if(arr.length <= 0){
if (pattern1.test(tagText)) {
wx.showToast({
title: `文字前不能包含空格!`,
icon: 'none',
duration: 2000
})
return
}else if (pattern2.test(tagText)) {
wx.showToast({
title: `文字后不能包含空格!`,
icon: 'none',
duration: 2000
})
return
}else if(tagText === '' || tagText === null){
wx.showToast({
title: `解决办法输入不能为空!`,
icon: 'none',
duration: 2000
})
return
}else{
arr.push(tagText)
}
}else{
if(tagText !== '' || tagText !== null){
arr.push(tagText)
}
}
let imgs = []
this.data.originFiles.forEach(item => {
imgs.push(item.img)
})
arr = arr.filter(item => item !== '')
wx.request({
url: baseUrl + '/api/emaint/repairProblem/complete',
data: {
id: that.data.id,
remark:that.data.formData.remarks,
imgs:imgs.join('|~|'),
tags:arr.join(',')
remark: that.data.formData.remarks,
imgs: imgs.join('|~|'),
tags: arr.join(',')
},
method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
......@@ -201,7 +241,8 @@ Page({
"accessToken": wx.getStorageSync('accessToken')
}, // 设置请求的 header
success: function (res) {
if(res.data.statusCode === 200){
if (res.data.statusCode === 200) {
that.addTag()
wx.showToast({
title: '提交成功!',
icon: 'success',
......@@ -211,7 +252,8 @@ Page({
delta: 1
})
}
}})
}
})
},
/**
* 生命周期函数--监听页面显示
......
......@@ -8,7 +8,7 @@
</view>
<view class="add">
<input placeholder="新增解决方案标签(不超过8个字)" bindinput="onInput" value="{{tagText}}" />
<button bindtap="addTag">新增标签</button>
<!-- <button bindtap="addTag">新增标签</button> -->
</view>
</view>
<view class="uploader">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment