postProduct.vue 6.41 KB
<template>
	<view class="page">
		<!-- 反馈内容 -->
		<view class="feedback-data">
			<view class="titleall-box">
				<view class="titleall-left">
					<view class="titleall-left-line"></view>填写产品信息
				</view>
			</view>
			<uni-forms ref="valiForm" :rules="rules" :modelValue="valiFormData" style="width: 96%;margin: 0 auto;">
				<uni-forms-item label="产品名" required name="title">
					<uni-easyinput v-model="valiFormData.title" placeholder="请输入产品名" />
				</uni-forms-item>
				<uni-forms-item label="产品简介">
					<uni-easyinput type="textarea" v-model="valiFormData.remark" placeholder="请输入产品简介" />
				</uni-forms-item>
				<uni-forms-item label="产品详细介绍">
					<uni-easyinput type="textarea" v-model="valiFormData.bodyContent" placeholder="请输入详细产品介绍" />
				</uni-forms-item>
			</uni-forms>
			<view class="example-body">
				<uni-file-picker limit="9"  @select="select"
					title="最多选择9张产品图片"></uni-file-picker>
			</view>
			<!-- <view class="voucher-img">
				<view class="list">
					<image src="/static/voucher_bg.png"></image>
				</view>
				<view class="list">
					<image src="/static/img/yf_01.png"></image>
				</view>
				<view class="list">
					<image src="/static/img/yf_01.png"></image>
				</view>
			</view> -->
		</view>
		<!-- 选择反馈类型 -->
		<view class="feedback-type">
			<view class="feedback-type-left">隶属类别</view>
			<view class="feedback-type-right">
				<view class="title">
					<text>{{TypeArray[TypeIndex]}}</text>
				</view>
				<view class="picker">
					<picker @change="FeedbackTypeCh" :value="TypeIndex" :range="TypeArray">
						<view class="uni-input">{{TypeArray[TypeIndex]}}</view>
					</picker>
				</view>
				<view class="more">
					<image src="../../static/down1.png"></image>
				</view>
			</view>
		</view>
		<!-- 提交 -->
		<view class="submit-btn" @click="submitContent('valiForm')">
			<text>发布</text>
		</view>
	</view>
</template>

<script>
	import {
		data
	} from '../../uview-ui/libs/mixin/mixin';
	import request from '@/utils/request.js'
	export default {
		data() {
			return {
				userCode:{},
				// 选择图片路径
				filePath:[],
				uploadPath:[],
				imageValue: [],
				TypeArray: ['资讯', '意见建议', '投诉', '表扬'],
				TypeList:[],
				TypeId:[],
				TypeIndex: 0,
				type: "",
				lastModifyUserId: '',
				// 校验表单数据
				valiFormData: {
					title: '',
					bodyContent: '',
					remark:''
				},
				creater: '',
				rules: {
					title: {
						rules: [{
							required: true,
							errorMessage: '产品名不能为空'
						}]
					},
				},
				baseUrl:"http://deyanggaoxin.fengshiyun.com"
			};

		},
		onShow() {
			this.getType()
		},
		onLoad() {
			this.getUser()
			let user = uni.getStorageSync('user')
			this.lastModifyUserId = user.userInfo.userId

		},
		methods: {
			// 获取上传状态
			select(e) {
				console.log('选择文件:', e)
				this.filePath = e.tempFilePaths
			},
			// 获取用户信息
			getUser() {
				if (uni.getStorageSync('user')) {
					this.userCode = uni.getStorageSync('user').userInfo
					// this.userInfo = this.userCode.userAccount
					// this.userInfo = '123456'
					console.log('用户已登录!',this.userCode)
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/index'
						})
					})
				}
			},
			// 提交内容
			submitContent(ref) {
				this.$refs[ref].validate().then(res => {
					console.log('success', res);
					uni.showToast({
						title: `校验通过`
					})
					
					this.uploadPath = []
					for(let i=0;i<this.filePath.length;i++){
						uni.uploadFile({
							url:"http://deyanggaoxin.fengshiyun.com/api/file/Uploader/1",
							filePath:this.filePath[i],
							name:'file',
							success: (res) => {
								console.log(JSON.parse(res.data))
								let data = JSON.parse(res.data).data
								console.log(data)
								this.uploadPath.push(data)
							}
						})
					}
					console.log('需要',this.uploadPath)
					let stageName = this.TypeId[this.TypeIndex]
					let that = this
					that.postPro()
				}).catch(err => {
					console.log('err', err);
				})	
			},
			// 上传
			postPro(){
				let that = this
				let stageName = this.TypeId[this.TypeIndex]
				setTimeout(function(){
					console.log('需要',that.uploadPath)
					if(that.uploadPath){
						console.log('jinru')
						var NewData={
								title:that.valiFormData.title,
								content:that.valiFormData.bodyContent,
								remark:that.valiFormData.remark,
								creatorUserId:that.userCode.userId,
								stageName:that.TypeArray[that.TypeIndex],
								stage:stageName,
								comapny:that.userCode.organizeId,
								images:that.uploadPath
							};
							console.log(NewData);
						request({
							url:'/api/Extend/baseproduct',
							method:'POST',
							header:{
								"Content-Type": "application/json;charset:utf-8"
							},
							data:NewData
						}).then(res=>{
							console.log("post返回",res)
							if(res.code === 200){
								console.log("上传后的值",res)
								uni.showToast({
									icon:"success",
									title:"发布成功"
								}).then(()=>{
									uni.navigateTo({
										url:'/pages/supply/supply'
									})
								})
							}
							
							
								// console.log("上传后的值",res)
								// uni.showToast({
								// 	icon:"success",
								// 	title:"发布成功"
								// })
							
						})
					}else{
						uni.showToast({
							icon:"error",
							title:"请选择图片"
						})
					}
				},2000)
			},
			// 获取产品分类
			getType() {
				// request({
				// 	url: '/api/Extend/baseproduct/ProductReadAccount',
				// 	method: 'get',
				// 	data: {},
				// }).then(res => {
				// 	console.log(res)
				// 	this.TypeArray = res.data.legend.data
				// })
				request({
					url: '/api/system/DictionaryData/359690843851851013/Data/Selector',
					method: 'get',
					data: {},
				}).then(res => {
					console.log(res.data)
					this.TypeList = res.data.list
					this.TypeArray = this.TypeList.map(it=>{
						return it.fullName
					})
					this.TypeId = this.TypeList.map(it=>{
						return it.id
					})
				})
			},
			/**
			 * 反馈类型
			 * @param {Object} val
			 */
			FeedbackTypeCh(val) {
				console.log(val);
				this.TypeIndex = val.detail.value;
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'Feedback.scss';
</style>