<template>
	<view class="">
		<uni-section title="基本信息" style="padding: 0 62rpx;" titleColor="5F5F5F" titleFontSize="28rpx">
			<uni-forms ref="form1" :modelValue="form" :border="true" label-width="80">
				<uni-forms-item name="cname" label="店铺名称" required>
					<uni-easyinput v-model="form.cname" class="right-align" placeholder-class="placeholder-right"
						placeholder="请输入内容" :inputBorder="false" :clearable="false" :disabled="form.enableOrNot==1">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="corpsFilesList" label="店面照片" required>
					<view style="display: flex;align-items: center;">
						<uni-file-picker :value="form.corpsFilesList.filter(item=>item.isDeleted==0)"
							return-type="array" limit="9" :imageStyles="imageStyles" :auto-upload="false"
							@select="corpsfileSelect" @delete="fileDelete" :del-icon="!(form.enableOrNot==1)"
							:disabled="form.enableOrNot==1"></uni-file-picker>
					</view>
				</uni-forms-item>
				<uni-forms-item name="businessLicense" label="营业执照">
					<view style="display: flex;align-items: center;">
						<uni-file-picker v-model="form.businessLicense" return-type="object" limit="1"
							:imageStyles="imageStyles" file-mediatype="image" @select="businessLicenseSelect"
							:del-icon="!(form.enableOrNot==1)" :disabled="form.enableOrNot==1">
						</uni-file-picker>
					</view>

				</uni-forms-item>
				<uni-forms-item name="contacts" label="联系人" required>
					<uni-easyinput v-model="form.contacts" class="right-align" placeholder-class="placeholder-right"
						placeholder="请输入内容" :inputBorder="false" :clearable="false"
						:disabled="form.enableOrNot==1"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="contactsPhone" label="电话" required>
					<uni-easyinput v-model="form.contactsPhone" class="right-align" type="number"
						placeholder-class="placeholder-right" placeholder="请输入内容" :inputBorder="false"
						:clearable="false" :disabled="form.enableOrNot==1" maxlength="11"
						@change="photoChange"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="salesmanName" label="业务员" required>
					<view style="display: flex;align-items: center;height: 36px;">
						<view @click="getSalerList();form.enableOrNot!=1?salesmanShow=true:null"
							style="width: 100%;text-align: right;"
							:style="form.salesmanName?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
							{{form.salesmanName||'请选择'}}
						</view>
						<uni-icons v-if="!form.salesmanName" type="down" size="14" color='#BCBCBC'
							@click="getSalerList();form.enableOrNot!=1?salesmanShow=true:null"></uni-icons>
					</view>
					<u-picker :show="salesmanShow" :columns="salesmanList" keyName="name" @confirm="salesmanConfirm"
						@cancel="salesmanShow=false" @close="salesmanShow=false" closeOnClickOverlay></u-picker>
				</uni-forms-item>
				<uni-forms-item name="deliveryWarehouseName" label="发货仓库" required>
					<view style="display: flex;align-items: center;height: 36px;">
						<view @click="getStorageList();form.enableOrNot!=1?deliveryWarehouseShow=true:null"
							style="width: 100%;text-align: right;"
							:style="form.deliveryWarehouseName?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
							{{form.deliveryWarehouseName||'请选择'}}
						</view>
						<uni-icons v-if="!form.deliveryWarehouseName" type="down" size="14" color='#BCBCBC'
							@click="getStorageList();form.enableOrNot!=1?deliveryWarehouseShow=true:null"></uni-icons>
					</view>
					<u-picker :show="deliveryWarehouseShow" :columns="deliveryWarehouseList" keyName="cname"
						@confirm="deliveryWarehouseConfirm" @cancel="deliveryWarehouseShow=false"
						@close="deliveryWarehouseShow=false" closeOnClickOverlay></u-picker>
				</uni-forms-item>
				<uni-forms-item name="priceSystem" label="商城价格" required>
					<view style="display: flex;align-items: center;height: 36px;">
						<view @click="form.enableOrNot!=1?priceSystemShow=true:null"
							style="width: 100%;text-align: right;"
							:style="form.priceSystem?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
							{{form.priceSystem||'请选择'}}
						</view>
						<uni-icons v-if="!form.priceSystem" type="down" size="14" color='#BCBCBC'
							@click="form.enableOrNot!=1?priceSystemShow=true:null"></uni-icons>
					</view>
					<u-picker :show="priceSystemShow" :columns="priceSystemList" keyName="dictValue"
						@confirm="priceSystemConfirm" @cancel="priceSystemShow=false" @close="priceSystemShow=false"
						closeOnClickOverlay></u-picker>
				</uni-forms-item>
				<uni-forms-item name="brandName" label="品牌">
					<view>
						<view style="display: flex;align-items: center;height: 36px;">
							<view class="slot-box" @click="brandPopup">
								<view v-for="(item,index) in sliceArray(form.brandName)" :key="index"
									class="slot-content-item">
									{{item}}
								</view>
								<view v-if="form.brandName.length > 2" class="slot-content-item">
									+{{form.brandName.length - 2}}</view>
								<view v-if="form.brandName.length == 0" style="color:#B5B4B4;font-size: 24rpx;">
									请选择
								</view>
							</view>
							<uni-icons v-if="!form.brandName.length" type="down" size="14" color='#BCBCBC'
								@click="brandPopup"></uni-icons>
						</view>
						<uni-popup ref="brand" type="bottom" @change="popupChange">
							<view class="popup-content">
								<view class="popup-content-checkbox">
									<scroll-view scroll-y="true" style="height: 600rpx;" :show-scrollbar="false">
										<uni-data-checkbox mode="tag" multiple v-model="form.brandName"
											:localdata="brandList" @change="brandChange" selectedColor='#03803B'
											:map="brandObject" />
									</scroll-view>
								</view>
								<debounce-button class="confirm-btn" @click="brandConfirm">确认</debounce-button>
							</view>
						</uni-popup>
					</view>
				</uni-forms-item>
				<uni-forms-item name="address" label="所属区域" required>
					<!-- 	<uni-data-picker v-model="form.address" :localdata="addressData" popup-title="请选择所属区域"
						:map="mapObject" :inputBorder="false" :clear-icon="false"
						:readonly="form.enableOrNot==1"></uni-data-picker> -->

					<view style="display: flex;align-items: center;height: 36px;">
						<view @click="openMap" style="width: 100%;text-align: right;"
							:style="form.address?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
							{{form.address||'请选择'}}
						</view>
						<uni-icons v-if="!form.address" type="location" size="24" color='#03803B'
							@click="openMap"></uni-icons>
					</view>
				</uni-forms-item>
				<uni-forms-item name="detailedAddress" label="详细地址" required>
					<uni-easyinput v-model="form.detailedAddress" type="textarea" autoHeight class="right-align"
						placeholder-class="placeholder-right" placeholder="请输入内容" :inputBorder="false"
						:clearable="false" :disabled="form.enableOrNot==1"></uni-easyinput>
				</uni-forms-item>
			</uni-forms>
		</uni-section>
		<uni-section title="店面分类" style="padding: 0 62rpx;margin-top: 30rpx;" titleColor="5F5F5F" titleFontSize="28rpx">
			<uni-forms ref="form2" :modelValue="form" :border="true" label-width="80">
				<uni-forms-item name="corpsTypeName" label="店面分类" required>
					<view style="display: flex;align-items: center;height: 36px;">
						<view @click="getSelectType();form.enableOrNot!=1?corpsTypeShow=true:null"
							style="width: 100%;text-align: right;"
							:style="form.corpsTypeName?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
							{{form.corpsTypeName||'请选择'}}
						</view>
						<uni-icons v-if="!form.corpsTypeName" type="down" size="14" color='#BCBCBC'
							@click="getSelectType();form.enableOrNot!=1?corpsTypeShow=true:null"></uni-icons>
					</view>

					<u-picker :show="corpsTypeShow" :columns="corpsTypeList" keyName="cname" @confirm="corpsTypeConfirm"
						@cancel="corpsTypeShow=false" @close="corpsTypeShow=false" closeOnClickOverlay></u-picker>
				</uni-forms-item>
				<uni-forms-item name="storeAttributes" label="店面属性">
					<view>
						<view style="display: flex;align-items: center;height: 36px;">
							<view @click="form.enableOrNot!=1?storeAttributesShow=true:null"
								style="width: 100%;text-align: right;"
								:style="form.storeAttributes?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
								{{form.storeAttributes||'请选择'}}
							</view>
							<uni-icons v-if="!form.storeAttributes" type="down" size="14" color='#BCBCBC'
								@click="form.enableOrNot!=1?storeAttributesShow=true:null"></uni-icons>
						</view>
						<u-picker :show="storeAttributesShow" :columns="storeAttributesList" keyName="dictValue"
							@confirm="storeAttributesConfirm" @cancel="storeAttributesShow=false"
							@close="storeAttributesShow=false" closeOnClickOverlay></u-picker>
					</view>
				</uni-forms-item>
				<uni-forms-item name="chainAttribute" label="连锁属性">
					<view>
						<view style="display: flex;align-items: center;height: 36px;">
							<view @click="form.enableOrNot!=1?chainAttributeShow=true:null"
								style="width: 100%;text-align: right;"
								:style="form.chainAttribute?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
								{{form.chainAttribute||'请选择'}}
							</view>
							<uni-icons v-if="!form.chainAttribute" type="down" size="14" color='#BCBCBC'
								@click="form.enableOrNot!=1?chainAttributeShow=true:null"></uni-icons>
						</view>
						<u-picker :show="chainAttributeShow" :columns="chainAttributeList" keyName="dictValue"
							@confirm="chainAttributeConfirm" @cancel="chainAttributeShow=false"
							@close="chainAttributeShow=false" closeOnClickOverlay></u-picker>
					</view>
				</uni-forms-item>
				<uni-forms-item name="label" label="店面标签">
					<view>
						<view style="display: flex;align-items: center;height: 36px;">
							<view class="slot-box" @click="openPopup">
								<view v-for="(item,index) in sliceArray(form.label)" :key="index"
									class="slot-content-item">
									{{item}}
								</view>
								<view v-if="form.label.length > 2" class="slot-content-item">
									+{{form.label.length - 2}}</view>
								<view v-if="form.label.length == 0" style="color:#B5B4B4;font-size: 24rpx;">
									请选择
								</view>
							</view>
							<uni-icons v-if="!form.label.length" type="down" size="14" color='#BCBCBC'
								@click="openPopup"></uni-icons>
						</view>

						<uni-popup ref="popup" type="bottom" @change="popupChange">
							<view class="popup-content">
								<view class="popup-content-checkbox">
									<scroll-view scroll-y="true" style="height: 600rpx;" :show-scrollbar="false">
										<uni-data-checkbox mode="tag" multiple v-model="form.label"
											:localdata="labelList" @change="onChange" selectedColor='#03803B'
											:map="labelObject" />
									</scroll-view>
								</view>
								<debounce-button class="confirm-btn" @click="labelConfirm">确认</debounce-button>
							</view>
						</uni-popup>
					</view>
				</uni-forms-item>
			</uni-forms>
		</uni-section>
		<uni-section title="商务政策" style="padding: 0 62rpx;margin-top: 30rpx;" titleColor="5F5F5F" titleFontSize="28rpx">
			<uni-forms ref="form3" :modelValue="form" :border="true" label-width="80">
				<uni-forms-item name="signingLevel" label="签约级别">
					<!-- <uni-data-select v-model="form.signingLevel" :localdata="signingLevelList">
					</uni-data-select> -->
					<view>
						<view style="display: flex;align-items: center;height: 36px;">
							<view @click="form.enableOrNot!=1?signingLevelShow=true:null"
								style="width: 100%;text-align: right;"
								:style="form.signingLevel?'color:#000;':'color:#B5B4B4;font-size: 24rpx;'">
								{{form.signingLevel||'请选择'}}
							</view>
							<uni-icons v-if="!form.signingLevel" type="down" size="14" color='#BCBCBC'
								@click="form.enableOrNot!=1?signingLevelShow=true:null"></uni-icons>
						</view>
						<u-picker :show="signingLevelShow" :columns="signingLevelList" keyName="dictValue"
							@confirm="signingLevelConfirm" @cancel="signingLevelShow=false"
							@close="signingLevelShow=false" closeOnClickOverlay></u-picker>
					</view>
				</uni-forms-item>
				<uni-forms-item name="signingNumber" label="签约条数">
					<uni-easyinput v-model="form.signingNumber" class="right-align"
						placeholder-class="placeholder-right" placeholder="请输入内容" :inputBorder="false"
						:clearable="false" :disabled="form.enableOrNot==1" type="number"
						@blur="intBlur('signingNumber',form.signingNumber)"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="signingPeriodEnd" label="签约期限">
					<uni-datetime-picker v-model="form.signingPeriodEnd" type="date" :clear-icon="false" :border="false"
						placeholder="请选择签约期限" :disabled="form.enableOrNot==1"></uni-datetime-picker>
				</uni-forms-item>
				<uni-forms-item name="checkStatus" label="门店状态">
					<view style="display: flex;justify-content: flex-end;align-items: center;height: 70rpx;">
						<text v-if="form.checkStatus=='录入'" style="color:#e6a23c">
							录入
						</text>
						<text v-if="form.checkStatus=='提交'" style="color:#409EFF">
							提交
						</text>
						<text v-if="form.checkStatus=='审核通过'" style="color:#67c23a">
							审核通过
						</text>
						<text v-if="form.checkStatus=='审核驳回'" style="color:#f56c6c">
							审核驳回
						</text>
					</view>
				</uni-forms-item>
			</uni-forms>
		</uni-section>
		<!--<view v-if="form.enableOrNot!=1" style="padding:30rpx 20rpx;">
			<view>
				<debounce-button bgColor="#03803B" @click="submit">保存</debounce-button>
			</view>
		</view> -->
		<view v-if="form.enableOrNot!=1" class="nav-bottom-height">
		</view>
		<view v-if="form.enableOrNot!=1&&!popupShow" class="goods-nav-bottom">
			<uni-goods-nav v-if="form.checkStatus=='录入'||form.checkStatus=='审核驳回'" :fill="true" :options="[]"
				:buttonGroup="buttonGroup" @buttonClick="buttonClick" />
			<uni-goods-nav v-if="!(form.checkStatus=='录入'||form.checkStatus=='审核驳回')" :fill="true" :options="[]"
				:buttonGroup="buttonGroup2" @buttonClick="buttonClick2" />
		</view>
	</view>
