Browse Source

修改物料导入功能,添加单价

lwx_dev
erdanergou 3 years ago
parent
commit
8ec13562b7
  1. 4
      src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfo.java
  2. 20
      src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java
  3. 62
      src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java
  4. BIN
      src/main/resources/static/upload/materialImport.xlsx
  5. 108
      src/main/resources/templates/pages/depository/table-stock.html
  6. 106
      src/main/resources/templates/pages/material/material-out.html
  7. 103
      src/main/resources/templates/pages/materialtype/materialType_view.html
  8. BIN
      target/classes/static/upload/materialImport.xlsx

4
src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfo.java

@ -39,6 +39,10 @@ public class ExcelInfo {
@ExcelProperty("编码")
private String code;
/**单价**/
@ExcelProperty(value = "单价")
private String price;
/** 规格型号 */
@ExcelProperty("规格型号")
private String version;

20
src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java

@ -86,18 +86,18 @@ public class ExcelServiceImpl implements ExcelService {
taskCenterUtil.submitTask(() -> {
List<Object> success = new ArrayList<>();
Map<String, Object> returnResult = new HashMap<>();
for (int i = 0; i < excelVos.size(); i++) {
for (ExcelInfo excelVo : excelVos) {
Map<String, Object> param = new HashMap<>();
param.put("mname", excelVos.get(i).getMname());
param.put("code", excelVos.get(i).getCode());
param.put("unit", excelVos.get(i).getUnit());
param.put("version", excelVos.get(i).getVersion());
param.put("texture", excelVos.get(i).getTexture());
param.put("materialTypeId", excelVos.get(i).getTypeId());
param.put("id", excelVos.get(i).getId());
param.put("mname", excelVo.getMname());
param.put("code", excelVo.getCode());
param.put("unit", excelVo.getUnit());
param.put("version", excelVo.getVersion());
param.put("texture", excelVo.getTexture());
param.put("materialTypeId", excelVo.getTypeId());
param.put("id", excelVo.getId());
param.put("price",excelVo.getPrice() == null ? "0" : excelVo.getPrice());
materialService.insertMaterial(param);
success.add(excelVos.get(i));
success.add(excelVo);
}
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVos));

62
src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java

@ -80,11 +80,9 @@ public class MaterialServiceImpl implements MaterialService {
@Transactional(rollbackFor = Exception.class)
@Override
public Integer insertMaterial(Map<String, Object> map) {
if (map.containsKey("quantity") && map.containsKey("price")) {
int quantity = (int) Math.round(Double.parseDouble(map.get("quantity").toString()));
if (map.containsKey("price")) {
int price = (int) (Double.parseDouble(map.get("price").toString()) * 100);
map.put("price", price);
map.put("amounts", quantity * price);
}
// 判断是否有保质期
Integer shelfLife = 0;
@ -214,10 +212,10 @@ public class MaterialServiceImpl implements MaterialService {
map.put("state", state);
List<Material> list = materialMapper.findMaterialByCondition(map);
for (Material material : list) {
if(material.getPrice() != null){
if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100);
}else{
material.setPrice(material.getPrice() / 100);
} else {
material.setPrice(0.0);
}
material.setAmounts(material.getPrice() * material.getQuantity());
@ -267,9 +265,9 @@ public class MaterialServiceImpl implements MaterialService {
}
map.put("state", state);
List<Material> materialByCondition = materialMapper.findMaterialByCondition(map);
for (Material material:materialByCondition
) {
if(material.getPrice() != null){
for (Material material : materialByCondition
) {
if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100);
}
}
@ -373,7 +371,7 @@ public class MaterialServiceImpl implements MaterialService {
}
List<Material> list = materialMapper.findMaterialByCondition(map);
for (Material material : list) {
if(material.getPrice() == null){
if (material.getPrice() == null) {
material.setPrice(0.0);
}
material.setPrice(material.getPrice() / 100);
@ -441,7 +439,7 @@ public class MaterialServiceImpl implements MaterialService {
public List<Material> findMaterialAll() {
List<Material> materialList = materialMapper.findMaterialByCondition(new HashMap<String, Object>());
for (Material material : materialList) {
if(material.getPrice() == null){
if (material.getPrice() == null) {
material.setPrice(0.0);
}
material.setPrice(material.getPrice() / 100);
@ -461,10 +459,10 @@ public class MaterialServiceImpl implements MaterialService {
Material material = materialMapper.findMaterialById(id);
MaterialType materialTypeByOldId = materialTypeMapper.findMaterialTypeByOldId(material.getMaterialTypeId());
material.setTypeName(materialTypeByOldId.getTname());
if(material.getPrice() != null){
if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100);
}else{
material.setPrice(material.getPrice() / 100);
} else {
material.setPrice(0.0);
}
material.setAmounts(material.getPrice() * material.getQuantity());
@ -501,13 +499,13 @@ public class MaterialServiceImpl implements MaterialService {
for (Inventory inventory : inventoryByMid) {
MaterialType materialTypeByOldId = materialTypeMapper.findMaterialTypeByOldId(inventory.getMaterialTypeId());
inventory.setTypeName(materialTypeByOldId.getTname());
if(inventory.getPlaceCode() != null){
if (inventory.getPlaceCode() != null) {
inventory.setPrice(inventory.getPrice() / 100);
}else{
inventory.setPrice(inventory.getPrice() / 100);
} else {
inventory.setPrice(0.0);
}
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
}
return inventoryByMid;
}
@ -621,10 +619,10 @@ public class MaterialServiceImpl implements MaterialService {
public List<Inventory> findMaterialByIds(List<Integer> ids) {
List<Inventory> materialList = materialMapper.findInventoryByIds(ids);
for (Inventory material : materialList) {
if(material.getPrice() != null){
if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100);
}else{
material.setPrice(material.getPrice() / 100);
} else {
material.setPrice(0.0);
}
@ -820,7 +818,7 @@ public class MaterialServiceImpl implements MaterialService {
splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity);
}
if(inventory.getPrice() == null){
if (inventory.getPrice() == null) {
inventory.setPrice(0.0);
}
BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / splitInfo.getQuantity());
@ -1095,7 +1093,7 @@ public class MaterialServiceImpl implements MaterialService {
if (materialAndBarCode.getIid() != null) {
Inventory inventoryByMid = materialMapper.findInventoryById(materialAndBarCode.getIid());
if (inventoryByMid != null) {
if(inventoryByMid.getPrice() == null){
if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0);
}
materialAndBarCode.setPrice(inventoryByMid.getPrice() / 100);
@ -1537,7 +1535,7 @@ public class MaterialServiceImpl implements MaterialService {
Map<String, Object> insertForSplitInventory = new HashMap<>();
insertForSplitInventory.put("mid", inventoryByMid.getMid());
insertForSplitInventory.put("mcode", inventoryByMid.getCode());
if(inventoryByMid.getPrice() == null){
if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0);
}
insertForSplitInventory.put("price", inventoryByMid.getPrice() / scale);
@ -1555,7 +1553,7 @@ public class MaterialServiceImpl implements MaterialService {
// 定义进制时算法需要的参数
Map<String, Object> paramForNewMap = new HashMap<>();
paramForNewMap.put("mid", inventoryByMid.getMid());
if(inventoryByMid.getPrice() == null){
if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0);
}
paramForNewMap.put("price", String.valueOf(inventoryByMid.getPrice() / 100));
@ -1594,13 +1592,13 @@ public class MaterialServiceImpl implements MaterialService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, pidAndMidForAfter.getId(), paramForNewMap, quantity, splitInfo);
} else {
if(inventoryByMid.getPrice() == null){
if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0);
}
paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100));
paramForNewMap.put("realQuantity", String.valueOf(dispose));
paramForNewMap.put("quantity", String.valueOf(dispose));
depositoryRecordService.applicationInPlace(paramForNewMap,false);
depositoryRecordService.applicationInPlace(paramForNewMap, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id")));
}
// 调用新算法
@ -1641,13 +1639,13 @@ public class MaterialServiceImpl implements MaterialService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, pidAndMidForAfter.getId(), paramForNewMap, quantity, splitInfo);
} else {
if(inventoryByMid.getPrice() == null){
if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0);
}
paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100));
paramForNewMap.put("realQuantity", String.valueOf(dispose));
paramForNewMap.put("quantity", String.valueOf(dispose));
depositoryRecordService.applicationInPlace(paramForNewMap,false);
depositoryRecordService.applicationInPlace(paramForNewMap, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id")));
}
} else {
@ -1690,13 +1688,13 @@ public class MaterialServiceImpl implements MaterialService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, ObjectFormatUtil.toInteger(insertForSplitInventory.get("id")), paramForNewMap, quantity, splitInfo);
} else {
if(inventoryByMid.getPrice() == null){
if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0);
}
paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100));
paramForNewMap.put("realQuantity", String.valueOf(dispose));
paramForNewMap.put("quantity", String.valueOf(dispose));
depositoryRecordService.applicationInPlace(paramForNewMap,false);
depositoryRecordService.applicationInPlace(paramForNewMap, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id")));
}
@ -2419,7 +2417,6 @@ public class MaterialServiceImpl implements MaterialService {
}
// 构造树形组件数据模板
public Map<String, Object> InitTreeMenus_New(MaterialType mt, List<Object> children) {
if (mt != null) {
@ -2585,6 +2582,7 @@ public class MaterialServiceImpl implements MaterialService {
/**
* 获取当前仓库列表下的库存数量
*
* @param depositoryIds 待查询仓库列表
* @return
*/

BIN
src/main/resources/static/upload/materialImport.xlsx

Binary file not shown.

108
src/main/resources/templates/pages/depository/table-stock.html

@ -30,19 +30,22 @@
<div class="layui-inline">
<label class="layui-form-label">物料名称</label>
<div class="layui-input-block">
<input type="text" name="mname" autocomplete="off" class="layui-input" placeholder="请填写物料名称">
<input type="text" name="mname" autocomplete="off" class="layui-input"
placeholder="请填写物料名称">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">存货编码</label>
<div class="layui-input-block">
<input type="text" name="code" autocomplete="off" class="layui-input" placeholder="请填写物料编码">
<input type="text" name="code" autocomplete="off" class="layui-input"
placeholder="请填写物料编码">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">型号</label>
<div class="layui-input-block">
<input type="text" class="layui-input" id="version" name="version" autocomplete="off" placeholder="请填写物料型号"/>
<input type="text" class="layui-input" id="version" name="version" autocomplete="off"
placeholder="请填写物料型号"/>
</div>
</div>
@ -92,6 +95,10 @@
function changeUnit() {
}
function bindTableToolbarFunction() {
}
layui.use(['form', 'table', 'upload'], function () {
var $ = layui.jquery,
form = layui.form,
@ -197,7 +204,7 @@
});
bindTableToolbarFunction();
}
});
@ -247,7 +254,7 @@
if (data.code !== '') {
req.mcode = data.code.trim();
}
if(data.version !== ''){
if (data.version !== '') {
req.version = data.version.trim();
}
//执行搜索重载
@ -332,8 +339,8 @@
layer.full(index);
});
return false;
}else if (obj.event === 'downloadFile') {
window.open("/download/inventoryImportDownload","_self");
} else if (obj.event === 'downloadFile') {
window.open("/download/inventoryImportDownload", "_self");
}
});
@ -376,7 +383,7 @@
// 获取当前showQuantity 的长度
let length = Object.getOwnPropertyNames(showQuantity).length;
if (length> 0) {
if (length > 0) {
if (clickNum < length) {
@ -451,52 +458,55 @@
};
//用于导入数据
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importInventory', // 上传接口
accept: 'file', // 允许上传的格式,
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
},
exts: 'xls|xlsx|csv',
done: function (res) {
layer.closeAll('loading'); //关闭loading
//如果上传成功
if (res.code === 200) {
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
for (let i = 0; i < res.data.dataList.length; i++) {
var code = res.data.dataList[i]["code"] === null ? '' : res.data.dataList[i]["code"];
var mname = res.data.dataList[i]["mname"];
var version = res.data.dataList[i]["version"] === null ? '' : res.data.dataList[i]["version"];
var quantity = res.data.dataList[i]["quantity"];
var show = "<p style='color: #00FF00'>" + code + ", " + mname + ", " + version + ", 数量为" + quantity + ":成功" + "</p>";
re += show
function bindTableToolbarFunction() {
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importInventory', // 上传接口
accept: 'file', // 允许上传的格式,
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
},
exts: 'xls|xlsx|csv',
done: function (res) {
layer.closeAll('loading'); //关闭loading
//如果上传成功
if (res.code === 200) {
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
for (let i = 0; i < res.data.dataList.length; i++) {
var code = res.data.dataList[i]["code"] === null ? '' : res.data.dataList[i]["code"];
var mname = res.data.dataList[i]["mname"];
var version = res.data.dataList[i]["version"] === null ? '' : res.data.dataList[i]["version"];
var quantity = res.data.dataList[i]["quantity"];
var show = "<p style='color: #00FF00'>" + code + ", " + mname + ", " + version + ", 数量为" + quantity + ":成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
} else {
layer.msg(res.msg)
}
})
}
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
})
});
</script>

