business-card/src/main/resources/static/route/namecardList/namecardList.html
2021-06-03 15:50:52 +08:00

732 lines
34 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<base href="/businesscard/">
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
<link rel="stylesheet" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.css"/>
<link rel="stylesheet" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
<title>名片</title>
<style>
.btn-box{padding: 10px;background: #fff}
.layui-form{padding: 10px}
.layui-form-label{width: 66px;}
.layui-input-block{margin-left: 96px}
.submit-btn{display: block;margin: 0 auto;}
.layui-upload-img{width:90px;height:90px;}
.card-table{background: #fff;padding: 0 10px;overflow: hidden}
#cardTable{display: none}
.layui-table-page{padding: 3px 0 0;}
label{cursor: pointer}
</style>
</head>
<body >
<div class="layui-card layadmin-header">
<div class="layui-breadcrumb" lay-filter="breadcrumb">
<a lay-href="">主页</a>
<a><cite>名片列表</cite></a>
</div>
</div>
<div class="layui-fluid" id="imgShow">
<div class="layui-row">
<div class="card-table">
<table id="cardTable" class="layui-table" lay-filter="cardTable"></table>
</div>
</div>
</div>
</body>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script src="assets/businessCard/js/requestUrl.js"></script>
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
<!--<script src="assets/businessCard/js/namecardList.js"></script>-->
<script>
// layui.use('namecardList', layui.factory('namecardList'));
layui.config({
base: 'assets/layuiadmin/'
}).extend({
index: 'lib/index'
}).use(['form', 'upload', 'table'], function () {
var $ = layui.$
var form = layui.form;
var upload = layui.upload;
var table = layui.table;
var requestUrl = layui.requestUrl;
var $win = $(window);
var industryHtml = '';
var html = ''
var code = ''
var bgImgId = ''
var fontHtml = ''
var finishCount = 0
var industryList = []
var cardInfo = {}
var innerCount = 0
var token = layui.requestUrl.token
function initTable() {
table.render({
elem: '#cardTable',
id: 'cardTable',
toolbar: '#headerToolBar',
height: $win.height() - 60,
limit: 20,
limits: [20, 40, 60, 80, 100, 200],
url: requestUrl.url + '/app/cardtemplate/listpagecardtemplate',
headers: {
token: token
},
request: {
pageName: 'page',
limitName: 'rows'
},
// parseData: function(res) {
// return {
// "code": 0,
// "msg": res.msg,
// "data": res,
// "count": res.length
// }
// },
page: true,
parseData: function(data) {
return {
'code': 0,
'msg': '',
'count': data.total,
'data': data.rows
};
},
cols: [[
{type:'checkbox', fixed: 'left'},
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
{
field: 'templateTitle',
title: '名片名称',
width: '180',
sort: false,
},
{
field: 'templateDescription',
title: '名片简介',
width: '200',
sort: false,
},
{
field: 'templateStatus',
title: '是否收费',
width: '80',
sort: false,
templet: function (data) {
var charge = ''
if (data.templateStatus == '0') {
charge = '<span style="color: red">停用</span>'
} else {
charge = '<span style="color: green">公开</span>'
}
return charge
}
},
{
field: 'templateIndustry',
title: '使用行业',
width: '150',
sort: false,
templet: function (data) {
var ids = data.templateIndustry.split('_')
var text = ''
for (var i = 0; i < ids.length; i++) {
for (var j = 0; j < industryList.length; j++) {
if (ids[i] == industryList[j].id) {
text += industryList[j].name
}
}
if (i != ids.length -1) {
text += ','
}
}
return '<span>' + text + '</span>'
}
},
{
field: 'templatePhoto',
title: '预览图',
width: '200',
sort: false,
templet: function (data) {
var value='<img style="height: 50px;width: 100px;" src="'+data.templatePreviewPhoto+'"/>';
setTimeout(function() {
new Viewer(document.getElementById('imgShow'));
}, 50);
return value;
}
},
{
field: 'templateWidth',
title: '名片宽度',
width: '150',
sort: false,
},
{
field: 'templateHeight',
title: '名片高度',
width: '150',
sort: false,
},
{
field: 'cardTemplateId',
fixed: 'right',
title:'操作',
width:150,
align: 'center',
templet: function (data) {
return '<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit" lay-filter="edit">编辑名片样式</button>'
}}
]],
done: function (res) {
code = res.count
if (code < 10) {
code = '00' + (code + 1)
}
code = 'C' + (code + 1);
}
})
function getImg(id) {
top.restAjax.get(requestUrl.url + '/app/file/get/' + id, {}, {
headers: {
token: token
}
}, function (res, data) {
var url = requestUrl.url + '/' + data.data.fileUrl
$('.img' + id).attr('src', url)
})
}
table.on('toolbar(cardTable)', function (obj) {
var layEvent = obj.event;
var checkStatus = table.checkStatus('cardTable');
var checkDatas = checkStatus.data;
if (layEvent == 'save') {
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['550px', '650px'], //宽高
content: html
});
$('#uploadBg').on('change', function () {
var file = $(this)[0].files[0]
var formdata = new FormData()
formdata.append('image', file)
var reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = function (e) {
$('#uploadImg').attr('src', this.result)
}
$.ajax({
type: 'post',
url: requestUrl.url + '/app/file/uploadimage',
data: formdata,
async: false,
contentType: false,
processData: false,
headers: {
token: token
},
success: function (res) {
bgImgId = res.data
}
})
})
form.render();
$('#submit-btn').on('click', function () {
// 名片名称
var cardName = $('.card-name').val()
if (!cardName) {
layer.msg('名片名称不能为空')
return
}
// 名片介绍
var cardIntro = $('.card-intro').val()
// 行业
var arr_box = [];
var industry = ''
$('input[type=checkbox]:checked').each(function() {
arr_box.push($(this).val());
});
for (var i = 0; i < arr_box.length; i++) {
if (i < arr_box.length - 1) {
industry += arr_box[i] + '_'
} else {
industry += arr_box[i]
}
}
// 尺寸
var size = $('#card-size').val()
var height
if (size == '500') {
height = '300'
} else if(size == '480'){
height = '480'
}else {
height = '400'
}
if (size == '480') {
size = '600'
}
console.log(size)
// 是否收费
var isPay = $('input[type=radio]:checked').val()
//字体
var font = $('#card-font').val()
// 是否停用
var templateStatus = $('input[name=templateStatus]:checked').val()
var obj = {
templateCode: code,
templateCharge: isPay,
templateDescription: cardIntro,
templateIndustry: industry,
templatePhoto: bgImgId,
templateTitle: cardName,
templateType: '1',
templateWidth: size,
templateHeight: height,
templateTypeface: font,
templateMode: '1',
templateStatus: templateStatus
}
top.restAjax.post(requestUrl.url + '/app/cardtemplate/savecardtemplate', obj, {
headers: {
token: token
}
}, function (res, data) {
layer.msg('新增成功')
setTimeout(function () {
layer.closeAll()
initTable()
}, 1500)
}, function (res, data) {
layer.msg(data.msg)
})
})
} else if (layEvent == 'remove') {
layer.open({
content: '确认删除?',
btn: ['确认', '取消'],
yes: function () {
var ids = ''
for (var i = 0; i < checkDatas.length; i++) {
if (i > 0) {
ids += '_'
}
ids += checkStatus.data[i].cardTemplateId
}
top.restAjax.delete(requestUrl.url + '/app/cardtemplate/removecardtemplate/' + ids, {}, {
headers: {
token: token
}
}, function (res) {
if (res == '200') {
layer.msg('删除成功!')
initTable()
}
})
}
})
} else if (layEvent == 'update') {
if(checkDatas.length === 0) {
layer.msg('请选择要编辑的数据')
} else if(checkDatas.length > 1) {
layer.msg('只能同时编辑一条数据')
} else {
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['550px', '650px'], //宽高
content: updateHtml,
end: function () {
initTable()
innerCount = 0
}
})
getIndustry('update',checkDatas[0].cardTemplateId)
getFont('update',checkDatas[0].cardTemplateId)
top.restAjax.get(requestUrl.url + '/app/file/get/' + checkDatas[0].templatePhoto, {}, {
headers: {
token: token
}
}, function (res, data) {
var url = requestUrl.url + '/' + data.data.fileUrl
$('.bg-img').attr('src', url)
})
$('.update').click(function () {
// 是否停用
var templateStatus = $('input[name=templateStatus]:checked').val()
// 名片名称
var cardName = $('.card-name').val()
// 名片介绍
var cardIntro = $('.card-intro').val()
// 行业
var arr_box = [];
var industry = ''
$('input[name=industry]:checked').each(function() {
arr_box.push($(this).val());
});
for (let i = 0; i < arr_box.length; i++) {
if (i < arr_box.length - 1) {
industry += arr_box[i] + '_'
} else {
industry += arr_box[i]
}
}
// 尺寸
var size = $('#card-size').val()
var height
if (size == '500') {
height = '300'
} else if(size == '480') {
height = '480'
} else {
height = '400'
}
if (size == '480') {
size = '600'
}
// 是否收费
var isPay = $('input[name=pay]:checked').val()
//字体
var font = $('#inner-font').val()
var obj = {
templateCode: cardInfo.templateCode,
templateCharge: isPay,
templateDescription: cardIntro,
templateIndustry: industry,
templatePhoto: cardInfo.templatePhoto,
templateTitle: cardName,
templateType: '1',
templateWidth: size,
templateHeight: height,
templateTypeface: font,
templateMode: '1',
templateStatus: templateStatus
}
top.restAjax.put(requestUrl.url + '/app/cardtemplate/updatecardtemplate/' + checkDatas[0].cardTemplateId, obj, {
headers: {
token: token
}
}, function (res,data) {
layer.closeAll()
layer.msg('修改成功!')
initTable()
})
})
$('.close').click(function () {
layer.closeAll()
})
$('#uploadBg1').on('change', function () {
var file = $(this)[0].files[0]
var formdata = new FormData()
formdata.append('image', file)
var reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = function (e) {
$('.bg-img').attr('src', this.result)
}
$.ajax({
type: 'post',
url: requestUrl.url + '/app/file/uploadimage',
data: formdata,
async: false,
contentType: false,
headers: {
token: token
},
processData: false,
success: function (res) {
cardInfo.templatePhoto = res.data
}
})
})
form.render();
}
}
})
table.on('tool(cardTable)', function (obj) {
var layEvent = obj.event;
if (layEvent == 'edit') {
layer.open({
type: 2,
title: false,
closeBtn: true,
area: ['800px', '500px'],
shadeClose: true,
anim: 2,
content: top.restAjax.path('route/namecard/namecard.html?id=' + obj.data.cardTemplateId, []),
end: function () {
initTable()
}
});
}
})
}
// initTable()
function getIndustry(type,id) {
top.restAjax.get(requestUrl.url + '/app/datadictionary/listztreedictionary?id=567bb081-fa00-4af3-87cf-aa53e2e24010', {}, {
headers: {
token: token
}
}, function (res, data) {
if (type) {
var innerHtml = ''
for (let i = 0; i < data.length; i++) {
innerHtml += '<input type="checkbox" name="industry" lay-skin="primary" title="' + data[i].name + '" value="' + data[i].id + '">'
}
$('.industry-box').html(innerHtml)
innerCount++
if (innerCount == 2) {
getNameCard(id)
}
} else {
industryList = data
for (var i = 0; i < data.length; i++) {
industryHtml += '<input type="checkbox" name="industry" lay-skin="primary" title="' + data[i].name + '" value="' + data[i].id + '">'
}
finishCount++
if (finishCount == 2) {
mergeString()
initTable()
}
}
})
}
getIndustry()
function getFont(type,id) {
top.restAjax.get(requestUrl.url + '/app/datadictionary/listztreedictionary?id=327e3c97-5f02-4840-9569-73f5d2499e48', {}, {
headers: {
token: token
}
}, function (res, data) {
if (type) {
var innerHtml = ''
for (var i = 0; i < data.length; i++) {
innerHtml += '<option value="' + data[i].id + '">' + data[i].name + '</option>'
}
$('#inner-font').html(innerHtml)
innerCount++
if (innerCount == 2) {
getNameCard(id)
}
} else {
for (var i = 0; i < data.length; i++) {
fontHtml += '<option value="' + data[i].id + '">' + data[i].name + '</option>'
}
finishCount++
if (finishCount == 2) {
mergeString()
initTable()
}
}
})
}
getFont()
function mergeString(){
html =
'<form class="layui-form">' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">名片名称</label>' +
'<div class="layui-input-block">' +
'<input type="text" name="identity" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input card-name">' +
'</div>' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">名片介绍</label>' +
'<div class="layui-input-block">' +
'<textarea placeholder="请输入内容" class="layui-textarea card-intro"></textarea>' +
'</div>' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">使用行业</label>' +
'<div class="layui-input-block">' +
industryHtml +
'</div>' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">背景图片</label>' +
'<div class="layui-input-block">' +
'<div class="layui-upload">' +
'<input type="file" id="uploadBg" style="display: none">' +
'<label for="uploadBg" class="layui-btn layui-btn-normal">上传背景图片</label>' +
'<img src="" id="uploadImg" style="width: 100%;margin-top: 10px;">' +
'</div>' +
'</div>' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">名片尺寸</label>' +
'<div class="layui-input-block">' +
'<select name="city" lay-verify="required" id="card-size" lay-filter="card-size">\n' +
'<option value="500">500*300</option>\n' +
'<option value="600">600*400</option>\n' +
'<option value="480">600*480</option>\n' +
'</select>' +
'</div>' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">名片字体</label>' +
'<div class="layui-input-block">' +
'<select name="font" lay-verify="required" id="card-font" lay-filter="card-font">\n' +
fontHtml +
'</select>' +
'</div>' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">模板开关</label>' +
'<div class="layui-input-block">' +
'<input type="radio" name="templateStatus" value="1" title="公开" checked>\n' +
'<input type="radio" name="templateStatus" value="0" title="停用" >\n' +
'</div>' +
'<div class="layui-form-item">' +
'<label class="layui-form-label">是否收费</label>' +
'<div class="layui-input-block">' +
'<input type="radio" name="pay" value="1" title="收费">\n' +
'<input type="radio" name="pay" value="0" title="免费" checked>\n' +
'</div>' +
'</div>' +
'</form>' +
'<button class="layui-btn layui-btn-normal submit-btn" id="submit-btn">确认创建</button>';
}
function getNameCard (id) {
top.restAjax.get(requestUrl.url + '/app/cardtemplate/getcardtemplatebyid/' + id, {}, {
headers: {
token: token
}
}, function (res, data) {
cardInfo = data
$('.bg-img').attr('src',requestUrl.url + '/route/file/download/true/' + data.templatePhoto)
$('.card-name').val(data.templateTitle)
$('.card-intro').val(data.templateDescription)
$('#card-size').val(data.templateWidth)
$('#inner-font').val(data.templateTypeface)
var isPay = $('input[name=pay]')
isPay.each(function () {
if ($(this).val() == data.templateCharge ) {
$(this).attr('checked', 'checked')
}
})
var templateStatus = $('input[name=templateStatus]')
templateStatus.each(function () {
if ($(this).val() == data.templateStatus ) {
$(this).attr('checked', 'checked')
}
})
var industry = $('input[name=industry]')
var selectedIndustry = data.templateIndustry.split('_')
industry.each(function () {
for (let i = 0; i <selectedIndustry.length; i++) {
if ($(this).val() == selectedIndustry[i]) {
$(this).attr('checked', 'checked')
}
}
})
// getBgImg(data.templatePhoto)
form.render()
})
}
var updateHtml = '<div class="layui-fluid">\n' +
' <div class="layui-card">\n' +
' <div class="layui-card-body" style="padding: 15px">\n' +
' <form class="layui-form" lay-filter="dataForm">\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">名片名称 *</label>\n' +
' <div class="layui-input-block">\n' +
' <input type="text" name="dictionaryParentName" class="layui-input card-name">\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">名片介绍 *</label>\n' +
' <div class="layui-input-block">\n' +
' <input type="text" name="dictionaryName" lay-verify="required" placeholder="请输入字典名称" class="layui-input card-intro">\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">使用行业</label>\n' +
' <div class="layui-input-block industry-box"></div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">名片尺寸</label>\n' +
' <div class="layui-input-block">\n' +
' <select name="city" lay-verify="required" id="card-size" lay-filter="card-size">\n' +
' <option value="500">500*300</option>\n' +
' <option value="600">600*400</option>\n' +
' <option value="480">600*480</option>\n' +
' </select>\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">名片字体</label>\n' +
' <div class="layui-input-block">\n' +
' <select name="font" lay-verify="required" id="inner-font" lay-filter="card-font"></select>\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">模板开关</label>\n' +
' <div class="layui-input-block">\n' +
' <input type="radio" name="templateStatus" value="1" title="公开">\n' +
' <input type="radio" name="templateStatus" value="0" title="停用">\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">是否收费</label>\n' +
' <div class="layui-input-block">\n' +
' <input type="radio" name="pay" value="1" title="收费">\n' +
' <input type="radio" name="pay" value="0" title="免费">\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item">\n' +
' <label class="layui-form-label">背景图片</label>\n' +
' <div class="layui-input-block">\n' +
' <input type="file" id="uploadBg1" style="display: none">\n' +
' <img src="" alt="" class="bg-img" style="max-width: 100%">\n' +
' <label for="uploadBg1" style="line-height: 36px">\n' +
' 点击上传\n' +
' </label>\n' +
' </div>\n' +
' </div>\n' +
' <div class="layui-form-item layui-layout-admin">\n' +
' <div class="layui-input-block">\n' +
' <button type="button" class="layui-btn update" lay-submit="" lay-filter="submitForm">提交编辑</button>\n' +
' <button type="button" class="layui-btn layui-btn-primary close">返回上级</button>\n' +
' </div>\n' +
' </div>\n' +
' </form>\n' +
' </div>\n' +
' </div>\n' +
' </div>'
})
</script>
<script type="text/html" id="headerToolBar">
<div class="layui-btn-group">
<button type="button" class="layui-btn layui-btn-sm" lay-event="save">
<i class="fa fa-lg fa-plus"></i>
</button>
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">
<i class="fa fa-lg fa-edit"></i>
</button>
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="remove">
<i class="fa fa-lg fa-trash"></i>
</button>
</div>
</script>