addUs.vue 4.1 KB
<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>