106
src/main/resources/templates/pages/material/material-out.html

@ -104,6 +104,9 @@
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
function bindTableToolbarFunction(){
}
layui.use(['form', 'table', 'upload'], function () {
var $ = layui.jquery,
form = layui.form,
@ -208,6 +211,7 @@
let col = {field: 'price', width: 150, title: '物料单价'};
cols.splice(6,0,col);
table.reload('currentTableId',{cols:[cols]});
bindTableToolbarFunction();
}
}
@ -217,6 +221,59 @@
});
//用于导入数据
function bindTableToolbarFunction() {
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importExcelByMaterial', // 上传接口
accept: 'file', // 允许上传的格式,
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
},
exts: 'xls|xlsx|csv',
done: function (res) {
layer.closeAll('loading'); //关闭loading
//如果上传成功
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
if (res.code === 200) {
for (let i = 0; i < res.data.dataList.length; i++) {
var mname = res.data.dataList[i]["mname"];
var code = res.data.dataList[i]["code"] == null || res.data.dataList[i]["code"] === undefined ? "" : res.data.dataList[i]["code"];
var version = res.data.dataList[i]["version"] == null || res.data.dataList[i]["version"] === undefined ? "" : res.data.dataList[i]["version"];
var texture = res.data.dataList[i]["texture"] == null || res.data.dataList[i]["texture"] === undefined ? "" : res.data.dataList[i]["texture"];
var unit = res.data.dataList[i]["unit"] == null || res.data.dataList[i]["unit"] === undefined ? "" : res.data.dataList[i]["unit"];
var typeId = res.data.dataList[i]["typeId"] == null || res.data.dataList[i]["typeId"] === undefined ? "" : res.data.dataList[i]["typeId"];
var show = "<p style='color: #00FF00'>" + mname + " " + version + " " + code + " " + texture + " " + unit + " " + typeId + " :成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
}
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
});
}
// 监听搜索操作
@ -362,56 +419,7 @@
}
});
//用于导入数据
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importExcelByMaterial', // 上传接口
accept: 'file', // 允许上传的格式,
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
},
exts: 'xls|xlsx|csv',
done: function (res) {
layer.closeAll('loading'); //关闭loading
//如果上传成功
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
if (res.code === 200) {
for (let i = 0; i < res.data.dataList.length; i++) {
var mname = res.data.dataList[i]["mname"];
var code = res.data.dataList[i]["code"] == null || res.data.dataList[i]["code"] == undefined ? "" : res.data.dataList[i]["code"];
var version = res.data.dataList[i]["version"] == null || res.data.dataList[i]["version"] == undefined ? "" : res.data.dataList[i]["version"];
var texture = res.data.dataList[i]["texture"] == null || res.data.dataList[i]["texture"] == undefined ? "" : res.data.dataList[i]["texture"];
var unit = res.data.dataList[i]["unit"] == null || res.data.dataList[i]["unit"] == undefined ? "" : res.data.dataList[i]["unit"];
var typeId = res.data.dataList[i]["typeId"] == null || res.data.dataList[i]["typeId"] == undefined ? "" : res.data.dataList[i]["typeId"];
var show = "<p style='color: #00FF00'>" + mname + " " + version + " " + code + " " + texture + " " + unit + " " + typeId + " :成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
}
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
});
//监听表格复选框选择
table.on('checkbox(currentTableFilter)', function (obj) {

103
src/main/resources/templates/pages/materialtype/materialType_view.html

@ -59,8 +59,12 @@
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" th:style="'display:'+${display}"> 添加</button>
<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete" th:style="'display:'+${display}"> 删除</button>
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"
th:style="'display:'+${display}"> 添加
</button>
<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"
th:style="'display:'+${display}"> 删除
</button>
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" id="u_fileUpload"
lay-event="import">导入数据
</button>
@ -73,8 +77,10 @@
<script type="text/html" id="currentTableBar">
<a class="layui-btn layui-btn-normal layui-btn-xs data-count-subclass" lay-event="subclass">子类型</a>
<a class="layui-btn layui-btn-xs data-count-edit" lay-event="detail" th:style="'display:'+${display}">详情</a>
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" th:style="'display:'+${display}">删除</a>
<a class="layui-btn layui-btn-xs data-count-edit" lay-event="detail"
th:style="'display:'+${display}">详情</a>
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete"
th:style="'display:'+${display}">删除</a>
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" th:style="'display:'+${display}"
lay-event="realDelete">彻底删除</a>
</script>
@ -83,6 +89,9 @@
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
function bindTableToolbarFunction(){
}
layui.use(['form', 'table', 'upload'], function () {
var $ = layui.jquery,
form = layui.form,
@ -132,6 +141,7 @@
page: true,
skin: 'line',
done: function () {
bindTableToolbarFunction();
}
});
@ -175,8 +185,7 @@
$(window).on("resize", function () {
layer.full(index);
});
}
else if (obj.event === 'delete') { // 监听删除操作
} else if (obj.event === 'delete') { // 监听删除操作
var checkStatus = table.checkStatus('currentTableId')
, data = checkStatus.data;
var req = {};
@ -221,55 +230,57 @@
layer.msg("未选中记录,请确认!");
return false;
}
}
else if (obj.event === 'downloadFile') {
window.open("/download/materialTypeImportDownload","_self");
} else if (obj.event === 'downloadFile') {
window.open("/download/materialTypeImportDownload", "_self");
}
});
//用于导入数据
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importExcelByMT', // 上传接口
accept: 'file', // 允许上传的格式,
exts: 'xls|xlsx|csv',
done: function (res) {
//如果上传成功
if (res.code == 200) {
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
for (let i = 0; i < res.data.dataList.length; i++) {
var tname = res.data.dataList[i]["tname"];
var id = res.data.dataList[i]["oldId"];
var parentId = res.data.dataList[i]["parentId"] == null ? "" : res.data.dataList[i]["parentId"];
var introduce = res.data.dataList[i]["introduce"] == null ? "" : res.data.dataList[i]["introduce"];
var show = "<p style='color: #00FF00'>" + tname + " " + id + " " + parentId + "成功" + "</p>";
re += show
//用于导入数据
function bindTableToolbarFunction() {
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importExcelByMT', // 上传接口
accept: 'file', // 允许上传的格式,
exts: 'xls|xlsx|csv',
done: function (res) {
//如果上传成功
if (res.code == 200) {
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
for (let i = 0; i < res.data.dataList.length; i++) {
var tname = res.data.dataList[i]["tname"];
var id = res.data.dataList[i]["oldId"];
var parentId = res.data.dataList[i]["parentId"] == null ? "" : res.data.dataList[i]["parentId"];
var introduce = res.data.dataList[i]["introduce"] == null ? "" : res.data.dataList[i]["introduce"];
var show = "<p style='color: #00FF00'>" + tname + " " + id + " " + parentId + "成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
},
error: function () {
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
} else {
layer.msg(res.msg)
}
});
}
},
error: function () {
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
});
//监听表格复选框选择
table.on('checkbox(currentTableFilter)', function (obj) {

BIN
target/classes/static/upload/materialImport.xlsx

Binary file not shown.
Loading…
Cancel
Save