<style>
	.row{
		display: flex;
		
	}
	.items-center{
		align-items: center;
	}
	.fatContent {
		background-color: #fff;
		margin-bottom:80px;
	}

	.fatContent .compInfoList {
		width: 100%;
		display: flex;
		height: 50px;
		align-items: center;
		padding: 0 20px;
		border-bottom: 1px solid #F2F3F6;
	}

	.fatContent .comInforName {
		width: 25%;
		color: #000;
	}

	.fatContent .comInforName text {
		color: red;
		margin-left:3px;
	}

	.fatContent .fatInfoInput {
		width: 75%;
		margin-top: 2px;
		color:#000000;
		text-align: right;
	}
	.fatContent .fatInBtn{
		position: fixed;
		bottom:0;
		width:100%;
		height:50px;
		color:#fff;
		z-index:99;
		font-size: 16px;
		text-align: center;
		line-height: 50px;
		background-color: #017EDF;
		padding-bottom: env(safe-area-inset-top);
	}
	.fatContent .inputM{
		margin: 15rpx;
		width: 89%;
		padding:15px;
		background-color: #F7F7F7;
	}
</style>
<template>
	<view class="fatContent">
		<template v-if="this.type==0">
			<view class="compInfoList">
				<view class="comInforName">
					公司名称<text>*</text>
				</view>
				<input class="uni-input fatInfoInput" v-model="msg.CompanyName" placeholder="请输入公司名称" />
			</view>
			<view class="compInfoList">
				<view class="comInforName">
					联系人<text>*</text>
				</view>
				<input class="uni-input fatInfoInput" v-model="msg.Principal" placeholder="请输入联系人" />
			</view>
			<view class="compInfoList">
				<view class="comInforName">
					联系方式<text>*</text>
				</view>
				<input class="uni-input fatInfoInput" type="number" v-model="msg.Mobile" placeholder="请输入联系方式" />
			</view>
			<view class="compInfoList">
				<view class="comInforName">
					E-mail<text>*</text>
				</view>
				<input class="uni-input fatInfoInput" v-model="msg.EMail" placeholder="请输入邮箱" />
			</view>
			<view class="compInfoList">
				<view class="comInforName">
					FAT海关编码
				</view>
				<input class="uni-input fatInfoInput" v-model="msg.FatCode" placeholder="FAT海关编码" />
			</view>
			<view class="compInfoList">
				<view class="comInforName">
					咨询标题<text>*</text>
				</view>
				<input class="uni-input fatInfoInput" v-model="msg.FatTitle" placeholder="请输入标题" />
			</view>
		</template>
		<view class="rounded" style="background-color: #017EDF16;padding: 20rpx;margin: 30rpx;border-radius: 12rpx;" v-else>
			<view class="" style="font-size: 32rpx;color: #017EDF;font-weight:bold;">投诉建议</view>
			<view class="" style="margin-top: 30rpx;">
				<view class=" row items-center" @click="setPhone">
					<text style="font-size: 22rpx;">热线电话：</text>
					<u-icon name="phone" color="#017EDF"></u-icon>
					<text style="font-size: 28rpx;margin-left: 6rpx;"> 0831-2205915</text>
				</view>
				<view class=" row items-center" @click="setEmail" style="margin-top: 30rpx;">
					<text style="font-size: 22rpx;">电子邮箱：</text>
					<u-icon name="email" color="#017EDF"></u-icon>
					<text style="font-size: 28rpx;margin-left: 6rpx;">1071313880@qq.com</text>
				</view>
			</view>
		</view>
		<view class="compInfoList" style="border-bottom:0;height:30px;margin-top:15px;">
			<view class="comInforName">
				{{ type==0?'咨询问题':'线上填写' }}<text>*</text>
			</view>
		</view>
		<!-- <input type="textarea" class="uni-input fatInfoInput" v-model="msg.FatQuestion" placeholder="请输入具体咨询问题" /> -->
		<textarea style="height: 120px;" class="inputM" v-model="msg.FatQuestion" :placeholder="`请输入具体${type==0?'咨询问题':'投诉建议的内容'}`"  />
		<view class="fatInBtn" @click="saveInfo()">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "咨询",
				dataList: [],
				msg: {
					CompanyName:'', //公司名称
					Principal:'', //联系人
					Mobile:'', //联系电话
					EMail:'', //邮箱
					FatCode:'', //海关编码
					FatTitle:'', //咨询标题
					FatQuestion:'' //咨询问题
				},
				type: 0
			};
		},
		mounted() {
			
		},
		onLoad(options) {
			if(options.t){
				this.type=options.t
			}
			this.pageTitle = this.type==0?'新增咨询':'新增投诉建议'
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		},
		created() {
			this.getList();
		},
		onShow() {

		},
		methods: {
			setPhone(){
				uni.makePhoneCall({
					phoneNumber: '0831-2205915' //仅为示例
				});
			},
			setEmail(){
				uni.setClipboardData({
					data: '1071313880@qq.com',
					success: function () {
						uni.showToast({
							icon:'none',
							title:'邮箱地址已复制'
						})
					}
				});
			},
			//获取数据
			//获取数据
			getList() {
				uni.showLoading({
					title: '加载中'
				});
				this.request2({
						url: "/api/AppletTrade/GetUserCompany",
						data: {},
					},
					(res) => {
						uni.hideLoading();
						if (res.resultCode == 1) {
							let tempData = res.data;
							if (tempData) {
								if(tempData.CompanyName){
									this.msg.CompanyName = tempData.CompanyName;
								}
								if(tempData.Principal){
									this.msg.Principal = tempData.Principal;
								}
								if(tempData.Mobile){
									this.msg.Mobile = tempData.Mobile;
								}
								if(tempData.EMail){
									this.msg.EMail = tempData.EMail;
								}
							}
						}
					}
				);
			},
			//保存数据
			saveInfo(){
				if(this.type==0){
					if(this.msg.CompanyName==''){
						uni.showToast({
						  title: "请输入公司名称",
						  icon:'none'
						});
						return;
					}
					if(this.msg.Principal==''){
						uni.showToast({
						  title: "请输入联系人",
						  icon:'none'
						});
						return;
					}
					if(this.msg.Mobile==''){
						uni.showToast({
						  title: "请输入联系方式",
						  icon:'none'
						});
						return;
					}
					if(this.msg.EMail==''){
						uni.showToast({
						  title: "请输入邮箱",
						  icon:'none'
						});
						return;
					}
					if(this.msg.FatTitle==''){
						uni.showToast({
						  title: "请输入咨询标题",
						  icon:'none'
						});
						return;
					}
				}
				if(this.msg.FatQuestion==''){
					uni.showToast({
					  title: this.type==0?"请输入咨询问题":'请输入你要投诉建议的内容',
					  icon:'none'
					});
					return;
				} else if(this.type!=0){
					const newMsg = {
						CompanyName:this.msg.CompanyName!=''?this.msg.CompanyName:'未知', //公司名称
						Principal:this.msg.Principal!=''?this.msg.Principal:'未知', //联系人
						Mobile:this.msg.Mobile!=''?this.msg.Mobile:'未知', //联系电话
						EMail:this.msg.EMail!=''?this.msg.EMail:'未知', //邮箱
						FatCode:'', //海关编码
						FatTitle:'投诉建议', //咨询标题
						FatQuestion:this.msg.FatQuestion //咨询问题
					}
					this.msg = newMsg
				}
				this.request2({
						url: "/api/AppletTrade/SetCommerceAsk",
						data: this.msg,
					},
					(res) => {
						if (res.resultCode == 1) {
							uni.showToast({
							  title: "保存成功",
							});
							this.getList();
							const cur = getCurrentPages()
							if(cur.length>1){
								uni.navigateBack({
									delta: -1
								})
							}else{
								uni.navigateTo({
									url:'/pages/kotra/zixunList'
								})
							}
						}
					}
				);
			}
		},
	}
</script>
