<template>
	<view class="content">
		<view class="popup-content ffffffff">
			<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.category_name" :data-code="item.category_id" 
					:class="item.category_id==Prov_code?'act':''" class="popup-content-scroll-li flex-center"
					 v-for="(item,index) of Prov_arr" :key='index'>
						{{item.category_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.category_name" :class="item.category_id==City_code?'act':''" 
						:data-code="item.category_id" class="popup-content-scroll-li flex-center "
						 v-for="(item,index) of City_arr" :key='index'>
							{{item.category_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.category_name" :class="item.category_id==Dist_code?'act':''" :data-code="item.category_id"
						 class="popup-content-scroll-li flex-center" v-for="(item,index) of Dist_arr" :key='index'>
							{{item.category_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: 'uniScrollailOne',
		props: {
			Prov_arr: {
				type: Array,
				default () {
					return []
				}
			},
			type: {
				type: Number,
				default: 2,
			},
		},
		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) {
				console.log("info")
				let info;
				if (!this.City_code) {
					uni.showToast({
						title: "请选择分类",
						icon: "none"
					})
					return
				}
				if (this.type == 2) {
					info = {
						mccCd1: this.Prov_code,
						mccCd2: this.City_code,
						mccCd3: this.Dist_code,
						mccCd1_title: this.Prov_title1,
						mccCd2_title: this.City_title1,
						mccCd3_title: this.Dist_title1,
					}
				}
				console.log(info)
				this.$emit('setlet', info)
				this.popup.close();
			},

			City(e) {
				this.request({
					url: "setting/get_type",
					data: {
						category_id: this.Prov_code,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
						this.City_arr = res.data;
					}
				}).catch((res) => {
					this.City_arr = [];
				});
			},

			Dist(e) {
				this.request({
					url: "setting/get_type",
					data: {
						category_id: 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>
