vue动态禁用下拉可选项

<el-table-column label="可配送区域" align="center">
								<template slot-scope="scope">
									<!-- <el-form-item :prop="goodsList.cityIds" :rules="rules.cityIds"> -->
									<el-form-item :prop="'freightTemplateInfoList.'+[scope.$index]+'.cityIds'"
										:rules="rules.cityIds">
										<el-select v-model="scope.row.cityIds" multiple placeholder="请选择"
											@change="selectChange(scope.row.cityIds,scope.$index)">
											<el-option v-for="item in CityList" :key="item.id" :label="item.areaName"
												:value="item.id"
												:disabled="!CityList.includes(item.id) && selectedOptions.includes(item.id)">
											</el-option>
										</el-select>
									</el-form-item>
								</template>
							</el-table-column>
CityList: [], //省份列表
				selectedOptions: [], //公共列表
				goodsList: [], //模板信息
created() {
			this.getCityList()			//省份列表
			/* 初始化下拉可选项 */
			for (let j = 0; j < this.CityList.length; j++) {
				this.CityList.push({
					id: this.CityList[i].id,
					disabled: false
				})
			}
			/* 初始化下拉表格数据,得到公共选项列表'selectedOptions' */
			if (this.goodsList.length > 0) {
				let publicArr = [];
				for (let m in this.goodsList) {
					publicArr = [...publicArr]
				}
				this.selectedOptions = publicArr;
			}
		},
/* 监听下拉框值的变化,实时更新公共选项列表(选项的添加与删除) */
			selectChange() {
				let arr = [];
				for (let i in this.goodsList) {
					arr = [...arr, ...this.goodsList[i].cityIds]
					// console.log('goodsList', this.goodsList[i].cityIds) //ok
				}
				this.selectedOptions = arr;
			},

添加新数据

	//这里可以设置初始值
				obj: {
					cityIds: "", //城市ids
					firstWeight: "", //首重(kg)
					freight: '', //首重费用
					renew: '', //续重费用(/1kg)
					isDelete: '', //是否删除
					id: 0
				},        	
mounted() {
			this.tempUser = this.user
			if (this.dialogStatus == "update") {
				this.goodsList = this.user.freightTemplateInfoList
			} else {
				//解决新增添加后才实现动态禁用
				// this.goodsList = []
			}
			this.$set(this.tempUser, 'goodsList', this.goodsList)
			this.$set(this.tempUser, 'freightTemplateInfoList', this.freightTemplateInfoList)
		},

TakeAdd() {
				// console.log('push前',this.tempUser)
				this.goodsList.push(JSON.parse(JSON.stringify(this.obj)))
				this.tempUser.freightTemplateInfoList = this.goodsList
				//解决添加后选中某一值才实现动态禁用
				this.selectChange()
				// console.log('ppp后', this.tempUser)
			},
//去除已选-父组件进入详情
for (var i = 0; i < this.tempUser.freightTemplateInfoList.length; i++) {
						var a = this.tempUser.freightTemplateInfoList[i].cityIds.split(',')
						this.tempUser.freightTemplateInfoList[i].cityIds = a.map(function(item, index, array) {
							return item - 0;
						}); //此时已去除
					}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值