车辆绑定车型

This commit is contained in:
19173159168
2025-07-27 21:40:25 +08:00
parent 5352216ea7
commit 826973265e
9 changed files with 33 additions and 16 deletions

View File

@ -159,7 +159,7 @@ public class ZcCarModelController extends BaseController
@PostMapping("/getModels") @PostMapping("/getModels")
@ResponseBody @ResponseBody
public List<String> getModels(String brandName) { public List<ZcCarModel> getModels(String brandName) {
return zcCarModelService.selectModelsByBrand(brandName); return zcCarModelService.selectModelsByBrand(brandName);
} }

View File

@ -61,6 +61,6 @@ public interface ZcCarModelMapper
public List<String> selectAllBrands(); public List<String> selectAllBrands();
public List<String> selectModelsByBrand(String brandName); public List<ZcCarModel> selectModelsByBrand(String brandName);
} }

View File

@ -72,6 +72,6 @@ public interface IZcCarModelService
/** /**
* 根据品牌查询车型列表 * 根据品牌查询车型列表
*/ */
List<String> selectModelsByBrand(String brandName); List<ZcCarModel> selectModelsByBrand(String brandName);
} }

View File

@ -154,7 +154,7 @@ public class ZcCarModelServiceImpl implements IZcCarModelService
@Override @Override
public List<String> selectModelsByBrand(String brandName) { public List<ZcCarModel> selectModelsByBrand(String brandName) {
return zcCarModelMapper.selectModelsByBrand(brandName); return zcCarModelMapper.selectModelsByBrand(brandName);
} }

View File

@ -75,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="packageName != null and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if> <if test="packageName != null and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if>
<if test="status != null and status != ''"> and status = #{status}</if> <if test="status != null and status != ''"> and status = #{status}</if>
</where> </where>
order by update_time desc
</select> </select>
<select id="selectZcCarById" parameterType="Long" resultMap="ZcCarResult"> <select id="selectZcCarById" parameterType="Long" resultMap="ZcCarResult">

View File

@ -140,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SELECT DISTINCT brand_name FROM zc_car_model where del_flag = 0 ORDER BY brand_name ASC SELECT DISTINCT brand_name FROM zc_car_model where del_flag = 0 ORDER BY brand_name ASC
</select> </select>
<select id="selectModelsByBrand" resultType="string"> <select id="selectModelsByBrand" resultMap="ZcCarModelResult">
SELECT model_name FROM zc_car_model WHERE del_flag = 0 and brand_name = #{brandName} ORDER BY model_name ASC SELECT id,model_name FROM zc_car_model WHERE del_flag = 0 and brand_name = #{brandName} ORDER BY model_name ASC
</select> </select>
</mapper> </mapper>

View File

@ -47,7 +47,7 @@
<h2 style="text-align: center" class="login-title">[[${name}]]</h2> <h2 style="text-align: center" class="login-title">[[${name}]]</h2>
<form id="signupForm" autocomplete="off" style="background: #fff"> <form id="signupForm" autocomplete="off" style="background: #fff">
<input type="text" name="username" class="form-control uname" placeholder="用户名" value="admin" /> <input type="text" name="username" class="form-control uname" placeholder="用户名" value="admin" />
<input type="password" name="password" class="form-control pword" placeholder="密码" value="admin123" /> <input type="password" name="password" class="form-control pword" placeholder="密码" value="12345678" />
<!-- <input type="text" name="username" class="form-control uname" placeholder="用户名" />--> <!-- <input type="text" name="username" class="form-control uname" placeholder="用户名" />-->
<!-- <input type="password" name="password" class="form-control pword" placeholder="密码" />--> <!-- <input type="password" name="password" class="form-control pword" placeholder="密码" />-->
<div class="row m-t" th:if="${captchaEnabled==true}"> <div class="row m-t" th:if="${captchaEnabled==true}">

View File

