<template>
	<view class="content">
		<view class="popup-content">
			
			<view class="">
				<view class="box-pack-between ft32 flex-center popup-content-title">
					<text @click="close">关闭</text>
					<text style="color: #003A9B;" @click="confirm">确认</text>
				</view>
				<view class="ft22 tips cate border-b">
					<view class="">
						Tip:请根据小程序自身的功能，正确选择服务类目。
					</view>	
					餐饮行业选择服务类型是：餐饮 > 餐饮服务场所/餐饮服务管理企业,商业服务 > 公关/推广/市场调查
				</view>
				
			</view>
			
			<view class="flex">
				<scroll-view scroll-y class="popup-content-scroll">
					<view @click="bindProv" :data-title="item.name" :data-code="item.id" :class="item.id==Prov_code?'act':''"
					 class="popup-content-scroll-li flex-center" v-for="(item,index) of Prov_arr" :key='index'>
						{{item.name}}
					</view>
				</scroll-view>
				
				<scroll-view scroll-y class="popup-content-scroll">
					<block v-if="City_arr.length>0">
						<view @click="bindCity" :data-innername="item.inner_name" :data-title="item.name" 
						:class="item.id==City_code?'act':''" :data-code="item.id"
						 class="popup-content-scroll-li flex-center " v-for="(item,index) of City_arr" :key='index'>
							{{item.name}}
						</view>
					</block>
					<view v-else class="City  popup-content-scroll-li flex-center">
						请选择
					</view>
				</scroll-view>
				
				<scroll-view scroll-y class="popup-content-scroll">
			<!-- 		<block v-if="Dist_arr.length>0">
						<view @click="bindDist" :data-title="item.city_name" :class="item.cityid==Dist_code?'act':''" :data-code="item.cityid"
						 class="popup-content-scroll-li flex-center" v-for="(item,index) of Dist_arr" :key='index'>
							{{item.city_name}}
						</view>
					</block> -->
					<block v-if="innername">
					<view  class="City popup-content-scroll-li flex-center ft26">
						{{innername}}
					</view>
					<view class="home-img" @click="uploadFile" data-type='1'>
						<image :src="URL+xcx_logo" class="home-img-icon"></image>
					</view>
					</block>
				</scroll-view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'uniScroll',
		props: {
			Prov_arr: {
				type: Array,
				default () {
					return []
				}
			},
			type: {
				type: Number,
				default: 1,
			},
		},
		inject: ['popup'],
		data() {
			return {
				
				City_arr: [],
				Dist_arr: [],
				Prov_code: "",
				City_code: "",
				Dist_code: "",

				Prov_title1: "",
				City_title1: "",
				Dist_title1: "",
				Prov_title: "",
				City_title: "",
				Dist_title: "",
				innername:"",
				xcx_logo:"",			
				URL: getApp().globalData.URL,
			}
		},
		onLoad() {

		},

		methods: {
			uploadFile(e) {
				uni.chooseImage({
					success: (res) => {
						res.tempFilePaths.forEach((v, i) => {
							console.log(v)
							this.Upload({
								url: "setting/upload",
								data: {
									url: v,
									admin_id: uni.getStorageSync("admin_id"),
								}
							}).then(res => {
								console.log(res, "res")
								this.xcx_logo = res.src;
							}).catch({});
						})
					}
				});
			},
			
			// 商户地址省
			bindProv(e) {
				this.Prov_code = e.currentTarget.dataset.code;
				this.Prov_title1 = e.currentTarget.dataset.title;
				this.Dist_arr = [];
				this.Dist_code = "";
				this.City_code = "";
				this.City();
			},
			
			// 商户地址市
			bindCity(e) {
				console.log(e)
				let {code,title,innername }=e.currentTarget.dataset;
				this.City_code = code;
				this.City_title1 = title;
				this.innername=innername;
				this.Dist_code = "";
				// this.wechat_secondcode();
			},
			
			// 商户地址区
			bindDist(e) {
				
				this.Dist_title1 = e.currentTarget.dataset.title;
				this.Dist_code = e.currentTarget.dataset.code;
				
			},
			
			close(e) {
				this.popup.close();
				// this.$refs.popup.close();
			},

			confirm(e) {
				let info;
				if (!this.City_code||!this.Prov_code) {
					uni.showToast({
						title: "请选择",
						icon: "none"
					})
					return
				} 
				info = {
						code1: this.Prov_code,
						code2: this.City_code,
						// Dist_code: this.Dist_code,
						Prov_title: this.Prov_title1,
						City_title: this.City_title1,
						special_license_pic :this.xcx_logo,
						zzzs_name :this.innername,
						// Dist_title: this.Dist_title1,
				}
				this.$emit('select', info)
				this.popup.close();
			},


			City(e) {
				this.request({
					url: "setting/wechat_secondcategory",
					data: {
						id: this.Prov_code,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code =="200") {
						this.City_arr = res.data;
					}
				}).catch((res) => {
					// this.City_arr = [];
				});
			},
			
			wechat_secondcode(){
				this.request({
					url: "setting/wechat_secondcode",
					data: {
						id: this.City_code,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
					
					}
				}).catch((res) => {
				
				});
			},
			
			Dist(e) {
				
				this.Dist_arr = res.data;
				
				return
				this.request({
					url: "setting/getcity",
					data: {
						cityid: this.City_code,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
						this.Dist_arr = res.data;
					}
				}).catch((res) => {
					this.Dist_arr = [];
				});
			},
			
			
		}
	}
</script>

<style>
	page .act {
		color: #007AFF;
	}
	.popup-content {
		width: 100%;
		background: #fff;
		padding: 0rpx 40rpx;
	}

	.popup-content-title {
		border-bottom: 1rpx solid #F1F1F1;
		padding: 10rpx 0rpx;
	}

	.popup-content-scroll {
		height: 590rpx;
		width: 33%;
		text-align: center;
	}

	.popup-content-scroll-li {
		padding: 8rpx 0;
	}
	.home-img-icon {
		border: 1rpx solid #ccc;
		width: 200rpx;
		height: 200rpx;
	}
</style>
