addUs.vue
4.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
<view>
<image src="../../static/img-brand@2x.png" style="width: 100%; height: 438rpx;" mode=""></image>
<view class="box">
<view class="" style="padding: 32rpx; background: white;position: relative;">
<u--form labelPosition="left" :model="info" :rules="rules" ref="uForm">
<u-form-item label="公司名称" labelWidth="200rpx" prop="userInfo.name" borderBottom ref="item1">
<u--input v-model="info.name" placeholder="请输入公司名称" border="none"></u--input>
</u-form-item>
<u-form-item label="公司类型" labelWidth="200rpx" prop="userInfo.contract_name" borderBottom
ref="item1">
<u--input v-model="info.contract_name" placeholder="请选择公司类型" border="none"></u--input>
</u-form-item>
<u-form-item label="主营产品" labelWidth="200rpx" prop="userInfo.product_ids" borderBottom ref="item1">
<u--input v-model="info.product_ids" placeholder="请选择主营产品" border="none"></u--input>
</u-form-item>
<u-form-item label="营业执照" labelWidth="200rpx" prop="userInfo.product_ids" borderBottom ref="item1">
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
:maxCount="1" width="250" height="150">
<image src="/static/img-zhizhao@2x.png" mode="widthFix" style="width: 250px;height: 150px;">
</image>
</u-upload>
</u-form-item>
<u-form-item label="公司资质" labelWidth="200rpx" prop="userInfo.product_ids" borderBottom ref="item1">
<u-upload :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple
:maxCount="1" width="250" height="150">
<image src="/static/img-zhizhao@2x(1).png" mode="widthFix"
style="width: 250px;height: 150px;"></image>
</u-upload>
</u-form-item>
</u--form>
<view style="margin-top: 40rpx;">
<u-button text="提交" type="primary" @click="submit"></u-button>
</view>
</view>
</view>
</view>
</template>
<script>
import config from '@/common/config'
export default {
data() {
return {
info:{},
action: config.baseUrl + '/api/common/upload',
fileList1: [],
fileList2: [],
}
},
onShow() {
let pagearr = getCurrentPages(); //获取应用页面栈
let currentPage = pagearr[pagearr.length - 1]; //获取当前页面信息
console.log('option:', currentPage) //获取页面传递的信息
this.model1.userInfo.category_id = currentPage.$vm.category_id || (this.model1.userInfo.category && this.model1.userInfo.category.id) || ''
this.model1.userInfo.name = currentPage.$vm.name || (this.model1.userInfo.category && this.model1.userInfo.category.name) || ''
},
methods: {
submit(){
console.log(this.info);
},
goChoose(){
uni.navigateTo({
url: '/pages/subPages/more?val=2'
})
},
deletePic(event) {
this[`fileList${event.name}`].splice(event.index, 1)
},
// 新增图片
async afterRead(event) {
console.log(event);
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this[`fileList${event.name}`].length
lists.map((item) => {
this[`fileList${event.name}`].push({
...item,
status: 'uploading',
message: '上传中'
})
})
for (let i = 0; i < lists.length; i++) {
const result = await this.uploadFilePromise(lists[i].url)
let item = this[`fileList${event.name}`][fileListLen]
this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
status: 'success',
message: '',
url: result
}))
fileListLen++
}
},
uploadFilePromise(url) {
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: this.action, // 仅为示例,非真实的接口地址
filePath: url,
name: 'file',
formData: {
user: 'test'
},
success: (res) => {
setTimeout(() => {
resolve(JSON.parse(res.data).data.fullurl)
}, 1000)
}
});
})
},
}
}
</script>
<style scoped lang="scss">
.box {
border-radius: 20rpx 20rpx 0 0;
opacity: 1;
background: #ffffffff;
}
</style>