<template>
	<view>
		<view class="prefecture form-group mb20">
			<!-- 复购编号 -->
			<view class="form-item" v-if="cid == 33">
				<view class="form-label">
					<text class="domation mr10">*</text>
					{{ $t('APP_ADD_29') }}
				</view>
				<view class="disabled-input">{{ form.upgradeMemberCode }}</view>
			</view>
			<view class="form-item" v-else>
				<view class="form-label">
					<text class="domation mr10">*</text>
					{{ $t('w_0245') }}
				</view>
				<input @blur="changeInput('upgradeMemberCode')" class="form-input" type="text" v-model="form.upgradeMemberCode" :placeholder="$t('w_0280')" />
			</view>
			<!-- 复购姓名 -->
			<view class="form-item" v-if="cid == 33">
				<view class="form-label">
					<text class="domation mr10">*</text>
					{{ $t('APP_ADD_30') }}
				</view>
				<view class="disabled-input">{{ form.upgradeMemberName }}</view>
			</view>
			<view class="form-item" v-else>
				<view class="form-label">
					<text class="domation mr10">*</text>
					{{ $t('w_0246') }}
				</view>
				<view class="disabled-input">{{ form.upgradeMemberName }}</view>
			</view>
			<!-- 发货方式 -->
			<view class="form-item" style="border-bottom: 1rpx solid #eee;" @click="opendeliveryShow" v-if="deliveryList">
				<view class="form-label">
					<text class="domation mr10">*</text>
					{{ $t('w_0061') }}
				</view>
				<view class="form-input">{{ deliveryIndex }}</view>
				<text class="icon iconfont icon-jiantou" v-if="userCountry != 1"></text>
			</view>
			<u-picker
				:cancelText="$t('MN_F_31')"
				:confirmText="$t('MN_F_32')"
				@cancel="deliveryShow = false"
				:show="deliveryShow"
				ref="deliveryList"
				:columns="[deliveryList]"
				@confirm="changeDelivery"
				keyName="label"
			></u-picker>
			<!-- 会员店铺 -->
			<view class="form-item" style="border-bottom: 1rpx solid #eee;" @click="openStoreDialog" v-if="userCountry != 1 && form.deliveryWay != 2">
				<view class="form-label">
					<text class="domation mr10">*</text>
					{{ $t('w_0100') }}
				</view>
				<view class="form-input">{{ storeIndex }}</view>
				<text class="icon iconfont icon-jiantou" v-if="userCountry != 1"></text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			deliveryIndex: '',
			transportIndex: 0,
			storeIndex: '',
			storehouseIndex: '',
			deliveryShow: false,
			storeShow: false,
			showStoreDialog: false,
       		filteredStores: [],
        	searchTerm: '',
			storeData:{},
		};
	},
	inject: ['form'],
	props: ['cid','deliveryList', 'transportType', 'userCountry', 'storeList', 'storehouse','storeLists'],
	created() {
		let self= this;
		self.$fire.on('handleStoreData', function(n) {
			console.log(n,'n');
				self.handleStoreData(n)
			})
		console.log(this.userCountry,'111');
	},
	watch:{
		deliveryList: function(n, o) {
			if (n != o && n!='') {
				this.deliveryIndex = n[0].label;
				this.form.deliveryWay = n[0].value;
			}
		},
	},
	methods: {
		 openStoreDialog() {
            uni.navigateTo({
                url: '/pages/prefecture/part/memberStore' // 跳转到子页面
            });
        },
        handleStoreData(data) {
            this.storeData = data; // 接收子页面传递的数据
			 this.storeIndex = this.storeData.storeName+'('+this.storeData.storeCode+')';
			this.form.pkMemberStore = this.storeData.pkId;
        },
		opendeliveryShow() {
			if (this.userCountry == 1) {
				return;
			}
			this.deliveryShow = true;
		},
		changePkMemberStore(e) {
			this.storeIndex = e.value[0].storeName;
			if (this.storeList) {
				this.form.pkMemberStore = e.value[0].pkId;
			}
			this.storeShow = false;
		},
		changeDelivery(e) {
			// this.deliveryIndex = e.detail.value;
			// this.form.deliveryWay = this.deliveryList[this.deliveryIndex].value;
			this.deliveryIndex = e.value[0].label;
			this.form.deliveryWay = e.value[0].value;
			this.$emit('queryOrderPostage');
			this.deliveryShow = false;
		},
		changeStore(e) {
			this.storeIndex = e.detail.value;
			if (this.storeList) {
				this.form.pkMemberStore = this.storeList[this.storeIndex].pkId;
			}
		},
		changeStorehouse(e) {
			this.storehouseIndex = e.detail.value;
			if (this.storehouse) {
				this.form.pkStorehouse = this.storehouse[this.storehouseIndex].pkId;
			}
		},
		changeInput(e) {
			this.$emit('changeInput', e);
		},
		changeTransport(e) {
			this.transportIndex = e.detail.value;
			this.form.transType = this.transportType[this.transportIndex].value;
			this.$emit('queryOrderPostage');
		},
		changeAccount(e) {
			this.bank_index = e.detail.value;
			console.log(this.bank_index);
			this.form.pkBank = this.accountList[this.bank_index].value;
		},
		changeType(n) {
			this.registType = n;
		},
		changePlaceDept(e) {
			this.form.placeDept = e.detail.value + 1;
			this.changeInput('placeDept');
		},
		closeQuery() {
			this[this.poptype] = this.queryValue;
			if (this.poptype == 'pkSettleCountry') {
				this.form.pkSettleCountry = this.countryList[this.pkSettleCountry].pkId;
			} else {
				this.form.pkCountry = this.countryList[this.pkCountry].pkId;
			}
			this.isQuery = false;
		},
		changeQuery(e) {
			this.queryValue = e.detail.value[0];
		},
		moveHandle() {
			return false;
		},
		openCPop(name) {
			this.poptype = name;
			this.isQuery = true;
		}
	}
};
</script>

