<!-- <customNav :shownav="true" :title="$t('order.lianxikef')"  tinColor="#006AFF" jiantou="0" ></customNav> -->
<template>
	<view>
		<customNav :shownav="true" :title="$t('order.lianxikef')"  tinColor="#006AFF" jiantou="0" ></customNav>
		<view class="content" style="margin-top: 40rpx;">
			<view class="item_list">
				<view class="item_content" v-for="(item,index) in annexList" @click="imagesel(index)">
					<netImage v-if="item!=''" width="220" height="220" bradius="4" :mysrc="item" mymode="scaleToFill" ></netImage>
				</view>
				<view class="item_content" @click="updataImage">
					<image class="upimagV" src="/static/imags/shangctp.png" mode="scaleToFill"></image>
				</view>
			</view>
			<textarea class="pinglun" :placeholder="$t('order.wentimiaos')" :value="remarks" @input="sumfontnum"></textarea>
			<view style="padding: 0 15rpx;margin-bottom: 20rpx;">
				<checkbox-group @change="checkboxChange">
					<label class="contentInRowL" style="margin-top: 8rpx;" v-for="(item,index) in checkList">
						<view>
							<checkbox :value="item.value" :checked="item.checked" />
						</view>
						<view style="font-size: 30rpx;">{{item.name}}</view>
					</label>
				</checkbox-group>
			</view>
			<view style="margin-left: 20rpx;margin-bottom: 20rpx;">
				<radio-group @change="radioChange">
					<label class="" >
						<radio value="0" :checked="shiyong==0" />
						<text style="font-size: 30rpx;color: crimson;">{{$t('kefu.weishiyong')}}</text>
						<radio style="margin-left: 20rpx;" value="1" :checked="shiyong==1"/>
						<text style="font-size: 30rpx;color: crimson;">{{$t('kefu.yishiyong')}}</text>
					</label>
				</radio-group>
			</view>
			
		</view>
		<view class="contentColumnC" style="margin-top: 50rpx;">
			<text class="savebt" @click="uploadMsg">{{$t('index.tijiao')}}</text>
		</view>
		
		<view class="contentColumnC" style="width: 90%;margin-left: 5%;margin-top: 60rpx;">
			<text style="font-size: 30rpx;">{{$t('kefu.pzcanksl')}}</text>
			<text style="margin-top: 10rpx;font-size: 30rpx;">{{$t('kefu.dingdandb')}}</text>
			<view class="contentInRowS" style="width: 100%;">
				<image class="imageSizeA" src="/static/defimags/jietu.jpg" mode="aspectFit"></image>
				<image class="imageSizeA" src="/static/defimags/paizhao.jpg" mode="aspectFit"></image>
				<image class="imageSizeA" src="/static/defimags/abc.jpg" mode="aspectFit"></image>
			</view>
			<text style="margin-top: 20rpx;font-size: 30rpx;">{{$t('kefu.shangptp')}}</text>
			<view class="contentInRowL" style="width: 100%;">
				<image class="imageSizeB" src="/static/defimags/cuowu.jpg" mode="aspectFit"></image>
				<image class="imageSizeB" src="/static/defimags/zhengque.jpg" mode="aspectFit"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "@/pages/api/api.js"
	export default {
		data() {
			return {
				remarks:'',
				ddId:'',
				userInfo:'',
				annexList:[],
				feedlist:[],
				checkList:[],
				shiyong:0,
				language:''
			}
		},
		onLoad(option) {
			this.ddId= option.ddId;
			this.userInfo = uni.getStorageSync('userInfo');
			this.language = uni.getStorageSync('language');
			this.getfeedlist();
		},
		methods: {
			getfeedlist(){
				api('getfeedlist',{},res=>{
					console.log('getfeedlist',res)
					if(res.data.code==200){
						var temp=res.data.data;
						this.feedlist=res.data.data;
						this.checkList=[];
						for(var i=0;i<temp.length;i++){
							var item = temp[i];
							var obj={
								value:item.id,
								checked:false,
								name:this.getcheckValue(item)
							}
							this.checkList.push(obj);
						}
					}
				},failc=>{
					
				})
			},
			getcheckValue(obj){
				if(this.language=='zh-Hans'){
					return obj.contentCh;
				}
				if(this.language=='zh-Hant'){
					return obj.contentTw;
				}
				if(this.language=='yuenan'){
					return obj.contentVi;
				}
				return obj.contentCh;
			},
			
			checkboxChange: function (e) {
				console.log('checkboxChange1',this.checkList)
				var items = this.checkList;
				var values = e.detail.value;
				for (var i = 0; i < items.length;i++) {
					const item = items[i]
					if(values.includes(item.value)){
						this.$set(item,'checked',true)
					}else{
						this.$set(item,'checked',false)
					}
				}
				console.log('checkboxChange2',this.checkList)
			},
			radioChange(e){
				console.log(e.detail.value)
				this.shiyong=e.detail.value;
			},
			uploadMsg(){
				if(this.remarks==''||this.remarks==null||this.remarks==undefined){
					uni.showToast({
					    title:this.$t('order.wentimiaos'),
					    icon: 'none',
					    duration: 2500
					})
					return;
				}
				
				var feedBack=this.getfeedBack();
				if(feedBack.length==0){
					uni.showToast({
					    title:this.$t('kefu.wentileix'),
					    icon: 'none',
					    duration: 2500
					})
					return;
				}
				var data = {
					"ddId":this.ddId, //订单号
					"userType":this.userInfo.userType, //用户类型
					"nickName":this.userInfo.nickName, //昵称
					"content":this.remarks, //内容
					"useCase":this.shiyong,
					"feedBack":JSON.stringify(feedBack),
					"imgs":this.stringimgs(this.annexList) //上传图片
				}
				console.log(data)
				uni.showLoading({
					mask:true
				})
				api('updatakefuMsg',data,res=>{
					console.log('updatakefuMsg',res)
					uni.hideLoading();
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
					setTimeout(function() {
					  // 这里写要延时执行的代码
					  uni.navigateBack();
					}, 2000);
				},failc=>{
					uni.hideLoading();
					//console.log('getadvertis----',failc)
				})
			},
			getfeedBack(){
				var temp=[];
				for(var i=0;i<this.checkList.length;i++){
					if(this.checkList[i].checked==true){
						for(var j=0;j<this.feedlist.length;j++){
							if(this.checkList[i].value==this.feedlist[j].id){
								temp.push(this.feedlist[j].id);
							}
						}
					}
				}
				return temp;
			},
			stringimgs(list){
				var str='';
				for(var i=0;i<list.length;i++){
					if(i==0){
						str=list[i];
					}
					else{
						str=str+','+list[i];
					}
				}
				return str
			},
			sumfontnum(e){
				this.remarks=e.target.value;
			},
			imagesel(index){
				var that = this;
				uni.showModal({
					cancelText:that.$t('order.quxiao'),
					confirmText:that.$t('comp.queren'),
				    title: that.$t('api.message'),
				    content:that.$t('order.shanchutp'),
				    success: function (res) {
				        if (res.confirm) { //这里是点击了确定以后
							var temList = [];
							for(var i=0;i<that.annexList.length;i++){
								if(i!=index){
									temList.push(that.annexList[i]);
								}
							}
							that.annexList=temList;
				        } else { //这里是点击了取消以后
				          console.log('点击取消')
				        }
				    }
				})
			},
			updataImage(){
				console.log('selectImage');
				 var that = this;
				 uni.chooseImage({
				 	count: 1,  // 图片数量
				 	sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
				 	sourceType: ['album'], //从相册选择或者拍照
				 	success: (res) => {
				 		const tempFilePaths = res.tempFilePaths;
				 		console.log('-----',tempFilePaths)
						uni.showLoading({
							mask:true
						})
				 		uni.uploadFile({
				 			url:'https://api.awayqtw.com/utils/Upload', //上传图片api
				 			filePath: tempFilePaths[0],
				 			name: 'file',
				 			header:{
				 				//"Authorization": userinfo.token
				 			},
				 			success: (res) => {
								uni.hideLoading();
				 				let group =  JSON.parse(res.data);
				 				that.annexList.push(group.data);
								console.log(that.annexList);
				 			},
							fail: (res) =>{
								uni.hideLoading();
								console.log('uni.uploadFile',res)
							}
				 		});
				 	}
				 });
			},
		}
	}
</script>

<style>
.item_list{
	padding: 0 15rpx;
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-start;
	.item_content{
		width:210rpx;
		height:210rpx;
		margin: 10rpx;
		box-sizing: border-box;
	}
}
.upimagV{
	width: 210rpx;
	height:210rpx;
}
.pinglun{
	margin: 16rpx;
	padding: 10rpx;
	width:92%;
	height: 100rpx;
	border-radius: 15rpx;
	border: 2rpx solid lightgray;
}
.savebt{
	text-align: center;
	font-size: 36rpx;
	width: 80%;
	height: 80rpx;
	line-height: 80rpx;
	color: white;
	background-color: green;
	border-radius: 10rpx;
}
.imageSizeA{
	padding: 10rpx;
	width: 28%;
	background-color: whitesmoke;
}

.imageSizeB{
	padding: 10rpx;
	margin-left: 10rpx;
	width: 40%;
	background-color: whitesmoke;
}
</style>