<template>
	<view class="lists">
		<!-- <view class="status_bar" :style="navHeight">
		</view> -->
		<scroll-view class="scroll-area view" :scroll-top="scrollTop" show-scrollbar='false' scroll-y="true">
			<view class="main">
				<view class="middle view" v-if="!isTerminalType">
					<view class="text-block">
						<text class="middle-date">是否分流</text>
						<view class="middle-date-des uni-list picker-year">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<picker class="picker-block" @change="bindPickerChange($event,'shunt')" :value="shuntIndex"
										range-key='name' mode="selector" :range="shuntArr" :disabled="isV032NormalApply">
										<text class="uni-input">{{orderItem.shuntName || '请选择'}}</text>
									</picker>
								</view>
							</view>
							<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
						</view>
					</view>
					<view class="text-block" @click="handleShunt" v-if="orderItem.isShunt - 1 === 0">
						<text class="middle-date">分流经销商</text>
						<view class="middle-date-des uni-list picker-year" >
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<text class="uni-input">{{orderItem.shuntDealerName}}</text>
								</view>
							</view>
							<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
						</view>
					</view>
					
					<view class="text-block text-block-last" v-if="orderItem.isShunt - 1 === 0">
						<text class="middle-date" v-if="orderItem.isShunt - 1 === 0">分流渠道</text>
						<view class="middle-date-des uni-list picker-year" v-if="orderItem.isShunt - 1 === 0">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<picker class="picker-block" @change="bindPickerChange($event,'shuntType')" :value="Number(shuntTypeIndex) || 0"
										range-key='name' mode="selector" :range="shuntTypeArr">
										<text class="uni-input">{{orderItem.shuntTypeName || '请选择'}}</text>
									</picker>
								</view>
							</view>
							<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="middle view address-view">
					<view class="text-address" v-if="orderItem.isShunt - 1 === 0" @click="handleShuntAddress">
						<text class="middle-date-unit">分流收货单位</text>
						<view class="middle-date-des-unit uni-list picker-year" >
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<text class="middle-date-address-text">{{orderItem.shuntReceiveUnitName}}</text>
								</view>
							</view>
							<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
						</view>
					</view>
					<view class="text-address" @click="handleReceiveUnit" v-if="!isTerminalType">
						<text class="middle-date-unit">收货单位</text>
						<view class="middle-date-des-unit uni-list picker-year">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<text class="middle-date-address-text">{{orderItem.receiveUnitName || '请选择'}}</text>
								</view>
							</view>
							<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
						</view>
					</view>
					<view class="text-address" v-if="isTerminalType">
						<text class="middle-date-unit">收货终端</text>
						<view class="middle-date-des-unit uni-list picker-year">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<text class="middle-date-address-text">{{orderItem.receiveUnitName || '请选择'}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="text-address">
						<text class="middle-date-unit">喷码单位</text>
						<!-- <view class="middle-date-des-unit uni-list picker-year" @click="handleCustomer"> -->
						<view class="middle-date-des-unit uni-list picker-year">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<text class="middle-date-margin-des">{{orderItem.spurtCodeUnitName}}</text>
								</view>
							</view>
							<!-- <image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image> -->
						</view>
					</view>
					<view class="text-block text-block-last">
						<text class="middle-date">收货联系人</text>
						<input class="middle-date-des" type="text" v-model="orderItem.contacPerson" :disabled="!isTerminalType && !isV032NormalApply" placeholder="请输入" />
						<!-- <text class="middle-date-des">{{orderItem.contacPerson}}</text> -->
					</view>
				</view>
				<view class="middle view">
					<view class="text-block">
						<text class="middle-date">联系人电话</text>
						<input class="middle-date-des" type="text" v-model="orderItem.contactNumber" :disabled="!isTerminalType && !isV032NormalApply" placeholder="请输入" />
					</view>
					<view class="text-address">
						<text class="middle-date-add">收货地址</text>
						<text class="middle-date-des-add">{{orderItem.receiveAddress}}</text>
					</view>
					<text class="edit-add" @click="handleAdd" v-if="isTerminalType || isV032NormalApply">修改</text>
					<view class="text-block text-block-last">
						<text class="middle-date">备注</text>
					</view>
					<view class="remark">
						<textarea class="remark-text" v-model="orderItem.remark" />
					</view>

					<!-- <view class="text-block title-first">
						<text class="middle-date title-first__text">上传文件</text>
					</view>
					<view class="upload-block">
						<uni-file-picker ref='files' :auto-upload='false' v-model="fileList" file-mediatype="image"
							:imageStyles="imageStyles" @select="select" @progress="progress" @success="success"
							@fail='fail'>
							<text>+</text>
						</uni-file-picker>
					</view> -->
				</view>
				<view class="middle summary">
					<view class="summary-block">
						<image class="icon_plan" src="@/static/image/icon_plan@3x.png" mode=""></image>
						<text class="upload-text">附件上传(最多上传3张图片)</text>
					</view>
					<view class="upload-block">
						<uni-file-picker ref='files' limit="3" :auto-upload='false' :value="allFilesPath" v-model="allFilesPath" file-mediatype="image"
							:imageStyles="imageStyles" @select="select" @progress="progress" @success="success" @fail='fail' @delete='deletes'>
							<text>+</text>
						</uni-file-picker>
					</view>
				</view>
				<!-- <text class="receive-record">历史收货信息</text>
				<view class="middle view receive-record-view">
					<view class="text-block text-block-last receive-record-info">
						<text class="record-info-title">唐伟 133****9732</text>
						<text class="record-info-des">广东省云浮市罗定市银霄街294号</text>
					</view>
				</view>-->
				<view class="bottom-area"></view>
				<view class="bottom">
					<button class="btn btn-l" type="default" @tap="preStep">
						<text class="btn-text btn-text-l">上一步</text>
					</button>
					<button class="btn btn-l" type="default" @tap="preSave" v-if="!orderItem.saveTimes || orderItem.saveTimes - 1 !== 0">
						<text class="btn-text btn-text-l">保存</text>
					</button>
					<button class="btn" type="default" @tap="nextStep">
						<text class="btn-text">提交</text>
					</button>
				</view>
			</view>
			<uni-popup ref="popup" background-color="#fff"  :mask-click='false'>
				<view class="popup-content">
					<view class="popup-content-head">
						<image class="popup-content-head__icon" src="@/static/image/order_success@3x.png" mode=""></image>
					</view>
					<view class="popup-content-content">
						<text class="popup-content-content__title">提交成功</text>
						<text class="popup-content-content__title2">要货单号：{{ objectId }}</text>
					</view>
					<view class="popup-content-foot">
						<text class="popup-content-foot__btn" @click="fnBackHome()">回到首页</text>
						<text class="popup-content-foot__btn popup-content-foot__sure"
							@click="fnCheckOrderByNo()">查看订单</text>
					</view>
				</view>
			</uni-popup>
		</scroll-view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import store from '@/store/index.js'
	import {
		querySysDictionaryDetailsByCode,
		getReceipt,
		findByCustomer,
		startProcessInstanceByKey,
		advance,
		saveBizData,
		webUploadFile,
		doDeleteFile,
		doQuery, 
		attachmentDownFile,
		findShuntAnyByDealer,
		findFirstByTerminalId,
		exceedMonthPlan
	} from '@/servers/purchaseList.js'
	import { pathToBase64, base64ToPath } from 'image-tools'
	export default {
		data() {
			return {
			terminalAdd: {
				REGION: '',
				REGION_TEXT: '',
				CITY_CODE: '',
				CITY_TEXT: '',
				STREET_CODE: '',
				STREET_TEXT: '',
				STREET: ''
			},
			// V032普通要货申请的地址数据
			commonAddressData: {
				REGION: '',
				REGION_TEXT: '',
				CITY_CODE: '',
				CITY_TEXT: '',
				STREET_CODE: '',
				STREET_TEXT: '',
				STREET: ''
			},
				isRadio: false,
				receiveUnitArr: [],
				shuntArr: [],
				shuntTypeArr: [],
				shuntIndex: 0, // 是否分流的索引值
				shuntTypeIndex: 0, // 分流渠道的索引值
				receiveUnitIndex: 0, // 收货单位的索引值
				array: ['2021', '2020', '2019', '2018'],
				array1: [{'id':0,val:'00'},{'id':1,val:'01'}],
				index: 0,
				quantity: '',
				remark: '',
				fileList: [],
				scrollTop: 0,
				objectId: '',
				flag: false,
				allFiles: [],
				allFilesPath: [],
				// 保存页面加载时的默认值，用于从"是"切换回"否"时恢复
				defaultReceiveUnit: {
					receiveUnitCode: '',
					receiveUnitName: '',
					spurtCodeUnitName: '',
					contactNumber: '',
					contacPerson: '',
					receiveAddress: ''
				}
			}
		},
		props: {
			sourceType: {
				type: String,
				default: ''
			},
			orderItem: {
				type: Object,
				default () {
					return {}
				}
			},
		},
		watch: {
			'orderItem.isShunt' :function (newName,oldName){
				console.log(newName,'newName', oldName, 'oldName')
				// 从"是"切换到"否"时，恢复默认值
				if(newName - 0 === 0 && oldName && oldName - 0 !== 0){
					// 清空分流相关字段
					this.orderItem.shuntReceiveUnitName = ''
					this.orderItem.shuntReceiveUnitCode = ''
					this.orderItem.shuntChannelsType = ''
					this.orderItem.shuntDealer = ''
					this.orderItem.shuntDealerName = ''
					this.orderItem.shuntTypeName = ''
					this.shuntTypeIndex = 0 // 重置分流渠道索引
					
					// 恢复收货单位、喷码单位、收货联系人、联系人电话、收货地址为默认值
					if(this.defaultReceiveUnit && this.defaultReceiveUnit.receiveUnitCode){
						this.orderItem.receiveUnitCode = this.defaultReceiveUnit.receiveUnitCode
						this.orderItem.receiveUnitName = this.defaultReceiveUnit.receiveUnitName
						this.orderItem.spurtCodeUnitName = this.defaultReceiveUnit.spurtCodeUnitName
						this.orderItem.contactNumber = this.defaultReceiveUnit.contactNumber
						this.orderItem.contacPerson = this.defaultReceiveUnit.contacPerson
						this.orderItem.receiveAddress = this.defaultReceiveUnit.receiveAddress
						// 更新收货单位索引
						if(this.receiveUnitArr.length > 0){
							const receiveIndex = this.receiveUnitArr.findIndex(item => item.PARTNER === this.defaultReceiveUnit.receiveUnitCode)
							this.receiveUnitIndex = receiveIndex >= 0 ? receiveIndex : 0
						}
					}
				}else if(newName - 0 === 0){
					// 初始加载时选择"否"，只清空分流字段
					this.orderItem.shuntReceiveUnitName = ''
					this.orderItem.shuntReceiveUnitCode = ''
					this.orderItem.shuntChannelsType = ''
					this.orderItem.shuntDealer = ''
					this.orderItem.shuntDealerName = ''
					this.orderItem.shuntTypeName = ''
					this.shuntTypeIndex = 0
				}else if(newName - 0 !== 0){
					// 从"否"切换到"是"时，确保分流渠道索引有默认值（H5平台兼容性）
					if(this.shuntTypeArr.length > 0 && (this.shuntTypeIndex === undefined || this.shuntTypeIndex === null)){
						this.shuntTypeIndex = 0
					}
					//this.getShuntAnyByDealer()
				}
			}
		},
		computed: {
			isTerminalType() {
			  return this.orderItem.demandType == 'ZDZG'
			},
			// 是否为V032客户类型且为普通要货申请
			isV032NormalApply() {
				console.log('zzfld000016:',this.customerDetails?.info?.zzfld000016);
				// 优先从 store 中获取客户类型，其次从 orderItem 中获取
				const customerType = this.customerDetails?.info?.zzfld000016 || this.orderItem.customerType || this.orderItem.zzfld000016
				return customerType === 'V032' && !this.isTerminalType
			},
			imageStyles() {
				return {
					width: 64,
					height: 64,
					border: {
						radius: '50%'
					}
				}
			},
			navHeight() {
				return {
					'height': `${this.sysinfo.safeArea.top + 44}px`
				}
			},
			imageStyles() {
				return {
					width: 64,
					height: 64,
					border: {
						radius: '50%'
					}
				}
			},
			...mapState(['sysinfo', 'userInfo', 'customerDetails'])
		},
		// onLoad(option) {
		// 	this.orderItem = {
		// 		...this.orderItem,
		// 		...JSON.parse(option.order)
		// 	}
		// },
		// onBackPress(event) {
		// 	uni.switchTab({
		// 		url: `/pages/purchase-main/purchase-main?order=${JSON.stringify(this.orderItem)}`
		// 	})
		// 	return false
		// },
		mounted() {
			console.log('监听到事件来自 update');
			let _this = this
			uni.$on('selectShuntAccountInfo', function(data) {
				console.log('监听到事件来自 selectShuntAccountInfo ，携带参数 msg 为：', data);
				_this.orderItem.shuntDealerName = data.selectShuntAccountInfo.shuntingCustomer
				_this.orderItem.shuntDealer = data.selectShuntAccountInfo.shuntingCustomer
				// 渠道
				_this.orderItem.shuntChannelsType =  data.selectShuntAccountInfo.channels
				_this.orderItem.shuntTypeName =  data.selectShuntAccountInfo.channelsTextView
				// 同步更新分流渠道索引
				if(_this.shuntTypeArr.length > 0 && _this.orderItem.shuntTypeName){
					const shuntTypeIndex = _this.shuntTypeArr.findIndex(item => item.name === _this.orderItem.shuntTypeName)
					if(shuntTypeIndex >= 0){
						_this.shuntTypeIndex = shuntTypeIndex
					}
				}
			})
			uni.$on('selectAllShuntCode', function(data) {
				console.log('监听到事件来自 selectAllShuntCode：', data);
				_this.orderItem.shuntDealerName = data.selectAllShuntCode.name_org1
				_this.orderItem.shuntDealer = data.selectAllShuntCode.partner
			})
			uni.$on('selectShuntAdressAccountInfo', function(data) {
				console.log('监听到事件来自 selectShuntAdressAccountInfo ，携带参数 msg 为：', data);
				// 分流收货单位选择（type=1）
				_this.orderItem.shuntReceiveUnitName = data.selectShuntAdressAccountInfo.PARTNER_NAME
				_this.orderItem.shuntReceiveUnitCode = data.selectShuntAdressAccountInfo.PARTNER
				_this.orderItem.receiveCityCode = data.selectShuntAdressAccountInfo.CITY_CODE
				_this.orderItem.receiveCityName = data.selectShuntAdressAccountInfo.CITY_NAME
				_this.orderItem.receiveAddress = data.selectShuntAdressAccountInfo.STREET
				_this.orderItem.contactNumber = data.selectShuntAdressAccountInfo.TEL_NUMBER
				_this.orderItem.contacPerson = data.selectShuntAdressAccountInfo.C_O_NAME
				_this.orderItem.spurtCodeUnitName = data.selectShuntAdressAccountInfo.PARTNER_NAME
				_this.getReceipt(_this.orderItem.shuntDealer, true)
			})
			uni.$on('selectReceiveUnitInfo', function(data) {
				console.log('监听到事件来自 selectReceiveUnitInfo ，携带参数 msg 为：', data);
				// 普通收货单位选择（type=2）
				_this.orderItem.receiveUnitName = data.selectReceiveUnitInfo.PARTNER_NAME
				_this.orderItem.receiveUnitCode = data.selectReceiveUnitInfo.PARTNER
				_this.orderItem.contactNumber = data.selectReceiveUnitInfo.TEL_NUMBER
				_this.orderItem.contacPerson = data.selectReceiveUnitInfo.C_O_NAME
				_this.orderItem.receiveAddress = data.selectReceiveUnitInfo.STREET
				_this.orderItem.spurtCodeUnitName = data.selectReceiveUnitInfo.PARTNER_NAME
				
				// V032普通要货申请，保存省市区信息（如果收货单位数据中包含）
				if (_this.isV032NormalApply && data.selectReceiveUnitInfo) {
					const unitData = data.selectReceiveUnitInfo
					// 如果收货单位数据中包含省市区信息，保存它们
					if (unitData.REGION || unitData.REGION_TEXT) {
						_this.orderItem.province = unitData.REGION_TEXT || ''
						_this.orderItem.provinceId = unitData.REGION || ''
					}
					if (unitData.CITY_CODE || unitData.CITY_NAME || unitData.CITY_TEXT) {
						_this.orderItem.city = unitData.CITY_TEXT || unitData.CITY_NAME || ''
						_this.orderItem.cityId = unitData.CITY_CODE || ''
						_this.orderItem.cityCode = unitData.CITY_CODE || ''
					}
					if (unitData.STREET_CODE || unitData.STREET_TEXT) {
						_this.orderItem.district = unitData.STREET_TEXT || ''
						_this.orderItem.districtId = unitData.STREET_CODE || ''
						_this.orderItem.streetcode = unitData.STREET_CODE || ''
					}
					if (unitData.REGION) {
						_this.orderItem.region = unitData.REGION
					}
				}
				
				// 更新收货单位索引
				if(_this.receiveUnitArr.length > 0){
					const receiveIndex = _this.receiveUnitArr.findIndex(item => item.PARTNER === data.selectReceiveUnitInfo.PARTNER)
					_this.receiveUnitIndex = receiveIndex >= 0 ? receiveIndex : 0
				}
			})
			uni.$on('selectShuntCode', function(data) {
				console.log('监听到事件来自 selectShuntCode ，携带参数 msg 为：', data);
				_this.orderItem.spurtCodeUnit = data.selectShuntCode.info.partner
				_this.orderItem.spurtCodeUnitName = data.selectShuntCode.info.name_org1
			})
			uni.$on('selectTerminalAddress', function(data) {
				console.log('监听到事件来自 selectTerminalAddress ，携带参数 msg 为：', data);
				_this.terminalAdd = { ...data.selectTerminalAddress }
				_this.orderItem.receiveAddress = _this.terminalAdd.REGION_TEXT + _this.terminalAdd.CITY_TEXT + _this.terminalAdd.STREET_TEXT + _this.terminalAdd.STREET
			})
			uni.$on('selectCommonAddress', function(data) {
				console.log('监听到事件来自 selectCommonAddress ，携带参数 msg 为：', data);
				// V032普通要货申请修改收货地址
				if (data && data.selectCommonAddress) {
					const addrData = data.selectCommonAddress
					_this.commonAddressData = { ...addrData }
					_this.orderItem.receiveAddress = (addrData.REGION_TEXT || '') + (addrData.CITY_TEXT || '') + (addrData.STREET_TEXT || '') + (addrData.STREET || '')
					// 保存省市区名称和编码，用于行业团购时传递到后端
					_this.$set(_this.orderItem, 'province', addrData.REGION_TEXT || '')
					_this.$set(_this.orderItem, 'city', addrData.CITY_TEXT || '')
					_this.$set(_this.orderItem, 'district', addrData.STREET_TEXT || '')
					_this.$set(_this.orderItem, 'provinceId', addrData.REGION || '')
					_this.$set(_this.orderItem, 'cityId', addrData.CITY_CODE || '')
					_this.$set(_this.orderItem, 'districtId', addrData.STREET_CODE || '')
					// 同时保存 region、cityCode、streetcode 字段（用于兼容）
					_this.$set(_this.orderItem, 'region', addrData.REGION || '')
					_this.$set(_this.orderItem, 'cityCode', addrData.CITY_CODE || '')
					_this.$set(_this.orderItem, 'streetcode', addrData.STREET_CODE || '')
					// 允许修改联系人和手机号
					if (addrData.CONTACT_PERSON) {
						_this.$set(_this.orderItem, 'contacPerson', addrData.CONTACT_PERSON)
					}
					if (addrData.CONTACT_NUMBER) {
						_this.$set(_this.orderItem, 'contactNumber', addrData.CONTACT_NUMBER)
					}
					
					// 调试日志
					console.log('保存省市区信息到 orderItem:', {
						province: _this.orderItem.province,
						city: _this.orderItem.city,
						district: _this.orderItem.district,
						provinceId: _this.orderItem.provinceId,
						cityId: _this.orderItem.cityId,
						districtId: _this.orderItem.districtId,
						region: _this.orderItem.region,
						cityCode: _this.orderItem.cityCode,
						streetcode: _this.orderItem.streetcode
					})
					console.log('commonAddressData:', _this.commonAddressData)
				} else {
					console.error('selectCommonAddress 事件数据格式错误:', data)
				}
			})
			if(this.sourceType === 'myPurchase'){
				this.getFiles(this.orderItem.id)
			}
			// if(this.isTerminalType){
			// 	this.changeTerminal()
			// }
			// 初始化索引值（延迟执行，确保数据已加载）
			this.$nextTick(() => {
				setTimeout(() => {
					this.initPickerIndexes()
				}, 300)
			})
		},
			onUnload() {
				uni.$off('selectShuntAccountInfo')
				uni.$off('selectShuntAdressAccountInfo')
				uni.$off('selectReceiveUnitInfo')
				uni.$off('selectShuntCode')
				uni.$off('selectAllShuntCode')
				uni.$off('selectTerminalAddress')
				uni.$off('selectCommonAddress')
			},
			beforeDestroy() {
				uni.$off('selectShuntAccountInfo')
				uni.$off('selectShuntAdressAccountInfo')
				uni.$off('selectReceiveUnitInfo')
				uni.$off('selectShuntCode')
				uni.$off('selectAllShuntCode')
				uni.$off('selectTerminalAddress')
				uni.$off('selectCommonAddress')
			},
		created() {
			// 是否分流：B0099
			// 分流渠道：A0054
			this.getSelectDictDataOrigin('B0099')
			this.getSelectDictDataOrigin('A0054')
			this.getReceipt()
			// this.queryData()
		},
		methods: {
			// 初始化picker的索引值
			initPickerIndexes() {
				// 初始化是否分流的索引
				if(this.shuntArr.length > 0 && this.orderItem.isShunt){
					const shuntIndex = this.shuntArr.findIndex(item => item.value === this.orderItem.isShunt)
					if(shuntIndex >= 0){
						this.shuntIndex = shuntIndex
					}
				}
				// 初始化分流渠道的索引
				if(this.shuntTypeArr.length > 0){
					if(this.orderItem.shuntTypeName){
						const shuntTypeIndex = this.shuntTypeArr.findIndex(item => item.name === this.orderItem.shuntTypeName)
						if(shuntTypeIndex >= 0){
							this.shuntTypeIndex = shuntTypeIndex
						}else{
							// 如果找不到匹配项，设置为0（H5平台兼容性）
							this.shuntTypeIndex = 0
						}
					}else{
						// 如果没有选中值，确保索引有默认值（H5平台兼容性）
						this.shuntTypeIndex = 0
					}
				}
				// 初始化收货单位的索引
				if(this.receiveUnitArr.length > 0 && this.orderItem.receiveUnitCode){
					const receiveIndex = this.receiveUnitArr.findIndex(item => item.PARTNER === this.orderItem.receiveUnitCode)
					if(receiveIndex >= 0){
						this.receiveUnitIndex = receiveIndex
					}
				}
			},
			// 请求历史收货地址
			async changeTerminal(){
			  await findFirstByTerminalId({terminalId: this.orderItem.terminalId}).then(res => {
				this.orderItem.receiveAddress = res.data.receiveAddress
				this.orderItem.contactNumber = res.data.contactNumber
				this.orderItem.contacPerson = res.data.contacPerson
				this.orderItem.province = res.data.province
				this.orderItem.city = res.data.city
				this.orderItem.district = res.data.district
			  })
			},
			async getShuntAnyByDealer(){
				const res = await findShuntAnyByDealer({customerCode: this.userInfo.code})
				this.isRadio = res.data - 0 === 1
			},
			async getFiles(id) {
				const params = {
					bizId: id,
					bizCode: 'wantGoods'
				}
				const res= await doQuery(params)
				res.data.forEach((ele,idx) => {
					this.downFiles(ele)
				});
			},
			async downFiles(item) {
				console.log(item,'item')
				// 获取arraybuffer格式数据
				let res = await uni.request({
					method: "POST",
					url: `https://crm.wuliangye.com.cn/crm-app/attachmentDownFile?id=`+item.id, // 生产
					// url: `http://221.10.127.60:5000/crm-app/attachmentDownFile?id=`+item.id,
					params: {
					  id: item.id
					},
					header: {
						'X-Auth-Token': store.state.vuex_token,
						// 'content-type': 'multipart/form-data'
					},
					responseType: "arraybuffer"   //只有text、arraybuffer两种
				})
				 const buff = res[1].data
				// 转成base64格式路径
				const base64Src = 'data:image/png;base64,' + uni.arrayBufferToBase64(buff);
				// 通过 image-tools  中方法再将base64路径转为普通路径，用于预览
				const path = await  base64ToPath(base64Src);
				const picObj = {
					...item,
					"name": item.fileName,
					"extname": item.fileKind,
					"url":path,
				}
				this.allFilesPath.push(picObj)
			},
			fnCheckOrderByNo() {
				this.$refs.popup.close()
				uni.redirectTo({
					url: '/pages/my-purchase/my-purchase'
				})
			},
			fnBackHome() {
				this.$refs.popup.close()
				setTimeout(() => {
					uni.switchTab({
						url: `/pages/home/home`
					})
				}, 300)
			},
			handleCustomer() {
				uni.navigateTo({
					url: `/pages/select-customer/select-customer?order=${JSON.stringify(this.orderItem)}`
				})
			},
			handleShunt() {
				// 参考PC端逻辑：根据isRadio判断跳转到哪个页面
				if(this.isRadio){
					// 有任意分流权限，跳转到全部经销商选择页面
					uni.navigateTo({
						url: `/pages/select-shunt-all/select-shunt-all?order=${JSON.stringify(this.orderItem)}`
					})
				}else{
					// 普通分流权限，跳转到分流经销商选择页面
					uni.navigateTo({
						url: `/pages/select-shunt-list/select-shunt-list?order=${JSON.stringify(this.orderItem)}`
					})
				}
			},
			handleAdd() {
				if (this.isV032NormalApply) {
					// V032普通要货申请，跳转到普通地址选择页面（不传ZDZG参数）
					uni.navigateTo({
						url: `/pages/select-address/select-address?isCommon=true&order=${JSON.stringify(this.orderItem)}`
					})
				} else {
					// 终端直配，跳转到终端地址选择页面
					uni.navigateTo({
						url: `/pages/select-address/select-address`
					})
				}
			},
			handleReceiveUnit() {
				// 跳转到收货单位选择页面（复用select-shunt-adress页面，type=2表示普通收货单位）
				uni.navigateTo({
					url: `/pages/select-shunt-adress/select-shunt-adress?order=${JSON.stringify(this.orderItem)}&type=2`
				})
			},
			handleReceiptAddress() {
				uni.navigateTo({
					url: `/pages/select-shunt-adress/select-shunt-adress?order=${JSON.stringify(this.orderItem)}&type=2`
				})
			},
			handleShuntAddress() {
				if(this.orderItem.shuntDealerName){
					uni.navigateTo({
						url: `/pages/select-shunt-adress/select-shunt-adress?order=${JSON.stringify(this.orderItem)}&type=1`
					})
				}else{
					uni.showToast({
						title: '请先选择分流经销商！',
						duration: 2000,
						icon: 'none'
					});
				}
			},
			// 查询
			async queryData() {
				const params = {
					'customerCode': this.orderItem.customerCode,
					'type': '2',
				}
				const { data } = await findByCustomer(params)
			},
			async getReceipt(partner = this.orderItem.customerCode, flag=false){
				const params = {
					partner,
					'role': "WLY001"
				}
				const res = await getReceipt(params)
				this.receiveUnitArr = res.DATA
				if(flag)return
				if(this.orderItem.saveTimes - 0 >= 0){
					// 如果已有选中的收货单位，找到对应的索引
					if(this.orderItem.receiveUnitCode && this.receiveUnitArr.length > 0){
						const receiveIndex = this.receiveUnitArr.findIndex(item => item.PARTNER === this.orderItem.receiveUnitCode)
						this.receiveUnitIndex = receiveIndex >= 0 ? receiveIndex : 0
					}
					// 保存当前值作为默认值（用于从"是"切换回"否"时恢复）
					if(!this.defaultReceiveUnit.receiveUnitCode && this.orderItem.receiveUnitCode){
						this.defaultReceiveUnit = {
							receiveUnitCode: this.orderItem.receiveUnitCode || '',
							receiveUnitName: this.orderItem.receiveUnitName || '',
							spurtCodeUnitName: this.orderItem.spurtCodeUnitName || '',
							contactNumber: this.orderItem.contactNumber || '',
							contacPerson: this.orderItem.contacPerson || '',
							receiveAddress: this.orderItem.receiveAddress || ''
						}
					}
					return
				}
				this.orderItem.receiveUnitCode =  this.receiveUnitArr[0].PARTNER
				this.orderItem.spurtCodeUnitName =  this.receiveUnitArr[0].PARTNER_NAME
				this.receiveUnitIndex = 0
				if(this.isTerminalType){
					// this.orderItem.contactNumber = ''
					// this.orderItem.contacPerson = ''
					// this.orderItem.receiveAddress = ''
					// 保存默认值（终端类型时部分字段为空）
					this.defaultReceiveUnit = {
						receiveUnitCode: this.receiveUnitArr[0].PARTNER,
						receiveUnitName: this.receiveUnitArr[0].PARTNER_NAME || '',
						spurtCodeUnitName: this.receiveUnitArr[0].PARTNER_NAME,
						contactNumber: '',
						contacPerson: '',
						receiveAddress: ''
					}
				}else{
					this.orderItem.contactNumber = this.receiveUnitArr[0].TEL_NUMBER
					this.orderItem.contacPerson = this.receiveUnitArr[0].C_O_NAME
					this.orderItem.receiveAddress = this.receiveUnitArr[0].STREET
					this.orderItem.receiveUnitName =  this.receiveUnitArr[0].PARTNER_NAME
					
					// V032普通要货申请，保存省市区信息（如果收货单位数据中包含）
					if (this.isV032NormalApply && this.receiveUnitArr[0]) {
						const unitData = this.receiveUnitArr[0]
						if (unitData.REGION || unitData.REGION_TEXT) {
							this.orderItem.province = unitData.REGION_TEXT || ''
							this.orderItem.provinceId = unitData.REGION || ''
							this.orderItem.region = unitData.REGION || ''
						}
						if (unitData.CITY_CODE || unitData.CITY_NAME || unitData.CITY_TEXT) {
							this.orderItem.city = unitData.CITY_TEXT || unitData.CITY_NAME || ''
							this.orderItem.cityId = unitData.CITY_CODE || ''
							this.orderItem.cityCode = unitData.CITY_CODE || ''
						}
						if (unitData.STREET_CODE || unitData.STREET_TEXT) {
							this.orderItem.district = unitData.STREET_TEXT || ''
							this.orderItem.districtId = unitData.STREET_CODE || ''
							this.orderItem.streetcode = unitData.STREET_CODE || ''
						}
					}
					
					// 保存默认值
					this.defaultReceiveUnit = {
						receiveUnitCode: this.receiveUnitArr[0].PARTNER,
						receiveUnitName: this.receiveUnitArr[0].PARTNER_NAME,
						spurtCodeUnitName: this.receiveUnitArr[0].PARTNER_NAME,
						contactNumber: this.receiveUnitArr[0].TEL_NUMBER,
						contacPerson: this.receiveUnitArr[0].C_O_NAME,
						receiveAddress: this.receiveUnitArr[0].STREET
					}
				}
			},
			getSelectDictDataOrigin(dictcode) {
			  querySysDictionaryDetailsByCode({'code': dictcode})
				.then(res => {
					if(res.data.Rows.length > 0){
						switch (dictcode){
							case 'B0099':
								this.shuntArr = res.data.Rows
								if(this.orderItem.saveTimes - 0 >= 0 && this.orderItem.isShunt - 1 === 0){
									this.orderItem.shuntName =  '是'
									// 根据当前值找到对应的索引
									const shuntIndex = this.shuntArr.findIndex(item => item.value === this.orderItem.isShunt)
									this.shuntIndex = shuntIndex >= 0 ? shuntIndex : 1
									return
								}
								this.orderItem.isShunt =  this.shuntArr[1].value
								this.orderItem.shuntName =  this.shuntArr[1].name
								this.shuntIndex = 1
								break;
							case 'A0054':
								this.shuntTypeArr = res.data.Rows
								// 如果已有选中的分流渠道，找到对应的索引
								if(this.orderItem.shuntTypeName && this.shuntTypeArr.length > 0){
									const shuntTypeIndex = this.shuntTypeArr.findIndex(item => item.name === this.orderItem.shuntTypeName)
									this.shuntTypeIndex = shuntTypeIndex >= 0 ? shuntTypeIndex : 0
								}else if(this.shuntTypeArr.length > 0){
									// H5平台：如果没有选中值但数组有数据，确保索引不为undefined
									// 避免H5端picker无法选择的问题
									this.shuntTypeIndex = 0
								}
								// 使用$nextTick确保DOM更新后再设置索引（H5平台兼容性）
								this.$nextTick(() => {
									if(this.shuntTypeArr.length > 0 && this.shuntTypeIndex === undefined){
										this.shuntTypeIndex = 0
									}
								})
								break;
							default:
								break;
						  }
					}
				  
				})
				.catch(() => {})
			},
			async bindPickerChange(e,type) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				const index = e.detail.value || 0
				switch (type) {
					case 'shunt':
						this.shuntIndex = index
						this.orderItem.isShunt =  this.shuntArr[index].value
						this.orderItem.shuntName =  this.shuntArr[index].name
						// 参考PC端逻辑：当选择"是"时，查询分流权限
						if(this.orderItem.isShunt === '1'){
							await this.getShuntAnyByDealer()
						}
						break;
					case 'shuntType':
						this.shuntTypeIndex = index
						this.orderItem.shuntChannelsType =  this.shuntTypeArr[index].value
						this.orderItem.shuntTypeName =  this.shuntTypeArr[index].name
						break;
					case 'receive':
						this.receiveUnitIndex = index
						this.orderItem.receiveUnitName =  this.receiveUnitArr[index].PARTNER_NAME
						this.orderItem.receiveUnitCode =  this.receiveUnitArr[index].PARTNER
						this.orderItem.contactNumber = this.receiveUnitArr[index].TEL_NUMBER
						this.orderItem.receiveAddress = this.receiveUnitArr[index].STREET
						this.orderItem.contacPerson = this.receiveUnitArr[index].C_O_NAME
						
						// V032普通要货申请，保存省市区信息（如果收货单位数据中包含）
						if (this.isV032NormalApply && this.receiveUnitArr[index]) {
							const unitData = this.receiveUnitArr[index]
							if (unitData.REGION || unitData.REGION_TEXT) {
								this.orderItem.province = unitData.REGION_TEXT || ''
								this.orderItem.provinceId = unitData.REGION || ''
								this.orderItem.region = unitData.REGION || ''
							}
							if (unitData.CITY_CODE || unitData.CITY_NAME || unitData.CITY_TEXT) {
								this.orderItem.city = unitData.CITY_TEXT || unitData.CITY_NAME || ''
								this.orderItem.cityId = unitData.CITY_CODE || ''
								this.orderItem.cityCode = unitData.CITY_CODE || ''
							}
							if (unitData.STREET_CODE || unitData.STREET_TEXT) {
								this.orderItem.district = unitData.STREET_TEXT || ''
								this.orderItem.districtId = unitData.STREET_CODE || ''
								this.orderItem.streetcode = unitData.STREET_CODE || ''
							}
						}
						
				}
			},
			submit() {
				this.$emit('submit')
			},
			// 获取上传进度
			progress(e) {
				console.log('上传进度：', e)
			},
			async select(data) {
				data.tempFilePaths.forEach((item,idx) => {
					console.log('idx',data.tempFilePaths[idx],data.tempFiles[idx].file.name)
					uni.uploadFile({
						url: `https://crm.wuliangye.com.cn/crm-app/webUpload/ajaxUpload`, //生产
						// url: `http://221.10.127.60:5000/crm-app/webUpload/ajaxUpload`,
						filePath: data.tempFilePaths[idx],
						name: 'file',
						formData: {
							bizId: this.orderItem.fileBizId,
							bizCode: 'wantGoods',
							formSecretLevel: 0,
							name: data.tempFiles[idx].file.name,
							type: data.tempFiles[idx].file.fileType,
							lastModifiedDate: data.tempFiles[idx].file.lastModifiedDate,
							size: data.tempFiles[idx].file.size,
							// file: data.tempFiles[idx].file
						},
						header: {
							// 'Access-Control-Allow-Origin': 'http://221.10.127.60',
							'Access-Control-Allow-Origin': '*',
							'method': "POST",
							'X-Auth-Token': store.state.vuex_token,
							// 'content-type': 'multipart/form-data'
							
						},
						success: (uploadFileRes) => {
							this.allFiles.push(JSON.parse(uploadFileRes.data).data)
							console.log(this.allFiles, '成功');
							uni.showToast({
								title: '上传成功！',
								duration: 2000,
								icon: 'none'
							})
						},
						fail: (uploadFileRes) => {
							uni.showToast({
								title: '上传失败！',
								duration: 2000,
								icon: 'none'
							})
						},
					})
				})
			},
			// 上传成功
			success(e) {
				console.log('上传成功', e)
			},
			// 上传失败
			fail(e) {
				console.log('上传失败：', e)
			},
			async deletes(e){
				const params = {
					id: e.tempFile.id,
					isCheck: false
				}
				const res = await doDeleteFile(params)
				if(res.status - 0 === 1){
					const arr = this.allFiles.filter(item => item.fileName === e.tempFile.name || item.fileName === e.tempFile.fileName )
					this.allFiles = [...arr]
					console.log(this.allFiles)
				}
			},
			preStep() {
				// uni.switchTab({
				// 	url: '/pages/purchase-main/purchase-main'
				// })
				// 返回上一级 把刚刚上传的附件删除
				if(this.allFiles.length > 0){
					this.allFiles.forEach(ele => {
						const params = {
							id: ele.id,
							isCheck: false
						}
						const res = doDeleteFile(params)
						this.allFiles = []
					});
				}
				this.$emit('click', 'purchaseMain')
			},
			async preSave(){
				const that = this
				try{
					if(this.flag){
						return
					}
					// 验证分流相关字段（如果选择了"是"）
					if(this.orderItem.isShunt - 1 === 0){
						if (!this.orderItem.shuntDealerName) {
							uni.showToast({
								title: '请先选择分流经销商',
								duration: 2000,
								icon: 'none'
							});
							return
						}
						if (!this.orderItem.shuntTypeName) {
							uni.showToast({
								title: '请先选择分流渠道',
								duration: 2000,
								icon: 'none'
							});
							return
						}
					}
					this.flag = true
					for(let k in this.orderItem){
						this.orderItem[k] = this.orderItem[k] === null ? '' : this.orderItem[k]
					}
					const obj = {
						...this.orderItem
					}
					if(this.isTerminalType){
						// obj.province = this.terminalAdd.REGION_TEXT || this.orderItem.province
						// obj.city = this.terminalAdd.CITY_TEXT || this.orderItem.city
						// obj.district = this.terminalAdd.STREET_TEXT || this.orderItem.district
					}else{
						obj.demandType = 'none'
						// V032普通要货申请且渠道类型为H（行业团购），传递省市区信息
						if (this.isV032NormalApply && this.orderItem.channelsType === 'H') {
							// 优先使用 orderItem 中的值，如果没有则从 commonAddressData 中获取
							obj.province = this.orderItem.province || this.commonAddressData.REGION_TEXT || ''
							obj.city = this.orderItem.city || this.commonAddressData.CITY_TEXT || ''
							obj.district = this.orderItem.district || this.commonAddressData.STREET_TEXT || ''
							obj.provinceId = this.orderItem.provinceId || this.orderItem.region || this.commonAddressData.REGION || ''
							obj.cityId = this.orderItem.cityId || this.orderItem.cityCode || this.commonAddressData.CITY_CODE || ''
							obj.districtId = this.orderItem.districtId || this.orderItem.streetcode || this.commonAddressData.STREET_CODE || ''
							
							// 调试日志
							console.log('preSave - 省市区信息:', {
								orderItem: {
									province: this.orderItem.province,
									city: this.orderItem.city,
									district: this.orderItem.district,
									provinceId: this.orderItem.provinceId,
									cityId: this.orderItem.cityId,
									districtId: this.orderItem.districtId
								},
								commonAddressData: this.commonAddressData,
								obj: {
									province: obj.province,
									city: obj.city,
									district: obj.district,
									provinceId: obj.provinceId,
									cityId: obj.cityId,
									districtId: obj.districtId
								}
							})
							
							// 如果仍然为空，尝试从收货地址字符串中解析（作为最后的后备方案）
							if (!obj.province && !obj.city && !obj.district && this.orderItem.receiveAddress) {
								console.warn('省市区信息为空，请检查地址选择是否正确')
							}
						}
					}
					const params = JSON.parse(JSON.stringify(obj))
					params.wantGoodsDetailList = JSON.stringify(params.wantGoodsDetailList)
					let res = null
					if(params.id){
						// params.bizId = params.id
						const paramss = {
							bizId: params.id,
							...params,
						}
						res = await saveBizData(paramss)
					}else{
						res = await startProcessInstanceByKey(params)
					}
					if (res.status == 1) {
						uni.showToast({
							title: '保存成功',
							duration: 2000,
							icon: 'none'
						});
						
						setTimeout(function() {
							that.fnCheckOrderByNo()
						}, 1000)
					}else{
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						});
						this.flag = false
					}
				}catch(e){
					this.flag = false
					//TODO handle the exception
				}
			},
			async nextStep() {
				if(this.orderItem.isShunt - 1 === 0){
					if (!this.orderItem.shuntDealerName) {
						uni.showToast({
							title: '请先选择分流经销商',
							duration: 2000,
							icon: 'none'
						});
						return
					}
					if (!this.orderItem.shuntTypeName) {
						uni.showToast({
							title: '请先选择分流渠道',
							duration: 2000,
							icon: 'none'
						});
						return
					}
					if (!this.orderItem.shuntReceiveUnitName) {
						uni.showToast({
							title: '请先选择分流收货单位',
							duration: 2000,
							icon: 'none'
						});
						return
					}
				}
				// 只有终端要货时才验证联系人和联系电话
				if(this.isTerminalType){
					if(!this.orderItem.contacPerson){
						uni.showToast({
							title: '请先选择联系人',
							duration: 2000,
							icon: 'none'
						});
						return
					}
					if(!this.orderItem.contactNumber){
						uni.showToast({
							title: '请先输入联系电话',
							duration: 2000,
							icon: 'none'
						});
						return
					}
				}
				if(!this.orderItem.receiveAddress){
					uni.showToast({
						title: '请先选择收货地址',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				if(this.flag){
					return
				}
				this.flag = true
				try {
					const obj = {
						...this.orderItem
					}
					if(this.isTerminalType){
						obj.province = this.terminalAdd.REGION_TEXT || this.orderItem.province
						obj.city = this.terminalAdd.CITY_TEXT || this.orderItem.city
						obj.district = this.terminalAdd.STREET_TEXT || this.orderItem.district
					}else{
						obj.demandType = 'none'
						// V032普通要货申请且渠道类型为H（行业团购），传递省市区信息
						if (this.isV032NormalApply && this.orderItem.channelsType === 'H') {
							// 优先使用 orderItem 中的值，如果没有则从 commonAddressData 中获取
							obj.province = this.orderItem.province || this.commonAddressData.REGION_TEXT || ''
							obj.city = this.orderItem.city || this.commonAddressData.CITY_TEXT || ''
							obj.district = this.orderItem.district || this.commonAddressData.STREET_TEXT || ''
							obj.provinceId = this.orderItem.provinceId || this.orderItem.region || this.commonAddressData.REGION || ''
							obj.cityId = this.orderItem.cityId || this.orderItem.cityCode || this.commonAddressData.CITY_CODE || ''
							obj.districtId = this.orderItem.districtId || this.orderItem.streetcode || this.commonAddressData.STREET_CODE || ''
							
							// 调试日志
							console.log('nextStep - 省市区信息:', {
								orderItem: {
									province: this.orderItem.province,
									city: this.orderItem.city,
									district: this.orderItem.district,
									provinceId: this.orderItem.provinceId,
									cityId: this.orderItem.cityId,
									districtId: this.orderItem.districtId
								},
								commonAddressData: this.commonAddressData,
								obj: {
									province: obj.province,
									city: obj.city,
									district: obj.district,
									provinceId: obj.provinceId,
									cityId: obj.cityId,
									districtId: obj.districtId
								}
							})
							
							// 如果仍然为空，尝试从收货地址字符串中解析（作为最后的后备方案）
							if (!obj.province && !obj.city && !obj.district && this.orderItem.receiveAddress) {
								console.warn('省市区信息为空，请检查地址选择是否正确')
							}
						}
					}
					const params = JSON.parse(JSON.stringify(obj))
					params.wantGoodsDetailList = JSON.stringify(params.wantGoodsDetailList)
					let flagStatus = false
					let status = 0
					let data = null
					if(params.id){
						flagStatus = true
						params.bizId = params.id
					}else{
						try{
							const res = await startProcessInstanceByKey(params)
							status = res.status
							data = res.data
						}catch(e){
							this.flag = false
						}
					}
					if (status == 1 || flagStatus) {
						try{
							// exceedMonthPlan 也需要传递省市区信息（如果是行业团购）
							const exceedParams = JSON.parse(JSON.stringify(obj))
							if (this.isV032NormalApply && exceedParams.channelsType === 'H') {
								exceedParams.province = exceedParams.province || this.orderItem.province || this.commonAddressData.REGION_TEXT || ''
								exceedParams.city = exceedParams.city || this.orderItem.city || this.commonAddressData.CITY_TEXT || ''
								exceedParams.district = exceedParams.district || this.orderItem.district || this.commonAddressData.STREET_TEXT || ''
								exceedParams.provinceId = exceedParams.provinceId || this.orderItem.provinceId || this.orderItem.region || this.commonAddressData.REGION || ''
								exceedParams.cityId = exceedParams.cityId || this.orderItem.cityId || this.orderItem.cityCode || this.commonAddressData.CITY_CODE || ''
								exceedParams.districtId = exceedParams.districtId || this.orderItem.districtId || this.orderItem.streetcode || this.commonAddressData.STREET_CODE || ''
							}
							const res = await exceedMonthPlan(exceedParams)
							this.flag = false
							const that = this
							if(res.status == 0){
								// 弹框确认
								uni.showModal({
								  title: '提示',
								  content: '当前申请量超出当月发货计划量，是否确认提交？？',
								  confirmText: '确定',
								  cancelText: '取消',
								  success: function (res) {
									if (res.confirm) {
									  console.log('用户点击确定',params,data);
									  // 执行确认操作
									  that.submit(params,data)
									  return
									} else if (res.cancel) {
									  console.log('用户点击取消');
									  // 执行取消操作
									  that.flag = false
									}
								  }
								});
								that.flag = false
								return
							}
							this.submit(params,data)
						}catch(e){
							this.flag = false
						}
					}else{
						this.flag = false
					}
				} catch (e) {
					this.flag = false
				}
			},
			async submit(params,data){
				if(!params.id){
					Object.assign(params, data.bizData)
					params.bizId = data.bizId
					params.procInstId = data.procInstId
					params.taskId = data.taskId
					// 提交
					params.wantGoodsDetailList = JSON.stringify(params.wantGoodsDetailList)
				}
				
				// V032普通要货申请且渠道类型为H（行业团购），确保传递省市区信息
				if (this.isV032NormalApply && params.channelsType === 'H') {
					// 优先使用 params 中的值，其次使用 orderItem，最后使用 commonAddressData
					params.province = params.province || this.orderItem.province || this.commonAddressData.REGION_TEXT || ''
					params.city = params.city || this.orderItem.city || this.commonAddressData.CITY_TEXT || ''
					params.district = params.district || this.orderItem.district || this.commonAddressData.STREET_TEXT || ''
					params.provinceId = params.provinceId || this.orderItem.provinceId || this.orderItem.region || this.commonAddressData.REGION || ''
					params.cityId = params.cityId || this.orderItem.cityId || this.orderItem.cityCode || this.commonAddressData.CITY_CODE || ''
					params.districtId = params.districtId || this.orderItem.districtId || this.orderItem.streetcode || this.commonAddressData.STREET_CODE || ''
					
					// 调试日志
					console.log('提交省市区信息:', {
						province: params.province,
						city: params.city,
						district: params.district,
						provinceId: params.provinceId,
						cityId: params.cityId,
						districtId: params.districtId
					})
				}
				
				for(let k in params){
					params[k] = params[k] === null ? '' : params[k]
				}
				const res = await advance(params)
				if (res.status == 1) {
					this.objectId = res.data.bizData.wantCode
					this.$refs.popup.open('center')
				}
				this.flag = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.view {
		flex-direction: column;
	}

	/* #ifndef APP-PLUS */
	page {
		width: 100%;
		min-height: 100%;
		display: flex;
		background: #fff;
	}

	.status_bar {
		height: var(--status-bar-height);
		background: #fff;
	}

	/* #endif */

	.lists {
		flex: 1;
		flex-direction: column;
		background: #f0f4f5;
		// overflow-y: scroll;
	}

	.scroll-area {
		flex: 1;
	}

	.main {
		margin: 0 16rpx;
		flex-direction: column;
		border-radius: 16rpx;
		margin-top: 16rpx;
	}

	.middle {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 32rpx 64rpx 0 48rpx;
		margin-bottom: 16rpx;
	}
	.address-view{
		flex: 1;
	}

	.text-block {
		overflow: hidden;
		// height: 96rpx;
		// margin-bottom: 14rpx;
		border-bottom: 1px solid #f4f5f6;
	}
	.text-address {
		overflow: hidden;
		border-bottom: 1px solid #f4f5f6;
	}

	.text-block-last {
		margin-bottom: 0;
		border-bottom: 0;
	}

	.middle-date {
		flex: 2;
		font-size: 28rpx;
		line-height: 96rpx;
		color: #999;
	}

	.middle-date-des {
		flex: 3;
		font-size: 28rpx;
		height: 96rpx;
		line-height: 96rpx;
		color: $text-base-color;
	}
	.middle-date-address {
		color: #333;
		font-size: 28rpx;
		flex: 3;
		padding-top: 10rpx;
		justify-content: start;
		font-size: 28rpx;
		height: 96rpx;
	}
	.middle-date-address-text {
		color: #333;
		font-size: 28rpx;
		flex: 1;
		justify-content: start;
		font-size: 28rpx;
		height: 70rpx;
		line-height: 34rpx;
		align-items: center;
	}
	.middle-date-margin-des{
		flex: 1;
		font-size: 28rpx;
		color: #333;
		margin-top: 0rpx;
		margin-bottom: 20rpx;
		width: 200%;
		text-align: left;
		justify-content: end;
	}
	.picker-year {
		position: relative;
		align-items: center;
	}

	.uni-list-cell {
		flex: 1;
		height: 100%;
		align-items: center;
	}

	.uni-list-cell-db {
		flex: 1;
		align-items: center;
	}

	.picker-block {
		flex: 1;
	}

	.uni-input {
		line-height: 96rpx;
		height: 96rpx;
		font-size: 14px;
		color: $text-base-color;
	}

	.icon-arrow {
		position: absolute;
		right: 22rpx;
		top: 40rpx;
		width: 7px;
		height: 10px;
		z-index: 10;
	}

	.remark-text {
		flex: 1;
		height: 220rpx;
		background: #f5f6f7;
		border-radius: 4px;
		padding: 12rpx 18rpx;
		margin-bottom: 40rpx;
	}

	.title-first {
		border-bottom: 0;
	}

	.title-first__text {
		font-size: 28rpx;
		color: #333333;
		font-weight: 600;
	}

	.receive-record-view {
		padding: 40rpx 48rpx;
	}

	.receive-record {
		color: #555555;
		font-size: 28rpx;
		margin-bottom: 8rpx;
		margin-top: 32rpx;
	}

	.receive-record-info {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.record-info-title {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		margin-bottom: 16rpx;
	}

	.record-info-des {
		color: #999;
		font-size: 24rpx;
	}

	.bottom-area {
		height: 140rpx;
		margin-top: 12rpx;
	}

	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 10;
		width: 750rpx;
		height: 140rpx;
		padding: 0 32rpx;
		justify-content: space-between;
		align-items: center;
		background: #fff;
	}

	.btn {
		flex: 1;
		height: 92rpx;
		background: $wly-primary-color;
		border-radius: 46rpx;
	}

	.btn-l {
		margin-right: 30rpx;
		border: 1px solid $wly-primary-color;
		background-color: #fff;

	}

	.btn-text {
		color: #fff;
		font-size: 34rpx;
	}

	.btn-text-l {
		color: $wly-primary-color;
	}
	::v-deep  .uni-popup__wrapper {
		border-radius: 20rpx;
	}
	
	.popup-content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 580rpx;
		height: 408rpx;
		background: #ffffff;
		border-radius: 24rpx;
	}
	
	.popup-content-head {
		margin-top: 56rpx;
		margin-bottom: 16rpx;
	}
	
	.popup-content-head__icon {
		width: 80rpx;
		height: 80rpx;
	}
	
	.popup-content-content {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 52rpx;
	}
	
	.popup-content-content__title {
		font-size: 32rpx;
		color: #444;
		font-weight: 500;
		margin-bottom: 8rpx;
	}
	
	.popup-content-content__title2 {
		color: #999999;
		font-size: 24rpx;
	}
	
	.popup-content-foot {}
	
	.popup-content-foot__btn {
		width: 152rpx;
		height: 60rpx;
		font-size: 22rpx;
		line-height: 60rpx;
		background: #ffedee;
		text-align: center;
		color: #ff0f00;
		font-weight: 500;
		border-radius: 32rpx;
	}
	
	.popup-content-foot__sure {
		margin-left: 40rpx;
		color: #fff;
		background: #ff1d32;
		border: 1px solid #ff1d32;
	}
	.middle-date-unit {
		flex: 2;
		font-size: 28rpx;
		color: #999;
		margin-bottom: 8rpx;
		padding-top: 30rpx;
	}
	
	.middle-date-des-unit {
		flex: 3;
		font-size: 28rpx;
		min-height: 96rpx;
		color: $text-base-color;
		padding-top: 30rpx;
		justify-content: start;
	}
	.middle-date-add {
		flex: 2;
		font-size: 28rpx;
		color: #999;
		margin-bottom: 8rpx;
		padding-top: 30rpx;
	}
	
	.middle-date-des-add {
		flex: 3;
		font-size: 28rpx;
		min-height: 124rpx;
		color: $text-base-color;
		padding-top: 30rpx;
		justify-content: start;
	}
	.summary-block {
		display: flex;
		align-items: center;
	}
	.summary {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		margin-bottom: 32rpx;
		padding: 32rpx 48rpx 140rpx;
	}
	.icon_plan {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}
	
	.upload-block {
		display: flex;
		// width: 100%;
		// align-items: center;
		// justify-content: center;
		// align-self: center;
		// width: 388rpx;
		height: 388rpx;
		// background: #f5f6f7;
		// border: 1px dashed #dedede;
		border-radius: 4px;
		margin-top: 90rpx;
		flex-direction: column;
	}
	.upload-text {
		flex: 2;
		font-size: 32rpx;
		color: #333;
		font-weight: 500;
	}
	.summary {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		margin-bottom: 32rpx;
		padding: 32rpx 48rpx 140rpx;
	}
	.edit-add{
		text-align: right;
		padding-top: 10px;
		font-size: 28rpx;
	}
</style>
