<style scoped lang="scss">
	.mywishplan{
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		padding: 15px;
		.box{
			background: #FFFFFF;
			box-shadow: 0px 5px 25px 0px rgba(218, 220, 230, 0.85);
			border-radius: 20px;
			margin-bottom: 20px;
			// height: 100%;
			.box_center{
				padding: 0 15px 20px;
				.box_text{
					width: 100%;
					height: 55px;
					margin-top: 15px;
					border-bottom: 1px solid #DADCE6;
					display: flex;
					align-items: center;
					.box_text_l{
						font-size: 14px;
						font-weight: 500;
						color: #111111;
						width: 120rpx;
						margin-right: 15px;
					}
					.box_text_r{
						width: 1px;
						flex:1;
					}
				}
				.boxxq{
					width: 100%;
					min-height:170px ;
					border-radius: 10px;
					border: 1px solid #E9E9E9;
					box-shadow: 0px 1px 0px 0px rgba(116, 116, 116, 0.16);
					background: rgba(209, 210, 212, 0);
					
					
				}
				.box-tj{
					width: 100%;
					height: 50px;
					border-radius: 10px;
					background: #1F1F1F;
					font-size: 15px;
					color: #FFF;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-top: 20px;
					
				}
			}
		}
		
	}
</style>
<template>
	<view class="mywishplan">
		<view class="box">
			<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/wishaddtop.png" mode="widthFix" style="width: 100%;height: auto;"></image>
			<view class="box_center">
				<view class="box_text">
					<view class="box_text_l">我的信息</view>
					<view class="box_text_r">
						<input type="text" v-model="addMsg.BranchName" :min='0' placeholder="输入品牌或企业信息" style="font-size: 12px;text-align: right;">
					</view>
				</view>
				<view class="box_text">
					<view class="box_text_l">对标载体</view>
					<view class="box_text_r">
						<input type="text" v-model="addMsg.CarrierName" :min='0' placeholder="输入对标载体名称" style="font-size: 12px;text-align: right;">
					</view>
				</view>
				<view class="box_text">
					<view class="box_text_l">发展区域</view>
					<view class="box_text_r">
						<input type="text" v-model="addMsg.Area" :min='0' placeholder="输入区域" style="font-size: 12px;text-align: right;">
					</view>
				</view>
				<view class="box_text" style="border-bottom: none;">
					<view class="box_text_l">心愿详细</view>
				</view>
				<view @click="gorichText">
					<view class="boxxq" v-if="addMsg.Description==''" style="display: flex;flex-direction: column;align-items: center;justify-content: center;">
						<image mode="aspectFill" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/wish-edit.png" style="width: 50px;height: 50px;"></image>
						<view style="font-size: 14px;color: #1F1F1F;margin-top: 10px;">点击进入编辑>></view>
					</view>
					<view class="boxxq" v-if="addMsg.Description!=''" style="padding: 15px;">
						<view v-html='addMsg.Description'  style="width: 100%;overflow: hidden;"></view>
						<view style="font-size: 14px;color: #1F1F1F;margin: 10px 0;width: 100%;text-align: center;">继续编辑>></view>
					</view>
					
				</view>
	
				<view class="box_text" style="border-bottom: none;">
					<view class="box_text_l">我的名片</view>
				</view>
				<view @click="uploadcard">
					<view class="boxxq" v-if="addMsg.NameCard==''" style="display: flex;flex-direction: column;align-items: center;justify-content: center;">
						<image mode="aspectFill" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/wish-card.png" style="width: 60px;height: 46px;"></image>
						<view style="font-size: 14px;color: #1F1F1F;margin-top: 10px;">添加名片>></view>
					</view>
					<view class="boxxq" v-if="addMsg.NameCard!=''" style="overflow: hidden;border:none">
						<image mode="aspectFill" :src="addMsg.NameCard" style="width: 100%px;height: 170px;border-radius: 10px;"></image>
						
					</view>
				</view>
				
				<view class="box-tj" @click="submit">
					提交
				</view>
				
				
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				mainColor:'',
				addMsg:{
					Id:0,
					BranchName:'',
					CarrierName:'',
					Area:"",
					Description:'',
					NameCard:'',
				},
				WishId:0,
				action: this.host2 + "/api/File/UploadTencent",
				type:1,//1列表为新增时 2列表修改 3详情修改
			}
		},
		onLoad(options){
			if(options && options.Id){
				this.WishId = options.Id
				this.getdetails()
			}
			if(options && options.type){
				this.type = options.type
			}
		},
		created(){
			uni.setNavigationBarTitle({
				title: '我的心愿计划',
			});
			let MallBaseId = uni.getStorageSync("mall_UserInfo").MallBaseId ? uni.getStorageSync("mall_UserInfo").MallBaseId : 1;
			this.action = this.host2 + '/api/File/UploadTencent?MallBaseId=' + MallBaseId
			this.mainColor = this.$uiConfig.mainColor;
		},
		methods:{
			getdetails(){
				let parms = {
					url: "/api/AppletTrade/GetMyWishInfo",
					data:{WishId:this.WishId}
				}
				this.request2(parms, (res) => {
					this.loading = false;
					if (res.resultCode == 1) {
						this.addMsg = res.data
					}
				})
			},
			submit(){//提交
				if(this.addMsg.BranchName == ''){
					uni.showToast({
						title:'请输入品牌或企业信息',
						icon:'none'
					})
					return
				}
				if(this.addMsg.CarrierName == ''){
					uni.showToast({
						title:'请输入对标载体',
						icon:'none'
					})
					return
				}
				if(this.addMsg.Area == ''){
					uni.showToast({
						title:'请输入发展区域',
						icon:'none'
					})
					return
				}
				if(this.addMsg.Description == ''){
					uni.showToast({
						title:'请输入心愿详细',
						icon:'none'
					})
					return
				}
				if(this.addMsg.NameCard == ''){
					uni.showToast({
						title:'请上传我的名片',
						icon:'none'
					})
					return
				}
				uni.showLoading({
					title:'提交中...',
					icon:'none'
				})
				let parms = {
					url: "/api/AppletTrade/SetMyWishInfo",
					data:this.addMsg
				}
				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[pages.length - 2]; // 前一个页面
				let that = this
				
				this.request2(parms, (res) => {
					uni.hideLoading()
					if (res.resultCode == 1) {
						uni.showToast({title: res.message,icon: 'none',})
						
						setTimeout(()=>{
							 uni.navigateBack({
								 success: function() {
									 if(that.type==3){//1列表为新增时 2列表修改 3详情修改
										  beforePage.$vm.getdetails(); // 执行前一个页面的方法
									 }else if(that.type==1){
										 beforePage.$vm.getCarrierPageList(that.type); 
									 }else if(that.type==2){
										 beforePage.$vm.getCarrierPageList(that.type); 
									 }
								 }
							 });
						},1000)
					}
				})
				
				
			},
			gorichText(){
				console.log(this.addMsg.Description)
				let data = this.addMsg.Description
					data= encodeURIComponent(data)//加密
				uni.navigateTo({
					url: '/pages/kotra/wish/richText?Content=' +data
				})
			},
			Children(e){
				let regex = new RegExp('<img', 'gi');
				let richtext = e
				richtext = richtext.replace(regex, `<img width="100%"`); //图片超出的处理
				this.addMsg.Description = richtext
			},
			uploadcard(){
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: async(res) => {
						var tempFilePaths = res.tempFilePaths;
						uni.showLoading({
							title: '正在上传中...'
						})
						for (let temp of tempFilePaths) {
							// 图片上传服务器
							await uni.uploadFile({
								url: this.action,
								filePath: temp,
								name: 'file',
								formData: {
									user: 'test'
								},
								
								success: res => {
									let data = JSON.parse(res.data)
									// 上传完成后处理
									this.addMsg.NameCard = data.data
									uni.hideLoading()
								},
								
							});
						}
					}
				});
			}
		}
	}
</script>

