输入座位号自动向下填充
最近做票代系统有这样一个需求,填写多人乘车信息需要车厢车次车位号自动向下填充,如下图:
第一列输入12F后,需要像13A、13B、13C、13D、13F、14A...
下面是我的实现方法:
//输入坐席
handleInputSeat_number(index, row) {
let that = this
if (index == 0 && that.TicketForm.order_customers.length >= 2) {
that.$confirm('是否将该车厢自动向下填充', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
that.TicketForm.order_customers.map((item, index) => {
if (index !== 0) {
item.seat_number = that.getNextSeat(row.seat_number)
}
})
})
} else {
return false
}
},
getNextSeat(seat) {
//获取数字部分
let numPart = parseInt(seat.match(/\d+/)[0]);
//座位字母部分
let letterPart = ''
//最终结果
let newSeat = ''
if (seat.match(/[A-F]/) !== null) {
//获取字母座位号
letterPart = seat.match(/[A-F]/)[0];
if (letterPart === 'F') {
numPart++;
letterPart = 'A';
} else {
//charCodeAt返回字符串第一个字符的 Unicode 编码 例如A+1 就是B
letterPart = String.fromCharCode(letterPart.charCodeAt(0) + 1);
}
newSeat = numPart + letterPart;
} else {//如果输入12 不带字母情况 直接增加数字
numPart++;
newSeat = numPart
}
return newSeat;
},
这样就完成了!