<template>
	<view class="page">
		<u-navbar title="车型编辑" :border-bottom="false" :background="bgc" title-color='#000' title-size='36'
			height='45'></u-navbar>
		<view class="biaoti" style="margin-top: 30rpx;">
			<view class=""></view> 基本信息 
		</view>
		<view class="card">
			<view class="card_li">
				<view class="card_left">
					<text style="color: #FF4444;margin-right: 2rpx;">*</text>车型名称
				</view>
				<view class="" style="text-align: right;">
					<input type="text" v-model="data.name" placeholder="请输入车型名称" class="input"
						placeholder-style="color:#C7CDD3">
				</view>
			</view>
		</view>
		<view class="card">
            <view class="card_li">
            	<view class="card_left">
            		坐垫锁开启
            	</view>
            	<view class="card_right">
            		<u-switch v-model="data.enableSeat"></u-switch>
            	</view>
            </view>
			<view class="card_li">
				<view class="card_left">
					低电量提醒
				</view>
				<view class="card_right">
					<u-switch v-model="data.lowBatteryReminderSwitch"></u-switch>
					<!-- <input type="text" v-model="data.lowBatteryReminder" placeholder="请输入提醒电量" class="input"
						placeholder-style="color:#C7CDD3">
					<span> %</span> -->
				</view>
			</view>
			<view class="card_li">
				<view class="card_left">
					智能车
				</view>
				<view class="card_right">
					<u-switch v-model="data.smart"></u-switch>
				</view>
			</view>
			<view class="card_li" v-if="data.lowBatteryReminderSwitch">
				<view class="card_left" style="width: 500rpx;">
					骑行低电量提醒（%）
				</view>
				<view class="card_right">
					<input type="text" v-model="data.lowBatteryReminder" placeholder="请输入提醒电量" class="input"
						placeholder-style="color:#C7CDD3">
					<span> %</span>
				</view>
			</view>
            
			<view class="card_li">
				<view class="card_left">
					是否自动生成换电工单
				</view>
				<view class="card_right">
					<u-switch v-model="data.powerWorkEnable"></u-switch>
				</view>
			</view>
			<view class="card_li" v-if="data.powerWorkEnable">
				<view class="card_left" style="width: 500rpx;">
					生成换电工单阈值（%）
				</view>
				<view class="card_right">
					<input type="text" v-model="data.powerWorkRate" placeholder="请输入提醒电量" class="input"
						placeholder-style="color:#C7CDD3">
					<span> %</span>
				</view>
			</view>
			
			<view class="card_li">
				<view class="card_left">
					是否校验工单完成
				</view>
				<view class="card_right">
					<u-switch v-model="data.powerWorkCheck"></u-switch>
				</view>
			</view>
			<view class="card_li" v-if="data.powerWorkCheck">
				<view class="card_left" style="width: 500rpx;">
					生成换电工单阈值（%）
				</view>
				<view class="card_right">
					<input type="text" v-model="data.powerWorkFinishRate" placeholder="请输入校验阈值" class="input"
						placeholder-style="color:#C7CDD3">
					<span> %</span>
				</view>
			</view>
		</view>
		
		
		<view class="biaoti" style="margin-top: 30rpx;">
			<view class=""></view> 续航电量 
		</view>
		<view class="card" style="padding-bottom: 30rpx;">
			<view class="card_li">
				<view class="card_left">
					满电续航
				</view>
				<view class="card_right">
					<input type="text" v-model="data.fullEndurance" placeholder="请输入续航" class="input"
						placeholder-style="color:#C7CDD3">
					<span> KM</span>
				</view>
			</view>
			<view class="cxlist" style="margin-top: 20rpx;padding-bottom: 10rpx;">
				<view class="battery_table-tip" style="margin-bottom: 20rpx;">
					点击使用官方推荐车型
				</view>
			  <view class="cxitem" style="display: flex;align-items: center;width: 100%;overflow-x: auto;overflow-y: hidden;white-space: nowrap;-webkit-overflow-scrolling: touch;padding-bottom: 10rpx;">
			    <view hover-class="app-tap-hover" v-for="(item,index) in officialModelList" :key="index" :class="cxindex == index ? 'cxactive' : ''" @click="selectOfficialModel(item,index)" style="display: inline-block;flex-shrink: 0;padding: 6rpx 20rpx;border: 1px solid #ccc;border-radius: 10rpx;margin-right: 20rpx;font-size: 28rpx;min-width: fit-content;">
			      {{item.name}}
			    </view>
			  </view>
			</view>
			<view class="battery_table">
				<view class="battery_table-head" style="width: 670rpx;height: 78rpx;background-color: #F4F5F7;line-height: 78rpx;font-size: 28rpx;color: #3D3D3D;display: flex;justify-content: space-between;padding: 0 68rpx;">
					<view class="col " style=""># 电压</view>
					<view class="col ">电量</view>
					<view class="col ">操作</view>
				</view>
				<view class="battery_table-row" v-for="(item, index) in data.voltageRange" :key="index" style="padding-right: 38rpx;">
					<view class="col index">{{ index + 1 }}</view>
					<view class="col voltage">
						<input type="digit" inputmode="decimal" v-model="item.voltage" placeholder="请输入电压" class="inline-input"
							placeholder-style="color:#C7CDD3" />
						<text class="unit">V</text>
					</view>
					<view class="col power">
						<input type="number" v-model="item.rate" placeholder="请输入电量" class="inline-input"
							:disabled="isEdgePercent(index)" @blur="limitPercent(index)"
							placeholder-style="color:#C7CDD3" />
						<text class="unit">%</text>
					</view>
					<view class="col action">
						<text hover-class="app-tap-hover" class="link" style="color: #4297F3;" v-if="index === 0" @click="addVoltageRow(index)">+ 添加</text>
						<text hover-class="app-tap-hover"
						    style="color: #4297F3;"
							class="link delete"
							v-else-if="index !== data.voltageRange.length - 1"
							:class="{ disabled: !canRemoveRow(index) }"
							@click="removeVoltageRow(index)"
						>删除</text>
					</view>
				</view>
				<view class="battery_table-tip" style="padding-left: 30rpx;">
					<text>首行电量固定为 0%，末行固定为 100%</text>
				</view>
			</view>
		</view>
		
		<view class="card">
			<view class="card_li1">
				<view hover-class="app-tap-hover" class="card_top" @click="showpart = true">
					<view class="card_left">
						收费模版
					</view>
					<view class="card_right">
						<view class="iconfont icon-xiangyou1 " style="color: #CBCBCB;">

						</view>
					</view>
				</view>
				<view v-if="data.suitIds.length == 0" class="" style="width: 184rpx;height: 50rpx;border-radius: 6rpx;background-color: #4297F3;color: #fff;text-align: center;line-height: 50rpx;">
					收费模版名称
				</view>
				<view class="taocan" v-if="data.suitIds">
					<view v-for="(name, index) in getAccessoryNames()" :key="index" style=" display: flex;margin-top: 10rpx;">
						<view class="tc_li">
							{{ name }}
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 所属运营区 -->
		<!-- <view class="card" @click="btnyunying">
			<view class="card_li1">
				<view class="card_top" style="border: none;">
					<view class="card_left">
						所属运营区
					</view>
					<view class="card_right">
						 太姥山
						<view class="iconfont icon-xiangyou1 " style="color: #CBCBCB;"></view>
					</view>
				</view>
			</view>
		</view>
		<u-mask :show="yunyingflag" :z-index='100' @click="closeOfficialModal()" />
		<view class="choose_part official_part" v-if="yunyingflag">
			<view class="tit">
				运营区
			</view>
			<scroll-view class="part_box" @scrolltolower="handqixing" scroll-y >
				<view class="official_list">
					<view class="official_item" v-for="item in yunyinglist" :key="item.id">
						<view class="info">
							<view class="name">{{ item.name.length > 8 ? item.name.slice(0,8) + '...' : item.name}}</view>
						</view>
						<view class="choose_btn" @click="selectOfficialModel(item)">选择</view>
					</view>
					<view class="empty" v-if="!officialModelList.length">
						暂无运营区
					</view>
				</view>
			</scroll-view>
			<view class="btn" @click="closeOfficialModal">
				关闭
			</view>
		</view> -->
		
		<u-mask hover-class="app-tap-hover" :show="showOfficialModal" :z-index='100' @click="closeOfficialModal()" />
		<view class="choose_part official_part" v-if="showOfficialModal">
			<view class="tit">
				官方推荐车型
			</view>
			<scroll-view class="part_box" scroll-y>
				<view class="official_list">
					<view class="official_item" v-for="item in officialModelList" :key="item.id">
						<view class="info">
							<view class="name">{{ item.name.length > 8 ? item.name.slice(0,8) + '...' : item.name}}</view>
						</view>
						<view hover-class="app-tap-hover" class="choose_btn" @click="selectOfficialModel(item)">选择</view>
					</view>
					<view class="empty" v-if="!officialModelList.length">
						暂无官方车型
					</view>
				</view>
			</scroll-view>
			<view hover-class="app-tap-hover" class="btn" @click="closeOfficialModal">
				关闭
			</view>
		</view>
		<u-mask hover-class="app-tap-hover" :show="showpart" :z-index='100' @click="closepart()" />
		<view class="choose_part" v-if="showpart">
			<view class="tit">
				选择收费方式
			</view>
			<scroll-view class="part_box" scroll-y>
				<view class="part_list">
					<view hover-class="app-tap-hover" class="part_item" v-for="(item, index) in Accessorylist" :key="index"
						@click="chooseAcc(item.id)">
						<view class="part" :class="data.suitIds.includes(item.id) ? 'act' : ''">
							{{ item.name }}
							<image src="https://lxnapi.ccttiot.com/bike/img/static/uJNlGEGmN0F4AuPJmOZn" mode=""
								v-if="data.suitIds.includes(item.id)">
							</image>
						</view>
					</view>
				</view>
			</scroll-view>
			<view hover-class="app-tap-hover" class="btn" @click="subacc()">
				确定
			</view>
		</view>
		<!-- 新增：底部图标与车辆照片字段 -->
		<view class="card" style="padding-bottom: 50rpx;">
			<view class="card_li" style="margin-top: 30rpx;">
				<view class="up_left">
					<view class="txt1">
						图标
					</view>	
					<view class="txt2">
						建议使用清晰、方正的小图标，也可点击下方快速选择图标
					</view>
				</view>
				<view hover-class="app-tap-hover" class="up_rignt" @click="chooseone">
					<image src="https://lxnapi.ccttiot.com/bike/img/static/u08cpfIllwweGcS9awYP" mode=""
						v-if="data.icon == null || data.icon == ''"></image>
					<image :src="data.icon" mode="aspectFit" v-else></image>
					<image hover-class="app-tap-hover" src="https://lxnapi.ccttiot.com/bike/img/static/uFp9riSLtpmuq6gyKfdr" mode="aspectFill" class="close"
						v-if="data.icon != ''" @click.stop="data.icon = ''"></image>
				</view>
			</view>
			<view class="" style="display: flex;align-items: center;flex-wrap: wrap;gap: 26rpx;margin-top: 20rpx;">
				<view hover-class="app-tap-hover" class="" style="width: 66rpx;height: 76rpx;" v-for="(item,index) in quickIcons" :key="index" @click="btnimg(item)">
					<image :src="item" mode="aspectFill" style="width: 66rpx;height: 76rpx;"></image>
				</view>
			</view>
			<view class="card_li" style="margin-top: 30rpx;">
				<view class="up_left">
					<view class="txt1">
						车辆照片
					</view>
					<view class="txt2">
						请上传车辆实拍照，保持清晰完整
					</view>
				</view>
				<view hover-class="app-tap-hover" class="up_rignt" @click="choosetwo"> 
					<image src="https://lxnapi.ccttiot.com/bike/img/static/u08cpfIllwweGcS9awYP" mode=""
						v-if="data.picture == null || data.picture == ''"></image>
					<image :src="data.picture" mode="aspectFit" v-else></image>
					<image hover-class="app-tap-hover" src="https://lxnapi.ccttiot.com/bike/img/static/uFp9riSLtpmuq6gyKfdr" mode="" class="close"
						v-if="data.picture != ''" @click.stop="data.picture = ''"></image>
				</view>
			</view>
			<view class="" style="display: flex;align-items: center;flex-wrap: wrap;gap: 26rpx;margin-top: 20rpx;">
				<view hover-class="app-tap-hover" class="" style="width: 110rpx;height: 110rpx;" v-for="(item,index) in cheIcons" :key="index" @click="btnimgs(item)">
					<image :src="item" mode="aspectFit" style="width: 110rpx;height: 92rpx;"></image>
				</view>
			</view>
		</view>
		<view class="btn_box">
			<view hover-class="app-tap-hover" class="btn1" @click="backpage()">
				取消
			</view>
			<view hover-class="app-tap-hover" class="btn2" @click="sub">
				保存
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			bgc: {
				backgroundColor: "#fff",
			},
			showpart: false,
			list: [],
			Accessorylist: [],
			chooseIdxArr: [], // 存储选中的索引
			data: {
				model: "",
				fullVoltage: "",
				lowVoltage: "",
				fullEndurance: "",
				suitIds: [],
				lowBatteryReminder: '20',
				lowBatteryReminderSwitch: false,
				smart: false,
				enableSeat:false,
				icon: '',
				picture: '',
				voltageRange: [
					{
						voltage: '',
						rate: 0
					},
					{
						voltage: '',
						rate: 100
					}
				]
			},
			officialModelList: [],
			showOfficialModal: false,
			token: '',
			upurl: '',
			modelId: '',
			areaId: '',
			userinfo:'',
			quickIcons: [
			        'https://api.ccttiot.com/%E7%BB%84%2014527@3x-1758175543796.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014531@3x-1758175543841.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014535@3x-1758175543842.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014533@3x-1758175543842.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014529@3x-1758175543841.png',
			        'https://api.ccttiot.com/%E7%BB%84%201095@3x-1758175543790.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014528@3x-1758175543841.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014532@3x-1758175543843.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014536@3x-1758175543842.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014534@3x-1758175543842.png',
			        'https://api.ccttiot.com/%E7%BB%84%2014530@3x-1758175543842.png',
			        'https://api.ccttiot.com/%E7%BB%84%201096@3x-1758175543796.png',
					'https://api.ccttiot.com/%E7%BB%84%201051-1773632329508.png',
					'https://api.ccttiot.com/%E7%BB%84%2014532-1773632329561.png',
					'https://api.ccttiot.com/%E7%BB%84%2014534-1773632329598.png',
					'https://api.ccttiot.com/%E7%BB%84%2014536-1773632329636.png',
					'https://api.ccttiot.com/%E7%BB%84%201095-1773632329526.png',
					'https://api.ccttiot.com/%E7%BB%84%2014531-1773632329546.png',
					'https://api.ccttiot.com/%E7%BB%84%2014533-1773632329581.png',
					'https://api.ccttiot.com/%E7%BB%84%2014535-1773632329618.png',
			],
			cheIcons: [
			        'https://api.ccttiot.com/smartmeter/img/static/uei3dDAuPNNe9E65yi6g',
					'https://api.ccttiot.com/smartmeter/img/static/uSbp86vrre2xwjZho2iX',
					'https://api.ccttiot.com/smartmeter/img/static/u1FoIt3IRUOer3uGOOTI',
					'https://api.ccttiot.com/smartmeter/img/static/ulHNoYWHpoTcnoIlzgbp',
					'https://api.ccttiot.com/smartmeter/img/static/uI2eOX98s1wyr2LHzRK3',
					'https://api.ccttiot.com/smartmeter/img/static/uHTSUlE69nyHst0ec8jV',
					'https://api.ccttiot.com/UTV%E8%B6%8A%E9%87%8E%E8%BD%A6-1773632311691.png',
					'https://api.ccttiot.com/%E5%B1%A5%E5%B8%A6%E5%9D%A6%E5%85%8B-1773632329453.png',
					'https://api.ccttiot.com/%E8%B6%8A%E9%87%8E%E6%B2%99%E6%BB%A9%E5%8D%A1%E4%B8%81%E8%BD%A6-1773632329487.png',
					'https://api.ccttiot.com/%E7%A2%B0%E7%A2%B0%E8%BD%A6-1773632329469.png',
			],
			yunyinglist:[],
			yunyingflag:false,
			yunyingtotal:0,
			yunyingpagenum:1,
			cxindex:-1
		}
	},
	onLoad(e) {
		this.getchexlist()
		if (e.modelId) {
			console.log(e);
			this.modelId = e.modelId
			this.getmodelInfo()
		}
		if (uni.getStorageSync('adminAreaid')) {
			this.areaId = uni.getStorageSync('adminAreaid')
		}
	},
	onShow() {
		this.getinfo()
		this.getQiniuToken()
	},
	methods: {
		// // 点击请求运营区
		// btnyunying(){
		// 	this.$u.get(`/bst/area/list?pageNum=${this.yunyingpagenum}&pageSize=20`).then((res) => {
		// 		if (res.code == 200) {
		// 			this.yunyingtotal = res.total
		// 			if(this.yunyingpagenum == 1){
		// 				this.yunyinglist = res.rows
		// 				this.yunyingflag = true
		// 				this.yunyingpagenum++
		// 			}else{
		// 				this.yunyinglist = this.yunyinglist.concat(res.rows) 
		// 				this.yunyingflag = true
		// 				this.yunyingpagenum++
		// 			}
		// 		}
		// 	})
		// },
		// handqixing(){
		// 	if(this.yunyinglist.length < this.yunyingtotal){
		// 		this.btnyunying()
		// 	}
		// },
		// 请求官方车型
		getchexlist(){
			this.$u.get(`/bst/modelPreset/list`).then((res) => {
				if (res.code == 200) {
					this.officialModelList = res.rows || []
				}
			})
		},
		openOfficialModal() {
			if (!this.officialModelList.length) {
				this.getchexlist()
			}
			this.showOfficialModal = true
		},
		closeOfficialModal() {
			this.showOfficialModal = false
		},
		selectOfficialModel(item,index) {
			this.cxindex = index
			this.setVoltageList(item.voltageRange || item.voltagePowerList || [])
			if (item.fullEndurance !== undefined && item.fullEndurance !== null) {
				this.$set(this.data, 'fullEndurance', item.fullEndurance)
			}
			this.closeOfficialModal()
			uni.showToast({
				title: '已应用官方车型',
				icon: 'success',
				duration: 1200
			})
		},
		createDefaultVoltageList() {
			return [
				{
					voltage: '',
					power: 0
				},
				{
					voltage: '',
					power: 100
				}
			]
		},
		setVoltageList(list) {
			const formatted = this.normalizeVoltageList(list)
			this.$set(this.data, 'voltageRange', formatted)
		},
		normalizeVoltageList(list) {
			let parsed = list
			if (typeof parsed === 'string') {
				try {
					parsed = JSON.parse(parsed)
				} catch (error) {
					parsed = []
				}
			}
			if (!Array.isArray(parsed) || !parsed.length) {
				parsed = this.createDefaultVoltageList()
			}
			const cleaned = parsed.map(item => ({
				voltage: item && item.voltage !== undefined ? item.voltage : '',
				rate: item && (item.rate !== undefined ? item.rate : item.power !== undefined ? item.power : '')
			}))
			if (cleaned.length < 2) {
				cleaned.push({
					voltage: '',
					rate: 100
				})
			}
			cleaned[0].rate = 0
			cleaned[cleaned.length - 1].rate = 100
			return cleaned
		},
		ensureEdgePower() {
			const list = this.data.voltageRange
			if (!Array.isArray(list) || !list.length) {
				this.setVoltageList([])
				return
			}
			const lastIndex = list.length - 1
			this.$set(list[0], 'rate', 0)
			this.$set(list[lastIndex], 'rate', 100)
		},
		addVoltageRow(index) {
			const insertIndex = index + 1
			this.data.voltageRange.splice(insertIndex, 0, {
				voltage: '',
				rate: ''
			})
			this.ensureEdgePower()
		},
		removeVoltageRow(index) {
			if (!this.canRemoveRow(index)) return
			this.data.voltageRange.splice(index, 1)
			this.ensureEdgePower()
		},
		isEdgePercent(index) {
			return index === 0 || index === this.data.voltageRange.length - 1
		},
		canRemoveRow(index) {
			return this.data.voltageRange.length > 2 && !this.isEdgePercent(index)
		},
		limitPercent(index) {
			if (this.isEdgePercent(index)) return
			let value = this.data.voltageRange[index].rate
			value = value === '' || value === null || value === undefined ? '' : Number(value)
			if (value === '') {
				this.$set(this.data.voltageRange[index], 'rate', '')
				return
			}
			if (isNaN(value)) value = 0
			if (value < 0) value = 0
			if (value > 100) value = 100
			this.$set(this.data.voltageRange[index], 'rate', value)
		},
		validateVoltageTable() {
			const list = this.data.voltageRange || []
			if (!list.length) {
				uni.showToast({
					title: '请至少配置两行电压电量',
					icon: 'none'
				})
				return false
			}
			for (let i = 0; i < list.length; i++) {
				const item = list[i]
				if (item.voltage === '' || item.voltage === null || item.voltage === undefined) {
					uni.showToast({
						title: `请填写第${i + 1}行电压`,
						icon: 'none'
					})
					return false
				}
				if (item.rate === '' || item.rate === null || item.rate === undefined) {
					uni.showToast({
						title: `请填写第${i + 1}行电量`,
						icon: 'none'
					})
					return false
				}
			}
			if (Number(list[0].rate) !== 0 || Number(list[list.length - 1].rate) !== 100) {
				uni.showToast({
					title: '首行电量需为0，末行为100',
					icon: 'none'
				})
				return false
			}
			return true
		},
		// 点击快捷选择图标
		btnimg(item){
			this.data.icon = item
		},
		// 点击快捷选择车辆图片
		btnimgs(item){
			this.data.picture = item
		},
		// 获取上传七牛云token
		getQiniuToken() {
			this.$u.get("/common/qiniuToken").then((res) => {
				if (res.code == 200) {
					this.token = res.data
				}
			})
		},
		chooseone() {
			let _this = this
			let math = 'static/' + _this.$u.guid(20)
			uni.chooseImage({
				count: 1,
				type: 'image',
				success(res) {
					const tempFilePaths = res.tempFiles
					uni.uploadFile({
						url: 'https://up-z2.qiniup.com',
						name: 'file',
						filePath: tempFilePaths[0].path,
						formData: {
							token: _this.token, //后端返回的token
							key: 'smartmeter/img/' + math
						},
						success: function(res) {
							console.log(res, 'resres');
							let str = JSON.parse(res.data)
							console.log(str.key)
							_this.data.icon = 'https://api.ccttiot.com/' + str.key
							console.log(_this.data.icon);
						}
					})
				}
			})
		},
		choosetwo() {
			let _this = this
			let math = 'static/' + _this.$u.guid(20)
			uni.chooseImage({
				count: 1,
				type: 'image',
				success(res) {
					const tempFilePaths = res.tempFiles
					uni.uploadFile({
						url: 'https://up-z2.qiniup.com',
						name: 'file',
						filePath: tempFilePaths[0].path,
						formData: {
							token: _this.token, //后端返回的token
							key: 'smartmeter/img/' + math
						},
						success: function(res) {
							console.log(res, 'resres');
							let str = JSON.parse(res.data)
							console.log(str.key)
							_this.data.picture = 'https://api.ccttiot.com/' + str.key
							console.log(_this.data.picture);
						} 
					})
				}
			})
		},
		
		getinfo() {
			this.$u.get("/getInfo").then((res) => {
				if (res.code == 200) {
					this.userinfo = res.user
					this.getAccessorylist()
				} 
			})
		},
		closepart() {
			this.showpart = false
		},
		getmodelInfo() {
			this.$u.get(`/bst/model/${this.modelId}`).then((res) => {
				if (res.code == 200) {
					const remoteData = res.data || {}
					this.data = Object.assign({}, this.data, remoteData)
					this.data.suitIds = remoteData.suitIds || []
					this.setVoltageList(remoteData.voltageRange || remoteData.voltagePowerList || [])
					console.log(this.data, 'this.datathis.data');
				}
			})
		},
		// 点击返回上一级
		backpage() {
			uni.navigateBack()
		},
		// 点击保存
		sub() {
			if (!this.validateVoltageTable()) {
				return
			}
			if (this.modelId) {
				const submitData = { ...this.data }
				delete submitData.userId
				this.$u.put("/bst/model", submitData).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'success',
							duration: 1000
						});
						setTimeout(() => {
							uni.navigateBack()
						}, 1200)
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 5000
						}) 
					}
				})
			} else {
				const submitData = { ...this.data }
				submitData.areaId = this.areaId
				submitData.userId = this.userinfo?.userId
				this.$u.post("/bst/model", submitData).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'success',
							duration: 1000
						});
						setTimeout(() => {
							uni.navigateBack()
						}, 1200)
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 5000
						})
					}
				})
			}
		},

		subacc() {
			this.showpart = false
			console.log(this.chooseIdxArr)
		},
		chooseAcc(id) {
			const index = this.data.suitIds.indexOf(id)
			if (index > -1) {
				// 如果 id 已经存在于 suitIds 中，则从数组中删除
				this.data.suitIds.splice(index, 1)
			} else {
				// 如果 id 不存在，则添加到 suitIds 中
				this.data.suitIds.push(id)
			}
		},
		getAccessoryNames(accessoryIds) {
			const accessoryNames = this.data.suitIds.map(id => {
				const item = this.Accessorylist.find(accessory => accessory.id === id)
				return item ? item.name : ''
			})
			// 过滤掉空值并返回数组
			return accessoryNames.filter(name => name)
		},
		getAccessorylist() {
			this.$u.get(`/bst/suit/list?pageNum=1&pageSize=999&areaId=${this.areaId}&temp=false`).then((res) => {
				if (res.code == 200) {
					this.Accessorylist = res.rows
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 5000
					})
				}
			})
		},
	}
}
</script>