<style lang="scss">
.title-row {
    display: flex;
    justify-content: space-between;
    padding: 20rpx 0rpx;
	margin-left: 20rpx;
    border-bottom: 1rpx solid #ccc;
    font-weight: bold;
}

.title-row span {
    flex: 1;
}

.fixed-rows {
    padding: 0;
    margin: 0;
    list-style: none;
}

.data-item {
    display: flex;
    justify-content: space-between;
    padding: 30rpx 0; /* 调整每个数据项的上下内边距 */
    border-bottom: 1px solid #eee; /* 添加底部边框 */
	margin-bottom: 10rpx;
}
.data-item view {
    flex: 1; /* 均分每个数据项的宽度 */
    white-space: nowrap; /* 不换行 */
    overflow: hidden; /* 超出部分隐藏 */
    text-overflow: ellipsis; /* 超出部分用省略号表示 */
	margin-left: 10rpx;
}
.pop-up-bg {
	position: fixed;
	background-color: rgba(0, 0, 0, 0.6);
	left: 0;
	top: 0;
	width: 100%;
	height: 100vh;
	z-index: 99;
}

.pop-up {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 50vh; /* 限制最大高度 */
    overflow-y: auto; /* 当内容超出时，允许垂直滚动 */
	background-color: #ffffff;
	z-index: 100;
}

.form-title {
	width: 750rpx;
	height: 106rpx;
	background: #fb3024;
	padding-left: 44rpx;
	padding-right: 25rpx;
	position: relative;
	box-sizing: border-box;
	font-size: 28rpx;
	color: #ffffff;
	line-height: 106rpx;
	font-weight: bold;
	z-index: 1;
}

.form-title.redtitle {
	width: 750rpx;
	height: 106rpx;
	background: #fb3024;
	padding-left: 44rpx;
	position: relative;
	box-sizing: border-box;
	font-size: 28rpx;
	color: #fff;
	line-height: 106rpx;
	font-weight: bold;
	z-index: 1;
}

.form-title::before {
	content: '';
	position: absolute;
	top: 0;
	bottom: 0;
	margin: auto;
	left: 25rpx;
	width: 6rpx;
	height: 24rpx;
	background-color: #fb3024;
	z-index: 1;
}

.redtitle.form-title::before {
	content: '';
	position: absolute;
	top: 0;
	bottom: 0;
	margin: auto;
	left: 25rpx;
	width: 6rpx;
	height: 24rpx;
	background-color: #fff;
	z-index: 1;
}
</style>
