add.vue
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<view class="fs-p30">
<tui-form ref="form" :showMessage="false">
<tui-textarea :radius="20" placeholder="请输入巡检描述" isCounter :size="28" :maxlength="100" v-model="formData.remark"></tui-textarea>
<tui-white-space></tui-white-space>
<tui-upload background="#fff" :width="210" :radius="10" :height="210" delColor="#333" custom :serverUrl="serverURL" :header="{'Authorization': userToken}" :limit="3" @complete="complete">
<text class="fs-size__28 fs-color__subtitle fs-weight__400">上传图片</text>
</tui-upload>
</tui-form>
<view class="fs-mt60 fs-flex__center">
<tui-button shape="circle" width="600rpx" height="80rpx" shadow :loading="isLoading" :disabled="isLoading" @click="onSubmit">提 交</tui-button>
</view>
</view>
</template>
<script>
import { uploadURL } from '@/config/app'
import { apiInspectionAdd } from '@/api/work'
const rules = [
{
name: "remark",
rule: ["required"],
msg: ["请输入描述"]
}
]
export default {
data() {
return {
formData: {
type: 1,
remark: '',
imgs: [],
planNo: ''
},
isLoading: false,
serverURL: uploadURL,
id: 0
}
},
onLoad(options) {
this.id = options.id
this.formData.planNo = options.planno
},
methods: {
// 上传完成
complete(e) {
if (e.status == 1) this.formData.imgs = e.imgArr
},
// 提交记录
onSubmit() {
this.$refs.form.validate(this.formData, rules).then(res => {
if (!res.isPass) {
uni.$tui.toast(res.errorMsg)
return
}
if (!this.formData.imgs.length) {
uni.$tui.toast('请上传图片')
return
}
this.isLoading = true
apiInspectionAdd({data:{...this.formData}}).then(res => {
uni.$tui.toast('提交成功')
const pages = getCurrentPages()
const beforePage = pages[pages.length - 2]
const id = this.id
setTimeout(() => {
uni.navigateBack({
success () {
// 刷新页面数据
beforePage.$vm.getInspectionInfo(id)
}
})
}, 1500)
}).finally(() => {
this.isLoading = false
})
})
}
}
}
</script>
<style lang="scss" scoped>
</style>