<template>
	<view class="content">
		<view class="popup-content">
			<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="flex">
				<scroll-view scroll-y class="popup-content-scroll">
					<view @click="bindProv" :data-title="item.city_name" :data-code="item.cityid" :class="item.cityid==Prov_code?'act':''"
					 class="popup-content-scroll-li flex-center" v-for="(item,index) of Prov_arr" :key='index'>
						{{item.city_name}}
					</view>
				</scroll-view>
				<scroll-view scroll-y class="popup-content-scroll">
					<block v-if="City_arr.length>0">
						<view @click="bindCity" :data-title="item.city_name" :class="item.cityid==City_code?'act':''" :data-code="item.cityid"
						 class="popup-content-scroll-li flex-center " v-for="(item,index) of City_arr" :key='index'>
							{{item.city_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>
					<view v-else class="City popup-content-scroll-li flex-center">
						请选择
					</view>
				</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: "",
			}
		},
		onLoad() {

		},

		methods: {
			// 商户地址省
			bindProv(e) {
				this.Prov_code = e.currentTarget.dataset.code;
				this.Prov_title1 = e.currentTarget.dataset.title;
				this.Dist_arr = [];
				this.Dist_code = "";
				this.City();
			},
			// 商户地址市
			bindCity(e) {
				this.City_code = e.currentTarget.dataset.code;
				this.City_title1 = e.currentTarget.dataset.title;
				this.Dist_code = "";
				this.Dist();
			},
			// 商户地址区
			bindDist(e) {
				this.Dist_title1 = e.currentTarget.dataset.title;
				this.Dist_code = e.currentTarget.dataset.code;
			},
			close(e) {
				this.$refs.popup.close();
			},

			confirm(e) {
				let info;
				if (!this.Dist_code) {
					uni.showToast({
						title: "请选择区",
						icon: "none"
					})
					return
				}
				// if (this.type == 1) {
					info = {
						Prov_code: this.Prov_code,
						City_code: this.City_code,
						Dist_code: this.Dist_code,
						Prov_title: this.Prov_title1,
						City_title: this.City_title1,
						Dist_title: this.Dist_title1,
					}
				// } 
				console.log(info)
				this.$emit('select', info)
				this.popup.close();
			},

			City(e) {
				this.request({
					url: "setting/getcity",
					data: {
						// token: uni.getStorageSync("token"),
						cityid: this.Prov_code,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code =="200") {
						this.City_arr = res.data;
					console.log(this.City_arr, "City_arr")
					}
				}).catch((res) => {
					// this.City_arr = [];
				});
			},
			
			Dist(e) {
				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%;
		height: 656rpx;
		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;
	}
</style>