</template>

<script>
	import http from '@/http/api.js'
	import {
		clientId,
		clientSecret
	} from '@/common/setting'
	import {
		submit,
		getDetail,
		review,
		selectType,
		selectLabel,
		fileRemove,
		salerList,
		storageList,
		brandDesc
	} from '@/api/home/store.js'
	import {
		contrastObj
	} from '@/utils/contrastData.js'
	export default {
		data() {
			return {
				popupShow: false,
				buttonGroup: [{
						text: '通过',
						backgroundColor: '#18bc37',
						color: '#fff'
					},
					{
						text: '驳回',
						backgroundColor: '#e64340',
						color: '#fff'
					}
				],
				buttonGroup2: [{
					text: '保存',
					backgroundColor: '#03803B',
					color: '#fff'
				}],
				corpsTypeShow: false,
				storeAttributesShow: false,
				chainAttributeShow: false,
				signingLevelShow: false,
				salesmanShow: false,
				deliveryWarehouseShow: false,
				priceSystemShow: false,
				form: {
					corpsTypeId: null,
					corpsTypeName: null,
					storeAttributes: null,
					chainAttribute: null,
					signingLevel: null,
					dimension: null,
					longitude: null,
					address: null,
					detailedAddress: null,
					label: [],
					brandName: [],
					corpsFilesList: [],
					businessLicense: {}
				},
				oldForm: {
					corpsTypeId: null,
					corpsTypeName: null,
					storeAttributes: null,
					chainAttribute: null,
					signingLevel: null,
					dimension: null,
					longitude: null,
					address: null,
					detailedAddress: null,
					label: [],
					brandName: [],
					corpsFilesList: [],
					businessLicense: {}
				},
				imageStyles: {
					width: 46,
					height: 46
				},
				mapObject: {
					text: 'name',
					value: 'code',
					children: 'children'
				},
				labelObject: {
					text: 'label',
					value: 'label',
				},
				brandObject: {
					text: 'cname',
					value: 'cname',
				},
				addressData: [],
				labelList: [],
				corpsTypeList: [],
				storeAttributesList: [],
				chainAttributeList: [],
				signingLevelList: [],
				salesmanList: [],
				brandList: [],
				deliveryWarehouseList: [],
				priceSystemList: [],
				mapData: {},
				errData: {},
			}
		},
		onLoad(option) {
			uni.$on('commitCheck', (data) => {
				this.form.address = (data.province ? data.province : '') + (data.city ? "," + data.city :
					'') + (data.district ? "," + data.district : '')
				this.form.detailedAddress = data.name
				this.form.longitude = data.location ? data.location.split(',')[0] : null
				this.form.dimension = data.location ? data.location.split(',')[1] : null
			});
			this.getSelectType()
			this.getLabel()
			this.getSalerList()
			this.getStorageList()
			this.getDictionary()
			this.getBrandlist()
			if (option && option.id) {
				this.getDetail(option.id)
			}
		},
		onUnload() {
			uni.$off();
		},
		methods: {
			popupChange(e) {
				console.log(e)
				this.popupShow = e.show
			},
			buttonClick(e) {
				if (e.index == 0) {
					this.approval(1)
				}
				if (e.index == 1) {
					this.approval(2)
				}
			},
			buttonClick2(e) {
				if (e.index == 0) {
					this.submit()
				}
			},
			openMap() {
				if (this.form.enableOrNot != 1) {
					if (this.form.longitude && this.form.dimension) {
						uni.navigateTo({
							url: `/pages/home/store/map/index?longitude=${this.form.longitude}&latitude=${this.form.dimension}`
						});
					} else {
						uni.navigateTo({
							url: `/pages/home/store/map/index`
						});
					}
				}
			},
			photoChange(val) {
				if (val) {
					if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(val)) {
						uni.showToast({
							title: '请输入正确电话',
							icon: 'none'
						});
						return;
					}
				}
			},
			intBlur(name, value) {
				if (!this.form[name]) return
				// 使用toFixed处理小数位
				try {
					const num = parseFloat(this.form[name])
					if (!isNaN(num)) {
						this.form[name] = Math.floor(num).toFixed(0)
					}
				} catch (e) {
					console.error('格式化错误', e)
				}
			},
			openPopup() {
				if (this.form.enableOrNot != 1) {
					this.getLabel()
					this.$refs.popup.open()
				}
			},
			brandPopup() {
				if (this.form.enableOrNot != 1) {
					this.getBrandlist()
					this.$refs.brand.open()
				}
			},
			onChange(e) {
				console.log('当前选中:', e.detail.value)
			},
			brandChange(e) {
				console.log('当前选中:', e.detail)
				let ids = []
				e.detail.data.forEach(item => {
					ids.push(item.id)
				})
				this.form.brandId = ids.join(',')
			},
			labelConfirm() {
				this.$refs.popup.close()
				// 提交选中值逻辑...
			},
			brandConfirm() {
				this.$refs.brand.close()
				// 提交选中值逻辑...
			},
			clear(name) {
				if (name == 'corpsTypeName') {
					this.form.corpsTypeId = null
					this.form.corpsTypeName = null
				}
				if (name == 'salesmanName') {
					this.form.salesmanId = null
					this.form.salesmanName = null
				}
				if (name == 'deliveryWarehouseName') {
					this.form.deliveryWarehouseId = null
					this.form.deliveryWarehouseName = null
				}
			},
			salesmanConfirm(row) {
				this.form.salesmanId = row.value[0].id
				this.form.salesmanName = row.value[0].name
				this.salesmanShow = false
			},
			deliveryWarehouseConfirm(row) {
				this.form.deliveryWarehouseId = row.value[0].id
				this.form.deliveryWarehouseName = row.value[0].cname
				this.deliveryWarehouseShow = false
			},
			priceSystemConfirm(row) {
				this.form.priceSystem = row.value[0].dictValue
				this.priceSystemShow = false
			},
			corpsTypeConfirm(row) {
				this.form.corpsTypeId = row.value[0].id
				this.form.corpsTypeName = row.value[0].cname
				this.corpsTypeShow = false
			},
			storeAttributesConfirm(row) {
				this.form.storeAttributes = row.value[0].dictValue
				this.storeAttributesShow = false
			},
			chainAttributeConfirm(row) {
				this.form.chainAttribute = row.value[0].dictValue
				this.chainAttributeShow = false
			},
			signingLevelConfirm(row) {
				this.form.signingLevel = row.value[0].dictValue
				this.signingLevelShow = false
			},
			getDictionary() {
				this.$u.api.dictionary('storeAttributes').then(res => {
					this.storeAttributesList = [res.data]
				})
				this.$u.api.dictionary('chainAttribute').then(res => {
					this.chainAttributeList = [res.data]
				})
				this.$u.api.dictionary('signingLevel').then(res => {
					this.signingLevelList = [res.data]
				})
				this.$u.api.dictionary('mall_price').then(res => {
					this.priceSystemList = [res.data]
				})
			},
			sliceArray(ls) {
				if (Array.isArray(ls)) {
					return ls.slice(0, 2)
				}
				return ls
			},
			getSelectType() {
				selectType().then(res => {
					this.corpsTypeList = [res.data]
				})
			},
			getLabel() {
				selectLabel().then(res => {
					this.labelList = res.data
				})
			},
			getSalerList() {
				salerList().then(res => {
					this.salesmanList = [res.data]
				})
			},
			getStorageList() {
				storageList().then(res => {
					this.deliveryWarehouseList = [res.data]
				})
			},
			getBrandlist() {
				brandDesc().then(res => {
					this.brandList = res.data
				})
			},
			getFileExtension(filename) {
				return filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
			},
			businessLicenseSelect(files) {
				files.tempFiles.forEach(file => {
					uni.showLoading({
						title: '加载中',
						mask: true
					});
					uni.uploadFile({
						url: http.config.baseURL +
							'/blade-resource/oss/endpoint/put-file', // 仅为示例，非真实的接口地址
						filePath: file.path,
						header: {
							// 客户端认证参数
							'Authorization': 'Basic ' + Base64.encode(clientId + ':' + clientSecret),
							'Blade-Auth': 'bearer ' + uni.getStorageSync('accessToken')
						},
						name: 'file',
						success: (res) => {
							const data = JSON.parse(res.data).data
							this.form.businessLicense = {
								url: data.link,
								name: data.originalName,
								extname: this.getFileExtension(data.originalName)
							}
							this.form.businessLicenseUrl = data.link
							uni.showToast({
								title: '上传成功',
								icon: 'none'
							});
						},
						fail: (err) => {
							uni.showToast({
								title: '上传失败',
								icon: 'none'
							});
						},
						complete: () => {
							uni.hideLoading()
						}
					})
				})
			},
			fileDelete(row) {
				uni.showToast({
					title: '删除成功',
					icon: 'none'
				});
				this.form.corpsFilesList.filter(item => item.isDeleted == 0)[row.index].isDeleted = 1
			},
			corpsfileSelect(files) {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				files.tempFiles.forEach(file => {
					uni.uploadFile({
						url: http.config.baseURL +
							'/blade-resource/oss/endpoint/put-file', // 仅为示例，非真实的接口地址
						filePath: file.path,
						header: {
							// 客户端认证参数
							'Authorization': 'Basic ' + Base64.encode(clientId + ':' + clientSecret),
							'Blade-Auth': 'bearer ' + uni.getStorageSync('accessToken')
						},
						name: 'file',
						success: (res) => {
							const data = JSON.parse(res.data).data
							this.form.corpsFilesList.push({
								url: data.link,
								name: data.originalName,
								extname: this.getFileExtension(data.originalName),
								isDeleted: 0
							})
							uni.showToast({
								title: '上传成功',
								icon: 'none'
							});
						},
						fail: (err) => {
							uni.showToast({
								title: '上传失败',
								icon: 'none'
							});
						},
						complete: () => {
							uni.hideLoading()
						}
					})
				})
			},
			async submit() {
				if (!this.form.cname) {
					uni.showToast({
						title: '请输入店铺名称',
						icon: 'none'
					});
					return
				}
				if (this.form.corpsFilesList.filter(item => item.isDeleted == 0).length == 0) {
					uni.showToast({
						title: '请上传店面照片',
						icon: 'none'
					});
					return
				}

				if (!this.form.contacts) {
					uni.showToast({
						title: '请输入联系人',
						icon: 'none'
					});
					return
				}
				if (!this.form.contactsPhone) {
					uni.showToast({
						title: '请输入电话',
						icon: 'none'
					});
					return
				}
				if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.form.contactsPhone)) {
					uni.showToast({
						title: '请输入正确电话',
						icon: 'none'
					});
					return;
				}
				if (!this.form.salesmanName) {
					uni.showToast({
						title: '请选择业务员',
						icon: 'none'
					});
					return
				}
				if (!this.form.deliveryWarehouseName) {
					uni.showToast({
						title: '请选择发货仓库',
						icon: 'none'
					});
					return
				}
				if (!this.form.priceSystem) {
					uni.showToast({
						title: '请选择商城价格',
						icon: 'none'
					});
					return
				}
				if (!this.form.address) {
					uni.showToast({
						title: '请选择所属区域',
						icon: 'none'
					});
					return
				}
				if (!this.form.detailedAddress) {
					uni.showToast({
						title: '请输入详细地址',
						icon: 'none'
					});
					return
				}
				if (!this.form.corpsTypeId) {
					uni.showToast({
						title: '请选择店面分类',
						icon: 'none'
					});
					return
				}
				let obj = await this.convertData(this.$deepClone(this.form))
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				submit(obj).then(res => {
						setTimeout(() => {
							uni.showToast({
								title: '保存成功',
								icon: 'none',
							});
						}, 10);
						uni.setStorageSync('isUpdate', true)
						this.getDetail(res.data.id)
					})
					.catch(() => {
						uni.hideLoading()
					});
			},
			getDetail(id) {
				let obj = {
					id: id
				}
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				getDetail(obj).then(res => {
						if (res.data.corpsFilesList.length) {
							res.data.corpsFilesList.forEach(item => {
								item.name = item.fileName
							})
						}
						if (res.data.businessLicense) {
							res.data.businessLicense = JSON.parse(res.data.businessLicense)
						}
						res.data.label = res.data.label ? res.data.label.split(",") : []
						res.data.brandName = res.data.brandName ? res.data.brandName.split(",") : []
						this.form = res.data
						this.oldForm = res.data
					})
					.finally(() => {
						uni.hideLoading()
					});
			},
			async approval(type) {
				if (!this.form.cname) {
					uni.showToast({
						title: '请输入店铺名称',
						icon: 'none'
					});
					return
				}
				if (this.form.corpsFilesList.filter(item => item.isDeleted == 0).length == 0) {
					uni.showToast({
						title: '请上传店面照片',
						icon: 'none'
					});
					return
				}

				if (!this.form.contacts) {
					uni.showToast({
						title: '请输入联系人',
						icon: 'none'
					});
					return
				}
				if (!this.form.contactsPhone) {
					uni.showToast({
						title: '请输入电话',
						icon: 'none'
					});
					return
				}
				if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.form.contactsPhone)) {
					uni.showToast({
						title: '请输入正确电话',
						icon: 'none'
					});
					return;
				}
				if (!this.form.salesmanName) {
					uni.showToast({
						title: '请选择业务员',
						icon: 'none'
					});
					return
				}
				if (!this.form.deliveryWarehouseName) {
					uni.showToast({
						title: '请选择发货仓库',
						icon: 'none'
					});
					return
				}
				if (!this.form.priceSystem) {
					uni.showToast({
						title: '请选择商城价格',
						icon: 'none'
					});
					return
				}
				if (!this.form.address) {
					uni.showToast({
						title: '请选择所属区域',
						icon: 'none'
					});
					return
				}
				if (!this.form.detailedAddress) {
					uni.showToast({
						title: '请输入详细地址',
						icon: 'none'
					});
					return
				}
				if (!this.form.corpsTypeId) {
					uni.showToast({
						title: '请选择店面分类',
						icon: 'none'
					});
					return
				}
				let obj = await this.convertData(this.$deepClone(this.form))
				console.log(obj)
				let _this = this
				uni.showModal({
					title: '提示',
					content: type == 1 ? '是否通过审核?' : '是否驳回审核?',
					success: function(res) {
						if (res.confirm) {
							obj.type = type
							uni.showLoading({
								title: '加载中',
								mask: true
							});
							submit(obj).then(res => {
								review(obj).then(res => {
										uni.showToast({
											title: '操作成功',
											icon: 'none',
											duration: 2000
										});
										_this.getDetail(res.data.id)
									})
									.catch(() => {
										uni.hideLoading()
									});
							}).catch(() => {
								uni.hideLoading()
							})

						}
					}
				});
			},
			async convertData(obj) {
				if (obj.corpsFilesList.length) {
					obj.corpsFilesList.filter(item => item.isDeleted == 0).forEach((item, index) => {
						if (index == 0) {
							item.mainImage = 1
						}
						item.fileName = item.name
					})
				}
				if (obj.businessLicense) {
					obj.businessLicense = JSON.stringify(obj.businessLicense)
				}

				obj.label = obj.label ? obj.label.join(",") : null
				obj.brandName = obj.brandName ? obj.brandName.join(",") : null
				if (obj.signingPeriodEnd) {
					obj.signingPeriodEnd = obj.signingPeriodEnd.slice(0, 10) + ' 00:00:00'
				}
				return obj
			}

		}
	}