<style lang="scss">
	.cxactive{
		background-color: #4297F3 !important; 
		color: #fff !important;
	}
	.biaoti{
		display: flex;
		align-items: center;
		font-size: 32rpx;
		color: #3D3D3D;
		padding-left: 20rpx;
		margin-top: 40rpx;
		view{
			width: 16rpx;
			height: 46rpx;
			background: #4297F3;
			border-radius: 0 10rpx 10rpx 0;
			margin-right: 12rpx;
		}
	}
.page {
	padding-bottom: 500rpx;
	box-sizing: border-box;
	overflow: scroll;
	.choose_part {
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		z-index: 110;
		width: 644rpx;
		padding: 40rpx 48rpx;
		background: #FFFFFF;
		border-radius: 26rpx;
		.part_box {
			margin-top: 40rpx;
			max-height: 600rpx;
			.part_list {
				display: flex;
				flex-direction: column;
				gap: 20rpx;
				.part_item {
					width: 100%;
				}
				.part {
					position: relative;
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 20rpx;
					background: #F0F0F0;
					border-radius: 12rpx;
					border: 1rpx solid #F0F0F0;
					font-size: 32rpx;
					color: #3D3D3D;
					transition: all 0.3s ease;
					image {
						position: absolute;
						right: 10rpx;
						bottom: 10rpx;
						width: 34rpx;
						height: 34rpx;
					}
					&.act {
						background: #DCEDFF;
						border: 1rpx solid #4297F3;
						color: #4297F3;
					}

					&:active {
						opacity: 0.8;
					}
				}
			}
		}
		.tit {
			width: 100%;
			text-align: center;
			font-weight: 600;
			font-size: 36rpx;
			color: #3D3D3D;
			margin-bottom: 20rpx;
		}
		.btn {
			margin-top: 40rpx;
			width: 100%;
			height: 88rpx;
			background: #4C97E7;
			border-radius: 10rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			&:active {
				opacity: 0.9;
			}
		}
	}
	.btn_box {
		position: fixed;
		width: 750rpx;
		bottom: 50rpx;
		display: flex;
		flex-wrap: nowrap;
		align-content: center;
		justify-content: center;
		.btn1 {
			margin-right: 52rpx;
			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			justify-content: center;
			width: 310rpx;
			height: 100rpx;
			background: #E2F2FF;
			font-weight: 500;
			font-size: 40rpx;
			color: #4C97E7;
		}
		.btn2 {
			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			justify-content: center;
			width: 310rpx;
			height: 100rpx;
			background: #4C97E7;
			font-weight: 500;
			font-size: 40rpx;
			color: #FFFFFF;
		}
	}
	.card {
		padding: 0 24rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		width: 710rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0, 0, 0, 0.07);
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		.card_li:last-child {
			border-bottom: 1rpx solid #fff;
		}
		.card_li1 {
			padding-top: 24rpx;
			display: flex;
			flex-wrap: wrap;
			.taocan {
				margin-top: 10rpx;
				padding-bottom: 20rpx;
				display: flex;
				flex-wrap: wrap;
				width: 100%;
				.tc_li {
					padding: 8rpx 14rpx;
					margin-right: 20rpx;
					background: #DCEDFF;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #4297F3;
				}
			}
			.card_top {
				display: flex;
				flex-wrap: nowrap;
				align-content: center;
				justify-content: space-between;
				width: 100%;
				// border-bottom: 1rpx solid #D8D8D8;
				padding-bottom: 22rpx;
				.card_left {
					font-weight: 400;
					font-size: 30rpx;
					color: #3D3D3D;
				}
				.card_right {
					display: flex;
					flex-wrap: nowrap;
					align-items: center;
					span {
						font-weight: 400;
						font-size: 30rpx;
						color: #3D3D3D;
					}
					.input {
						text-align: right;
						/* 输入框内容靠右显示 */
					}
				}
			}
		}
		.card_li {
			padding-top: 24rpx;
			display: flex;
			flex-wrap: nowrap;
			align-content: center;
			justify-content: space-between;
			// border-bottom: 1rpx solid #D8D8D8;
			padding-bottom: 18rpx;
			.up_left {
				.txt1 {
					font-weight: 400;
					font-size: 30rpx;
					color: #3D3D3D;
				}
				.txt2 {
					margin-top: 16rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #3D3D3D;
				}
			}
			.up_rignt {
				width: 140rpx;
				height: 110rpx;
				border-radius: 10rpx;
				overflow: hidden;
				image {
					width: 110rpx;
					height: 110rpx;
					border-radius: 10rpx;
				}
				.close {
					background: #FFFFFF;
					position: absolute;
					right: 0;
					top: 0;
					width: 25rpx;
					height: 25rpx;
				}
			}
			.card_left {
				font-weight: 400;
				font-size: 30rpx;
				color: #3D3D3D;
			}
			.card_right {
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				span {
					font-weight: 400;
					font-size: 30rpx;
					color: #000;
				}
				.input {
					text-align: center;
					/* 输入框内容靠右显示 */
					color: #000;
					width: 144rpx;
					height: 60rpx;
					background: #F4F5F7;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					margin-right: 20rpx;
					padding-left: 20rpx;
				}
			}
		}
		.battery_table {
			width: 670rpx;
			max-height: 11314rpx;
			border-radius: 18rpx 18rpx 18rpx 18rpx;
			border: 1rpx solid #808080;
			overflow: hidden;
			padding-bottom: 20rpx;
			&-head,
			&-row {
				display: flex;
				align-items: center;
				padding: 12rpx 0;
				border-bottom: 1rpx solid #F0F1F5;
				.col {
					display: flex;
					align-items: center;
					min-width: 0;
					font-size: 26rpx;
					color: #111;
					&.index {
						width: 60rpx;
						justify-content: center;
					}
					&.voltage,
					&.power {
						// flex: 1;
						margin-right: 20rpx;

						gap: 12rpx;
					}
					&.action {
						width: 240rpx;
						justify-content: flex-end;
						gap: 20rpx;
					}
				}
			}
			&-head {
				font-weight: 600;
				color: #111;
				border-bottom: 2rpx solid #D8D8D8;
			}
			.inline-input {
				width: 300rpx;
				height: 60rpx;
				line-height: 60rpx;
				padding: 0 16rpx;
				border: 1rpx solid #E0E0E0;
				border-radius: 10rpx;
				text-align: left;
				color: #111;
			}
			.unit {
				font-size: 24rpx;
				color: #8A8A8A;
			}
			.link {
				font-size: 26rpx;
				color: #4297F3;
				&.disabled {
					color: #C5C5C5;
					pointer-events: none;
				}
			}
			.link.delete {
				color: #111;
			}
			&-row:last-of-type {
				border-bottom: none;
			}
			&-tip {
				margin-top: 14rpx;
				font-size: 24rpx;
				color: #8A8A8A;
				&.link-tip {
					margin-top: 30rpx;
					color: #4297F3;
					text-decoration: underline;
					cursor: pointer;
				}
			}
		}
	}
	.official_part {
		.official_list {
			display: flex;
			flex-direction: column;
			gap: 20rpx;
			padding-bottom: 20rpx;
		}
		.official_item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			border: 1rpx solid #EFEFEF;
			border-radius: 12rpx;
			background: #F9FAFB;
			gap: 20rpx;
			.cover {
				width: 120rpx;
				height: 80rpx;
				border-radius: 10rpx;
				object-fit: cover;
			}
			.info {
				display: flex;
				flex-direction: column;
				gap: 10rpx;
				.name {
					font-size: 32rpx;
					font-weight: 600;
					color: #111;
				}
				.meta {
					font-size: 24rpx;
					color: #666;
				}
			}
			.choose_btn {
				width: 120rpx;
				height: 56rpx;
				border-radius: 28rpx;
				background: #4297F3;
				color: #fff;
				font-size: 26rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
		.empty {
			text-align: center;
			color: #999;
			padding: 40rpx 0;
		}
	}
}
</style>