车辆导入导出
This commit is contained in:
@ -24,6 +24,7 @@ import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 车辆管理Controller
|
||||
@ -44,8 +45,10 @@ public class ZcCarController extends BaseController
|
||||
|
||||
@RequiresPermissions("operation:car:view")
|
||||
@GetMapping()
|
||||
public String car()
|
||||
public String car(ModelMap mmap)
|
||||
{
|
||||
List<Company> companyList = companyService.getCompanyList(new Company(),getSysUser()); // 获取运营商列表
|
||||
mmap.put("companyList", companyList); // 将运营商列表传递到前端
|
||||
return prefix + "/car";
|
||||
}
|
||||
|
||||
@ -58,6 +61,10 @@ public class ZcCarController extends BaseController
|
||||
public TableDataInfo list(ZcCar zcCar)
|
||||
{
|
||||
startPage();
|
||||
// 运营者账号,只能查询所属商户数据
|
||||
if(UserConstants.USER_TYPE_02 .equals(getSysUser().getUserType())){
|
||||
zcCar.setOperatorId(getSysUser().getGroupId());
|
||||
}
|
||||
List<ZcCar> list = zcCarService.selectZcCarList(zcCar);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@ -71,6 +78,10 @@ public class ZcCarController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult export(ZcCar zcCar)
|
||||
{
|
||||
// 运营者账号,只能查询所属商户数据
|
||||
if(UserConstants.USER_TYPE_02 .equals(getSysUser().getUserType())){
|
||||
zcCar.setOperatorId(getSysUser().getGroupId());
|
||||
}
|
||||
List<ZcCar> list = zcCarService.selectZcCarList(zcCar);
|
||||
ExcelUtil<ZcCar> util = new ExcelUtil<ZcCar>(ZcCar.class);
|
||||
return util.exportExcel(list, "车辆管理数据");
|
||||
@ -134,9 +145,25 @@ public class ZcCarController extends BaseController
|
||||
&& OperationConstants.USER_VIN_NOT_UNIQUE.equals(zcCarService.checkVinUnique(zcCar))) {
|
||||
return error("修改失败,车机号已存在");
|
||||
}
|
||||
|
||||
return toAjax(zcCarService.updateZcCar(zcCar));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配车辆
|
||||
*/
|
||||
@RequiresPermissions("operation:car:distribute")
|
||||
@GetMapping("/distribute/{id}")
|
||||
public String distribute(@PathVariable("id") Long id, ModelMap mmap)
|
||||
{
|
||||
List<Company> companyList = companyService.getCompanyList(new Company(),getSysUser()); // 获取运营商列表
|
||||
mmap.put("companyList", companyList); // 将运营商列表传递到前端
|
||||
|
||||
ZcCar zcCar = zcCarService.selectZcCarById(id);
|
||||
mmap.put("zcCar", zcCar);
|
||||
return prefix + "/distribute";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除车辆管理
|
||||
*/
|
||||
@ -164,7 +191,20 @@ public class ZcCarController extends BaseController
|
||||
public AjaxResult importTemplate()
|
||||
{
|
||||
ExcelUtil<ZcCar> util = new ExcelUtil<ZcCar>(ZcCar.class);
|
||||
return util.importTemplateExcel("车辆数据");
|
||||
return util.importTemplateExcel("车辆数据模板");
|
||||
}
|
||||
|
||||
@Log(title = "车辆管理-导入", businessType = BusinessType.IMPORT)
|
||||
@RequiresPermissions("operation:car:import")
|
||||
@PostMapping("/importData")
|
||||
@ResponseBody
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
||||
{
|
||||
ExcelUtil<ZcCar> util = new ExcelUtil<ZcCar>(ZcCar.class);
|
||||
List<ZcCar> carList = util.importExcel(file.getInputStream());
|
||||
String message = zcCarService.importCar(carList, updateSupport, getSysUser());
|
||||
return AjaxResult.success(message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -80,6 +80,10 @@ public class ZcRentCarRuleController extends BaseController
|
||||
@ResponseBody
|
||||
public AjaxResult export(ZcRentCarRule zcRentCarRule)
|
||||
{
|
||||
// 运营者账号,只能查询所属商户数据
|
||||
if(UserConstants.USER_TYPE_02 .equals(getSysUser().getUserType())){
|
||||
zcRentCarRule.setOperatingCompanyId(getSysUser().getGroupId());
|
||||
}
|
||||
List<ZcRentCarRule> list = zcRentCarRuleService.selectZcRentCarRuleList(zcRentCarRule);
|
||||
ExcelUtil<ZcRentCarRule> util = new ExcelUtil<ZcRentCarRule>(ZcRentCarRule.class);
|
||||
return util.exportExcel(list, "租车计费规则数据");
|
||||
|
||||
@ -30,31 +30,26 @@ public class ZcCar extends BaseEntity
|
||||
private String licensePlate;
|
||||
|
||||
/** 车辆品牌ID */
|
||||
@Excel(name = "车辆品牌ID")
|
||||
private Long brandId;
|
||||
|
||||
/** 车辆品牌名称 */
|
||||
@Excel(name = "车辆品牌名称")
|
||||
@Excel(name = "车辆品牌")
|
||||
private String brandName;
|
||||
|
||||
/** 车辆型号ID */
|
||||
@Excel(name = "车辆型号ID")
|
||||
private Long modelId;
|
||||
|
||||
/** 车辆型号名称 */
|
||||
@Excel(name = "车辆型号名称")
|
||||
@Excel(name = "车辆型号")
|
||||
private String modelName;
|
||||
|
||||
/** 支持电池类型 */
|
||||
@Excel(name = "支持电池类型")
|
||||
private String batteryType;
|
||||
|
||||
/** 整车重量(kg) */
|
||||
@Excel(name = "整车重量(kg)")
|
||||
private String weight;
|
||||
|
||||
/** 最高时速(km/h) */
|
||||
@Excel(name = "最高时速(km/h)")
|
||||
private String maxSpeed;
|
||||
|
||||
/** LOT识别号 */
|
||||
@ -75,15 +70,12 @@ public class ZcCar extends BaseEntity
|
||||
private String belongType;
|
||||
|
||||
/** 车辆图片 */
|
||||
@Excel(name = "车辆图片")
|
||||
private String images;
|
||||
|
||||
/** BRS车辆状态 */
|
||||
@Excel(name = "BRS车辆状态")
|
||||
private String brsStatus;
|
||||
|
||||
/** IoT设备状态 */
|
||||
@Excel(name = "IoT设备状态")
|
||||
private String iotStatus;
|
||||
|
||||
/** IoT识别码 */
|
||||
@ -91,31 +83,26 @@ public class ZcCar extends BaseEntity
|
||||
private String iotCode;
|
||||
|
||||
/** 所属运营商ID */
|
||||
@Excel(name = "所属运营商ID")
|
||||
private Long operatorId;
|
||||
|
||||
/** 所属运营商名称 */
|
||||
@Excel(name = "所属运营商名称")
|
||||
@Excel(name = "所属运营商")
|
||||
private String operatorName;
|
||||
|
||||
/** 所属门店ID */
|
||||
@Excel(name = "所属门店ID")
|
||||
private Long storeId;
|
||||
|
||||
/** 所属门店名称 */
|
||||
@Excel(name = "所属门店名称")
|
||||
@Excel(name = "所属门店")
|
||||
private String storeName;
|
||||
|
||||
/** 应用套餐ID */
|
||||
@Excel(name = "应用套餐ID")
|
||||
private Long packageId;
|
||||
|
||||
/** 应用套餐名称 */
|
||||
@Excel(name = "应用套餐名称")
|
||||
private String packageName;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
private String status;
|
||||
|
||||
/** 删除标志 */
|
||||
|
||||
@ -2,6 +2,7 @@ package com.ruoyi.operation.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.operation.domain.ZcCar;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 车型管理Mapper接口
|
||||
@ -35,6 +36,8 @@ public interface ZcCarMapper
|
||||
*/
|
||||
public int insertZcCar(ZcCar zcCar);
|
||||
|
||||
int batchInsert(@Param("list") List<ZcCar> carList);
|
||||
|
||||
/**
|
||||
* 修改车型管理
|
||||
*
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.ruoyi.operation.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.operation.domain.ZcCar;
|
||||
|
||||
/**
|
||||
@ -68,4 +70,8 @@ public interface IZcCarService
|
||||
String checkVinUnique(ZcCar zcCar);
|
||||
|
||||
public int changeStatus(ZcCar zcCar);
|
||||
|
||||
public String importCar(List<ZcCar> carList, Boolean isUpdateSupport, SysUser user);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,24 @@
|
||||
package com.ruoyi.operation.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.DictUtils;
|
||||
import com.ruoyi.common.utils.ShiroUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.bean.BeanValidators;
|
||||
import com.ruoyi.operation.domain.Company;
|
||||
import com.ruoyi.operation.domain.CompanyStore;
|
||||
import com.ruoyi.operation.service.ICompanyService;
|
||||
import com.ruoyi.operation.service.ICompanyStoreService;
|
||||
import com.ruoyi.operation.util.OperationConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.operation.mapper.ZcCarMapper;
|
||||
@ -11,6 +26,8 @@ import com.ruoyi.operation.domain.ZcCar;
|
||||
import com.ruoyi.operation.service.IZcCarService;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
|
||||
import javax.validation.Validator;
|
||||
|
||||
/**
|
||||
* 车型管理Service业务层处理
|
||||
*
|
||||
@ -20,9 +37,18 @@ import com.ruoyi.common.core.text.Convert;
|
||||
@Service
|
||||
public class ZcCarServiceImpl implements IZcCarService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(ZcCarServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private ZcCarMapper zcCarMapper;
|
||||
|
||||
@Autowired
|
||||
private ICompanyService companyService;
|
||||
@Autowired
|
||||
private ICompanyStoreService companyStoreService;
|
||||
|
||||
protected Validator validator;
|
||||
|
||||
/**
|
||||
* 查询车型管理
|
||||
*
|
||||
@ -57,6 +83,7 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
public int insertZcCar(ZcCar zcCar)
|
||||
{
|
||||
zcCar.setCreateTime(DateUtils.getNowDate());
|
||||
zcCar.setUpdateTime(DateUtils.getNowDate());
|
||||
return zcCarMapper.insertZcCar(zcCar);
|
||||
}
|
||||
|
||||
@ -113,5 +140,82 @@ public class ZcCarServiceImpl implements IZcCarService
|
||||
return zcCarMapper.updateZcCar(zcCar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importCar(List<ZcCar> carList, Boolean isUpdateSupport, SysUser user) {
|
||||
if (StringUtils.isNull(carList) || carList.size() == 0)
|
||||
{
|
||||
throw new ServiceException("导入车辆数据不能为空!");
|
||||
}
|
||||
|
||||
// 一次性查询所有运营商和门店,构建成 Map 用于快速查找
|
||||
List<Company> companyList = companyService.getCompanyList(new Company(),user); // 获取运营商列表
|
||||
Map<String, Long> companyMap = companyList.stream()
|
||||
.collect(Collectors.toMap(Company::getCompanyName, Company::getId));
|
||||
|
||||
List<CompanyStore> storeList = companyStoreService.selectCompanyStoreList(new CompanyStore());
|
||||
Map<String, Long> storeMap = storeList.stream()
|
||||
.collect(Collectors.toMap(CompanyStore::getName, CompanyStore::getId));
|
||||
|
||||
|
||||
int successNum = 0;
|
||||
int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
List<ZcCar> processedList = new ArrayList<ZcCar>();
|
||||
for (ZcCar car : carList)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证是否存在这个用户
|
||||
ZcCar u = zcCarMapper.checkVinUnique(car.getVin());
|
||||
if (StringUtils.isNull(u))
|
||||
{
|
||||
// 车辆归属字典转换
|
||||
car.setBelongType(DictUtils.getDictValue("key_car_belong_type", car.getBelongType(), car.getBelongType()));
|
||||
// 设置运营商ID
|
||||
if (StringUtils.isNotEmpty(car.getOperatorName()) && companyMap.containsKey(car.getOperatorName())) {
|
||||
car.setOperatorId(companyMap.get(car.getOperatorName()));
|
||||
}
|
||||
|
||||
// 设置门店ID
|
||||
if (StringUtils.isNotEmpty(car.getStoreName()) && storeMap.containsKey(car.getStoreName())) {
|
||||
car.setStoreId(storeMap.get(car.getStoreName()));
|
||||
}
|
||||
car.setCreateBy(user.getLoginName());
|
||||
|
||||
this.insertZcCar(car);
|
||||
// processedList.add(car);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、车机号 " + car.getVin() + " 导入成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + failureNum + "、车机号 " + car.getVin() + " 已存在");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、车机号 " + car.getVin() + " 导入失败:";
|
||||
failureMsg.append(msg + e.getMessage());
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (failureNum > 0)
|
||||
{
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// zcCarMapper.batchInsert(processedList);
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -163,6 +163,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="extend5 != null">#{extend5},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO zc_car (vin, license_plate, brand_name,
|
||||
model_name, lot_number, purchase_date,
|
||||
purchase_price, belong_type, iot_code,
|
||||
operator_id, operator_name,
|
||||
store_id, store_name,
|
||||
create_by, create_time, update_time, remark)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.vin}, #{item.licensePlate}, #{item.brandName}
|
||||
#{item.modelName}, #{item.lotNumber}, #{item.purchaseDate}
|
||||
#{item.purchasePrice}, #{item.belongType}, #{item.iotCode}
|
||||
#{item.operatorId}, #{item.operatorName},
|
||||
#{item.storeId}, #{item.storeName},
|
||||
#{item.createBy}, #{item.createTime}, #{item.updateTime},#{item.remark})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateZcCar" parameterType="ZcCar">
|
||||
update zc_car
|
||||
@ -186,7 +203,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="iotCode != null">iot_code = #{iotCode},</if>
|
||||
<if test="operatorId != null">operator_id = #{operatorId},</if>
|
||||
<if test="operatorName != null">operator_name = #{operatorName},</if>
|
||||
<if test="storeId != null">store_id = #{storeId},</if>
|
||||
<if test="storeName != null">store_name = #{storeName},</if>
|
||||
<if test="packageId != null">package_id = #{packageId},</if>
|
||||
<if test="packageName != null">package_name = #{packageName},</if>
|
||||
@ -202,6 +218,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="extend3 != null">extend3 = #{extend3},</if>
|
||||
<if test="extend4 != null">extend4 = #{extend4},</if>
|
||||
<if test="extend5 != null">extend5 = #{extend5},</if>
|
||||
store_id = #{storeId}
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
@ -27,11 +27,14 @@
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label>所属运营商名称:</label>
|
||||
<input type="text" name="operatorName"/>
|
||||
<label>所属运营商:</label>
|
||||
<select name="operatingId" id="operatingId" >
|
||||
<option value="">请选择所属运营商</option>
|
||||
<option th:each="company : ${companyList}" th:value="${company.id}" th:text="${company.companyName}"></option>
|
||||
</select>
|
||||
</li>
|
||||
<li>
|
||||
<label>所属门店名称:</label>
|
||||
<label>所属门店:</label>
|
||||
<input type="text" name="storeName"/>
|
||||
</li>
|
||||
<li>
|
||||
@ -68,6 +71,7 @@
|
||||
<th:block th:include="include :: footer" />
|
||||
<script th:inline="javascript">
|
||||
var editFlag = [[${@permission.hasPermi('operation:car:edit')}]];
|
||||
var distributeFlag = [[${@permission.hasPermi('operation:car:distribute')}]];
|
||||
var removeFlag = [[${@permission.hasPermi('operation:car:remove')}]];
|
||||
var statusDatas = [[${@dict.getType('key_car_status')}]];
|
||||
var batteryTypeDatas = [[${@dict.getType('key_car_battery_type')}]];
|
||||
@ -160,7 +164,7 @@
|
||||
formatter: function(value, row, index) {
|
||||
var actions = [];
|
||||
actions.push('<a class="btn btn-success btn-xs ' + editFlag + ' btnOption" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
|
||||
actions.push('<a class="btn btn-success btn-xs ' + editFlag + ' btnOption" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>分配</a> ');
|
||||
actions.push('<a class="btn btn-success btn-xs ' + distributeFlag + ' btnOption" href="javascript:void(0)" onclick="distribute(\'' + row.id + '\')"><i class="fa fa-edit"></i>分配</a> ');
|
||||
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + ' btnOption" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
|
||||
if (row.status == 1) {
|
||||
actions.push('<a class="btn btn-success btn-xs ' + editFlag + ' btnOption" href="javascript:void(0)" onclick="enable(\'' + row.id + '\')"><i class="fa fa-edit"></i>上架</a> ');
|
||||
@ -174,6 +178,9 @@
|
||||
$.table.init(options);
|
||||
});
|
||||
|
||||
function distribute(id){
|
||||
$.modal.open("车辆分配", prefix + "/distribute/" + id);
|
||||
}
|
||||
/* 下架 */
|
||||
function disable(id) {
|
||||
$.modal.confirm("确认是否下架此车辆?<span style='color: red'>下架后此车辆将在不会显示在用户小程序中</span>", function() {
|
||||
|
||||
@ -0,0 +1,163 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
|
||||
<head>
|
||||
<th:block th:include="include :: header('分配车辆')" />
|
||||
<th:block th:include="include :: datetimepicker-css" />
|
||||
</head>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-car-edit" th:object="${zcCar}">
|
||||
<input name="id" th:field="*{id}" type="hidden">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">车架号(VIN):</label>
|
||||
<div class="col-sm-8">
|
||||
<input readonly name="vin" th:field="*{vin}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">车牌号码:</label>
|
||||
<div class="col-sm-8">
|
||||
<input readonly name="licensePlate" th:field="*{licensePlate}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">车辆归属:</label>
|
||||
<div class="col-sm-8">
|
||||
<select readonly name="belongType" class="form-control m-b" th:with="type=${@dict.getType('key_car_belong_type')}">
|
||||
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{belongType}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">所属运营商:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="operatorName" id="operatorName" class="form-control" type="hidden" >
|
||||
<select name="operatorId" id="operator-select" class="form-control m-b" required>
|
||||
<option value="">请选择运营商</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">所属门店:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="storeName" id="storeName" class="form-control" type="hidden" >
|
||||
<select name="storeId" id="store-select" class="form-control m-b" disabled>
|
||||
<option value="">请先选择运营商</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<th:block th:include="include :: footer" />
|
||||
<th:block th:include="include :: datetimepicker-js" />
|
||||
<script th:inline="javascript">
|
||||
var prefix = ctx + "operation/car";
|
||||
$("#form-car-edit").validate({
|
||||
focusCleanup: true
|
||||
});
|
||||
$(function () {
|
||||
|
||||
// 获取运营商与门店下拉框
|
||||
var operatorSelect = $('#operator-select');
|
||||
var storeSelect = $('#store-select');
|
||||
|
||||
// 保存当前车辆的运营商与门店值
|
||||
var savedOperatorId = [[${zcCar.operatorId}]];
|
||||
var savedStoreId = [[${zcCar.storeId}]];
|
||||
|
||||
// =================== 加载运营商列表 ===================
|
||||
$.ajax({
|
||||
url: ctx + 'operation/company/companyAll',
|
||||
type: 'GET',
|
||||
success: function (companies) {
|
||||
companies.forEach(function (company) {
|
||||
var option = $('<option>').val(company.id).text(company.companyName);
|
||||
if (company.id == savedOperatorId) {
|
||||
option.attr('selected', 'selected');
|
||||
}
|
||||
operatorSelect.append(option);
|
||||
});
|
||||
|
||||
// 如果有已选运营商,则触发加载门店
|
||||
if (savedOperatorId) {
|
||||
storeSelect.prop('disabled', false).empty().append('<option value="">加载中...</option>');
|
||||
loadStores(savedOperatorId, savedStoreId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// =================== 运营商选择变化事件 ===================
|
||||
operatorSelect.on('change', function () {
|
||||
var selectedOperatorId = $(this).val();
|
||||
if (!selectedOperatorId) {
|
||||
storeSelect.empty().append('<option value="">请先选择运营商</option>').prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置隐藏域 operatorName
|
||||
var selectedOperatorName = operatorSelect.find('option:selected').text();
|
||||
$('#operatorName').val(selectedOperatorName);
|
||||
|
||||
loadStores(selectedOperatorId);
|
||||
});
|
||||
|
||||
// =================== 加载门店方法封装 ===================
|
||||
function loadStores(operatorId, savedStoreId = null) {
|
||||
$.ajax({
|
||||
url: ctx + 'operation/store/storesByCompanyId',
|
||||
type: 'POST',
|
||||
data: { companyId: operatorId },
|
||||
success: function (stores) {
|
||||
storeSelect.empty();
|
||||
$('#storeName').val('');
|
||||
if (stores.length === 0) {
|
||||
storeSelect.append('<option value="">暂无门店</option>').prop('disabled', true);
|
||||
} else {
|
||||
storeSelect.append($('<option>').val('').text('请选择门店'));
|
||||
stores.forEach(function (store) {
|
||||
storeSelect.append($('<option>').val(store.id).text(store.name));
|
||||
});
|
||||
storeSelect.prop('disabled', false);
|
||||
|
||||
// 回显门店
|
||||
if (savedStoreId) {
|
||||
storeSelect.val(savedStoreId);
|
||||
// 设置隐藏域 storeName
|
||||
var selectedStoreName = storeSelect.find('option:selected').text();
|
||||
$('#storeName').val(selectedStoreName);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// =================== 门店选择变化事件 ===================
|
||||
storeSelect.on('change', function () {
|
||||
var selectedStoreId = $(this).val();
|
||||
var selectedStoreName = $(this).find('option:selected').text();
|
||||
if(selectedStoreId != ''){
|
||||
$('#storeName').val(selectedStoreName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
$.operate.save(prefix + "/edit", $('#form-car-edit').serialize());
|
||||
}
|
||||
}
|
||||
|
||||
$("input[name='purchaseDate']").datetimepicker({
|
||||
format: "yyyy-mm-dd",
|
||||
minView: "month",
|
||||
autoclose: true
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -234,10 +234,11 @@
|
||||
data: { companyId: operatorId },
|
||||
success: function (stores) {
|
||||
storeSelect.empty();
|
||||
|
||||
$('#storeName').val('');
|
||||
if (stores.length === 0) {
|
||||
storeSelect.append('<option value="">暂无门店</option>').prop('disabled', true);
|
||||
} else {
|
||||
storeSelect.append($('<option>').val('').text('请选择门店'));
|
||||
stores.forEach(function (store) {
|
||||
storeSelect.append($('<option>').val(store.id).text(store.name));
|
||||
});
|
||||
@ -259,7 +260,9 @@
|
||||
storeSelect.on('change', function () {
|
||||
var selectedStoreId = $(this).val();
|
||||
var selectedStoreName = $(this).find('option:selected').text();
|
||||
$('#storeName').val(selectedStoreName);
|
||||
if(selectedStoreId != ''){
|
||||
$('#storeName').val(selectedStoreName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user