@ -31,7 +31,8 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label is-required">车辆型号:</label> <label class="col-sm-3 control-label is-required">车辆型号:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<select name="modelName" id="model-select" class="form-control m-b" required disabled> <input type="hidden" id="modelName" name="modelName" >
<select name="modelId" id="model-select" class="form-control m-b" required disabled>
<option value="">请先选择品牌</option> <option value="">请先选择品牌</option>
</select> </select>
</div> </div>
@ -156,7 +157,7 @@
modelSelect.append('<option value="">暂无车型</option>').prop('disabled', true); modelSelect.append('<option value="">暂无车型</option>').prop('disabled', true);
} else { } else {
models.forEach(function (model) { models.forEach(function (model) {
modelSelect.append('<option value="' + model + '">' + model + '</option>'); modelSelect.append('<option value="' + model.id + '">' + model.modelName + '</option>');
}); });
modelSelect.prop('disabled', false); modelSelect.prop('disabled', false);
} }
@ -164,6 +165,11 @@
}); });
}); });
$('#model-select').on('change', function () {
var modelName = $('#model-select option:selected').text();
// 将门店名称赋值给隐藏输入框
$("#modelName").val(modelName);
});
// 加载运营商列表 // 加载运营商列表
$.ajax({ $.ajax({

View File

@ -32,7 +32,8 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label is-required">车辆型号:</label> <label class="col-sm-3 control-label is-required">车辆型号:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<select name="modelName" id="model-select" class="form-control m-b" required disabled> <input type="hidden" id="modelName" name="modelName" >
<select name="modelId" id="model-select" class="form-control m-b" required disabled>
<option value="">请先选择品牌</option> <option value="">请先选择品牌</option>
</select> </select>
</div> </div>
@ -118,7 +119,8 @@
// 保存当前车辆的品牌与车型值 // 保存当前车辆的品牌与车型值
var savedBrand = [[${zcCar.brandName}]]; var savedBrand = [[${zcCar.brandName}]];
var savedModel = [[${zcCar.modelName}]]; var modelId = [[${zcCar.modelId}]];
var modelName = [[${zcCar.modelName}]];
// 加载品牌列表 // 加载品牌列表
$.ajax({ $.ajax({
@ -141,7 +143,7 @@
// 如果有已选品牌,则触发加载车型 // 如果有已选品牌,则触发加载车型
if (savedBrand) { if (savedBrand) {
modelSelect.prop('disabled', false).empty().append('<option value="">加载中...</option>'); modelSelect.prop('disabled', false).empty().append('<option value="">加载中...</option>');
loadModels(savedBrand, savedModel); loadModels(savedBrand, modelName);
} }
} }
}); });
@ -157,7 +159,7 @@
}); });
// =================== 加载车型方法封装 =================== // =================== 加载车型方法封装 ===================
function loadModels(brandName, savedModel = null) { function loadModels(brandName, modelName = null) {
$.ajax({ $.ajax({
url: ctx + 'operation/carModel/getModels', url: ctx + 'operation/carModel/getModels',
type: 'POST', type: 'POST',
@ -169,18 +171,26 @@
modelSelect.append('<option value="">暂无车型</option>').prop('disabled', true); modelSelect.append('<option value="">暂无车型</option>').prop('disabled', true);
} else { } else {
models.forEach(function (model) { models.forEach(function (model) {
modelSelect.append($('<option>').val(model).text(model)); modelSelect.append($('<option>').val(model.id).text(model.modelName));
}); });
modelSelect.prop('disabled', false); modelSelect.prop('disabled', false);
// 回显车型 // 回显车型
if (savedModel) { if (modelName) {
modelSelect.val(savedModel); modelSelect.val(modelId);
// 设置隐藏域
var selectedModelName = modelSelect.find('option:selected').text();
$('#modelName').val(selectedModelName);
} }
} }
} }
}); });
} }
$('#model-select').on('change', function () {
var modelName = $('#model-select option:selected').text();
// 将门店名称赋值给隐藏输入框
$("#modelName").val(modelName);
});
// 获取运营商与门店下拉框 // 获取运营商与门店下拉框
var operatorSelect = $('#operator-select'); var operatorSelect = $('#operator-select');