</script>

<style lang="scss" scoped>
	.right-align {
		text-align: right;
	}

	.photo {
		margin-left: 20rpx;
		width: 38rpx;
		height: 32rpx;
	}

	::v-deep .uni-section .uni-section-header {
		font-weight: bold !important;
		padding: 12px 0px !important;
		border-bottom: 2px solid #F6F6F6;
	}

	::v-deep .uni-file-picker__container {
		justify-content: flex-end !important;
	}

	::v-deep .uni-file-picker .file-picker__box-content {
		overflow: revert;
		z-index: 9;
	}

	::v-deep .icon-del-box {
		height: 26rpx;
		width: 26rpx;
		top: -2rpx;
		right: -8rpx;
		z-index: 999;
	}

	::v-deep .icon-del {
		width: 14rpx;
		height: 2rpx;
	}

	.slot-content-item {
		border-radius: 13rpx;
		border: 2rpx solid #03803B;
		padding: 1rpx 5rpx;
		color: #03803B;
	}

	.slot-content-item-placeholder {
		font-weight: 400 !important;
		font-size: 28rpx !important;
		height: 38rpx !important;
		color: #B5B4B4 !important;
	}

	.slot-box {
		gap: 5px;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
		width: 100%;
	}

	.popup-content {
		background: #fff;
		padding: 40rpx 20rpx;
		border-radius: 24rpx 24rpx 0 0;
	}

	.popup-content-checkbox {
		height: 600rpx;
	}

	.confirm-btn {
		margin-top: 30rpx;
		color: #ffffff;
		background: #03803B;
		width: 400rpx;
	}

	::v-deep .icon-add {
		width: 36px !important;
	}

	::v-deep .uni-date-x .uni-icons {
		color: #03803B !important;
	}
</style>