New file |
| | |
| | | package com.zy.crm.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.domain.KeyValueVo; |
| | | import com.zy.crm.common.web.BaseController; |
| | | import com.zy.crm.manager.entity.Reimburse; |
| | | import com.zy.crm.manager.service.ReimburseService; |
| | | import com.zy.crm.system.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | public class ReimburseController extends BaseController { |
| | | |
| | | @Autowired |
| | | private ReimburseService reimburseService; |
| | | |
| | | @RequestMapping(value = "/reimburse/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(reimburseService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/getSheetData/{id}/auth") |
| | | @ManagerAuth |
| | | public String getSheetData(@PathVariable("id") String id) { |
| | | return reimburseService.selectById(String.valueOf(id)).getSheetData(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/list/auth") |
| | | @ManagerAuth |
| | | public R list(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<Reimburse> wrapper = new EntityWrapper<>(); |
| | | wrapper.setSqlSelect("id,title,create_time as createTime,filepath,user_id as userId,status,update_time as updateTime"); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | allLike(Reimburse.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | return R.ok(reimburseService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | String val = String.valueOf(entry.getValue()); |
| | | if (val.contains(RANGE_TIME_LINK)){ |
| | | String[] dates = val.split(RANGE_TIME_LINK); |
| | | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | | } else { |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/add/auth") |
| | | @ManagerAuth |
| | | public R add(@RequestBody Map<String,Object> map) { |
| | | User user = getUser(); |
| | | if(!user.getRoleCode().equals("boss") && !user.getDeptName().equals("核价组")){ |
| | | return R.error("权限不足,禁止新增模板"); |
| | | } |
| | | |
| | | Reimburse reimburse = new Reimburse(); |
| | | reimburse.setTitle(map.get("title").toString()); |
| | | reimburse.setSheetData(map.get("sheetData").toString()); |
| | | reimburse.setCreateTime(new Date()); |
| | | reimburse.setUpdateTime(new Date()); |
| | | reimburse.setUserId(getUserId()); |
| | | reimburse.setStatus(1); |
| | | // if (!pri.getSheetData().isEmpty()) { |
| | | // //保存excel文件 |
| | | // String filepath = ExcelUtils.saveExcelFile(pri.getTitle(), pri.getSheetData()); |
| | | // pri.setFilepath(filepath); |
| | | // } |
| | | reimburseService.insert(reimburse); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/update/auth") |
| | | @ManagerAuth |
| | | public R update(@RequestBody Map<String,Object> map){ |
| | | User user = getUser(); |
| | | if(!user.getRoleCode().equals("boss") && !user.getDeptName().equals("核价组")){ |
| | | return R.error("权限不足,禁止更新模板"); |
| | | } |
| | | |
| | | Reimburse reimburse = reimburseService.selectById(Long.parseLong(map.get("id").toString())); |
| | | reimburse.setTitle(map.get("title").toString()); |
| | | reimburse.setSheetData(map.get("sheetData").toString()); |
| | | reimburse.setUpdateTime(new Date()); |
| | | reimburseService.updateById(reimburse); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/updateStatus/auth") |
| | | @ManagerAuth |
| | | public R update(Long id,Integer status){ |
| | | User user = getUser(); |
| | | if(!user.getRoleCode().equals("boss") && !user.getDeptName().equals("核价组")){ |
| | | return R.error("权限不足,禁止更新模板"); |
| | | } |
| | | |
| | | Reimburse reimburse = reimburseService.selectById(id); |
| | | reimburse.setStatus(status); |
| | | reimburse.setUpdateTime(new Date()); |
| | | reimburseService.updateById(reimburse); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(Long[] ids){ |
| | | User user = getUser(); |
| | | if(!user.getRoleCode().equals("boss") && !user.getDeptName().equals("核价组")){ |
| | | return R.error("权限不足,禁止删除模板"); |
| | | } |
| | | |
| | | if (Cools.isEmpty(ids)){ |
| | | return R.error(); |
| | | } |
| | | reimburseService.deleteBatchIds(Arrays.asList(ids)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/export/auth") |
| | | @ManagerAuth |
| | | public R export(@RequestBody JSONObject param){ |
| | | EntityWrapper<Reimburse> wrapper = new EntityWrapper<>(); |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("pri")); |
| | | convert(map, wrapper); |
| | | List<Reimburse> list = reimburseService.selectList(wrapper); |
| | | return R.ok(exportSupport(list, fields)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburseQuery/auth") |
| | | @ManagerAuth |
| | | public R query(String condition) { |
| | | EntityWrapper<Reimburse> wrapper = new EntityWrapper<>(); |
| | | wrapper.like("id", condition); |
| | | Page<Reimburse> page = reimburseService.selectPage(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (Reimburse pri : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", pri.getId()); |
| | | map.put("value", pri.getTitle()); |
| | | result.add(map); |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburse/check/column/auth") |
| | | @ManagerAuth |
| | | public R query(@RequestBody JSONObject param) { |
| | | Wrapper<Reimburse> wrapper = new EntityWrapper<Reimburse>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); |
| | | if (null != reimburseService.selectOne(wrapper)){ |
| | | return R.parse(BaseRes.REPEAT).add(getComment(Reimburse.class, String.valueOf(param.get("key")))); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping("/reimburse/all/get/kv") |
| | | @ManagerAuth |
| | | public R getDataKV(@RequestParam(required = false) String condition) { |
| | | List<KeyValueVo> vos = new ArrayList<>(); |
| | | Wrapper<Reimburse> wrapper = new EntityWrapper<Reimburse>().andNew().like("id", condition).orderBy("create_time", false); |
| | | reimburseService.selectPage(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | } |
| | |
| | | if (null == this.settle){ return null; } |
| | | switch (this.settle){ |
| | | case 1: |
| | | return "等待组长审核"; |
| | | case 2: |
| | | return "等待部门经理确认"; |
| | | case 3: |
| | | case 2: |
| | | return "等待总裁办审核"; |
| | | case 3: |
| | | return "等待业务员确认"; |
| | | case 4: |
| | | return "审批通过"; |
| | | default: |
New file |
| | |
| | | package com.zy.crm.manager.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import com.core.common.Cools; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.crm.system.entity.User; |
| | | import com.zy.crm.system.service.UserService; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | @TableName("man_reimburse") |
| | | public class Reimburse implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * ID |
| | | */ |
| | | @ApiModelProperty(value= "ID") |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 模板excel的sheet数据 |
| | | */ |
| | | @ApiModelProperty(value= "模板excel的sheet数据") |
| | | @TableField("sheet_data") |
| | | private String sheetData; |
| | | |
| | | /** |
| | | * 模板excel标题 |
| | | */ |
| | | @ApiModelProperty(value= "模板excel标题") |
| | | private String title; |
| | | |
| | | @ApiModelProperty(value= "文件保存地址") |
| | | private String filepath; |
| | | |
| | | @ApiModelProperty(value= "创建人员用户id") |
| | | @TableField("user_id") |
| | | private Long userId; |
| | | |
| | | @ApiModelProperty(value= "状态{0:禁止,1:正常}") |
| | | @TableField("status") |
| | | private Integer status; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @ApiModelProperty(value= "创建时间") |
| | | @TableField("create_time") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | @ApiModelProperty(value= "更新时间") |
| | | @TableField("update_time") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date updateTime; |
| | | |
| | | public Reimburse() {} |
| | | |
| | | public Reimburse(String sheetData, String title, Date createTime, String filepath) { |
| | | this.sheetData = sheetData; |
| | | this.title = title; |
| | | this.createTime = createTime; |
| | | this.filepath = filepath; |
| | | } |
| | | |
| | | // Pri pri = new Pri( |
| | | // null, // 模板excel的sheet数据[非空] |
| | | // null, // 模板excel标题[非空] |
| | | // null // 创建时间 |
| | | // ); |
| | | |
| | | public String getCreateTime$(){ |
| | | if (Cools.isEmpty(this.createTime)){ |
| | | return ""; |
| | | } |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime); |
| | | } |
| | | |
| | | public String getUser$() { |
| | | UserService userService = SpringUtils.getBean(UserService.class); |
| | | User user = userService.selectById(this.userId); |
| | | if (!Cools.isEmpty(user)){ |
| | | return String.valueOf(user.getNickname()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public String getStatus$() { |
| | | if (null == this.status){ return null; } |
| | | switch (this.status){ |
| | | case 1: |
| | | return "正常"; |
| | | case 0: |
| | | return "禁用"; |
| | | default: |
| | | return String.valueOf(this.status); |
| | | } |
| | | } |
| | | |
| | | public String getUpdateTime$(){ |
| | | if (Cools.isEmpty(this.updateTime)){ |
| | | return ""; |
| | | } |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.updateTime); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.crm.manager.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import com.zy.crm.manager.entity.Reimburse; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface ReimburseMapper extends BaseMapper<Reimburse> { |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.crm.manager.service; |
| | | |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | import com.zy.crm.manager.entity.Reimburse; |
| | | |
| | | public interface ReimburseService extends IService<Reimburse> { |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.crm.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.zy.crm.manager.entity.Reimburse; |
| | | import com.zy.crm.manager.mapper.ReimburseMapper; |
| | | import com.zy.crm.manager.service.ReimburseService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service("reimburseService") |
| | | public class ReimburseServiceImpl extends ServiceImpl<ReimburseMapper, Reimburse> implements ReimburseService { |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.zy.crm.manager.mapper.ReimburseMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.zy.crm.manager.entity.Reimburse"> |
| | | <id column="id" property="id" /> |
| | | <result column="sheet_data" property="sheetData" /> |
| | | <result column="title" property="title" /> |
| | | <result column="create_time" property="createTime" /> |
| | | |
| | | </resultMap> |
| | | |
| | | </mapper> |
New file |
| | |
| | | var pageCurr; |
| | | var admin; |
| | | layui.config({ |
| | | base: baseUrl + "/static/layui/lay/modules/" |
| | | }).extend({ |
| | | cascader: 'cascader/cascader', |
| | | }).use(['table','laydate', 'form', 'admin', 'xmSelect', 'element', 'cascader', 'tree', 'dropdown'], function(){ |
| | | var table = layui.table; |
| | | var $ = layui.jquery; |
| | | var layer = layui.layer; |
| | | var layDate = layui.laydate; |
| | | var form = layui.form; |
| | | admin = layui.admin; |
| | | |
| | | // 数据渲染 |
| | | tableIns = table.render({ |
| | | elem: '#reimburse', |
| | | headers: {token: localStorage.getItem('token')}, |
| | | url: baseUrl+'/reimburse/list/auth', |
| | | page: true, |
| | | limit: 16, |
| | | limits: [16, 30, 50, 100, 200, 500], |
| | | toolbar: '#toolbar', |
| | | cellMinWidth: 150, |
| | | cols: [[ |
| | | {type: 'checkbox', fixed: 'left'} |
| | | ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80} |
| | | ,{field: 'title', align: 'center',title: '模板名'} |
| | | ,{field: 'createTime$', align: 'center',title: '创建时间'} |
| | | ,{field: 'updateTime$', align: 'center',title: '更新时间'} |
| | | ,{field: 'user$', align: 'center',title: '创建人员'} |
| | | ,{field: 'status$', align: 'center',title: '状态'} |
| | | ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:220} |
| | | ]], |
| | | request: { |
| | | pageName: 'curr', |
| | | pageSize: 'limit' |
| | | }, |
| | | parseData: function (res) { |
| | | return { |
| | | 'code': res.code, |
| | | 'msg': res.msg, |
| | | 'count': res.data.total, |
| | | 'data': res.data.records |
| | | } |
| | | }, |
| | | response: { |
| | | statusCode: 200 |
| | | }, |
| | | done: function(res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } |
| | | pageCurr=curr; |
| | | limit(); |
| | | } |
| | | }); |
| | | |
| | | // 监听排序事件 |
| | | table.on('sort(reimburse)', function (obj) { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | searchData[this.name] = this.value; |
| | | }); |
| | | searchData['orderByField'] = obj.field; |
| | | searchData['orderByType'] = obj.type; |
| | | tableIns.reload({ |
| | | where: searchData, |
| | | page: { |
| | | curr: 1 |
| | | }, |
| | | done: function (res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } |
| | | pageCurr=curr; |
| | | limit(); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | // 监听头工具栏事件 |
| | | table.on('toolbar(reimburse)', function (obj) { |
| | | var checkStatus = table.checkStatus(obj.config.id); |
| | | switch(obj.event) { |
| | | case 'addData': |
| | | layer.open({ |
| | | type: 2, |
| | | title: '新增', |
| | | maxmin: true, |
| | | area: [top.detailWidth, top.detailHeight], |
| | | shadeClose: false, |
| | | content: 'reimburse_template.html', |
| | | success: function(layero, index){ |
| | | // layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); |
| | | } |
| | | }); |
| | | break; |
| | | case 'refreshData': |
| | | tableIns.reload({ |
| | | page: { |
| | | curr: pageCurr |
| | | } |
| | | }); |
| | | limit(); |
| | | break; |
| | | case 'deleteData': |
| | | var data = checkStatus.data; |
| | | var ids=[]; |
| | | data.map(function (track) { |
| | | ids.push(track.id); |
| | | }); |
| | | if (ids.length === 0){ |
| | | layer.msg('请选择数据'); |
| | | } else { |
| | | layer.confirm('确定删除'+(ids.length===1?'此':ids.length)+'条数据吗', function(){ |
| | | $.ajax({ |
| | | url: baseUrl+"/reimburse/delete/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: {ids: ids}, |
| | | method: 'POST', |
| | | traditional:true, |
| | | success: function (res) { |
| | | if (res.code === 200){ |
| | | layer.closeAll(); |
| | | tableReload(false); |
| | | } else if (res.code === 403){ |
| | | top.location.href = baseUrl+"/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }) |
| | | }); |
| | | } |
| | | break; |
| | | case 'exportData': |
| | | layer.confirm('确定导出Excel吗', {shadeClose: true}, function(){ |
| | | var titles=[]; |
| | | var fields=[]; |
| | | obj.config.cols[0].map(function (col) { |
| | | if (col.type === 'normal' && col.hide === false && col.toolbar == null) { |
| | | titles.push(col.title); |
| | | fields.push(col.field); |
| | | } |
| | | }); |
| | | var exportData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | exportData[this.name] = this.value; |
| | | }); |
| | | var param = { |
| | | 'config': exportData, |
| | | 'fields': fields |
| | | }; |
| | | $.ajax({ |
| | | url: baseUrl+"/reimburse/export/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify(param), |
| | | dataType:'json', |
| | | contentType:'application/json;charset=UTF-8', |
| | | method: 'POST', |
| | | success: function (res) { |
| | | layer.closeAll(); |
| | | if (res.code === 200) { |
| | | table.exportFile(titles,res.data,'xls'); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | // 监听行工具事件 |
| | | table.on('tool(reimburse)', function(obj){ |
| | | var data = obj.data; |
| | | switch (obj.event) { |
| | | // 编辑 |
| | | case 'edit': |
| | | layer.open({ |
| | | type: 2, |
| | | title: '修改', |
| | | maxmin: true, |
| | | area: [top.detailWidth, top.detailHeight], |
| | | shadeClose: false, |
| | | content: 'reimburse_template.html?id=' + data.id, |
| | | success: function(layero, index){ |
| | | // layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); |
| | | } |
| | | }); |
| | | break; |
| | | case 'use': |
| | | showEditModel(data.id,data.title); |
| | | break; |
| | | case 'status': |
| | | showEditStatus(data); |
| | | break; |
| | | case 'del': |
| | | layer.confirm('确定删除这条数据吗', function(){ |
| | | $.ajax({ |
| | | url: baseUrl+"/reimburse/delete/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: {ids: data.id}, |
| | | method: 'POST', |
| | | traditional:true, |
| | | success: function (res) { |
| | | if (res.code === 200){ |
| | | layer.closeAll(); |
| | | tableReload(false); |
| | | } else if (res.code === 403){ |
| | | top.location.href = baseUrl+"/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }) |
| | | }); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | //更新状态 |
| | | function showEditStatus(mData) { |
| | | admin.open({ |
| | | type: 1, |
| | | area: '800px', |
| | | title: '模板状态', |
| | | content: $('#editStatus').html(), |
| | | success: function (layero, dIndex) { |
| | | form.val('editStatusDetail', mData); |
| | | form.render('select') |
| | | form.on('submit(editSubmit)', function (data) { |
| | | var loadIndex = layer.load(2); |
| | | $.ajax({ |
| | | url: baseUrl+"/reimburse/updateStatus/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: { |
| | | id: data.field.id, |
| | | status: data.field.status |
| | | }, |
| | | method: 'POST', |
| | | traditional:true, |
| | | success: function (res) { |
| | | if (res.code === 200){ |
| | | layer.closeAll(); |
| | | tableReload(false); |
| | | } else if (res.code === 403){ |
| | | top.location.href = baseUrl+"/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }) |
| | | layer.close(loadIndex); |
| | | layer.close(dIndex); |
| | | return false; |
| | | }); |
| | | $(layero).children('.layui-layer-content').css('overflow', 'visible'); |
| | | layui.form.render('select'); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /* 弹窗 - 新增、修改 */ |
| | | function showEditModel(id,title) { |
| | | admin.open({ |
| | | type: 1, |
| | | area: '800px', |
| | | title: '使用核价模板', |
| | | content: $('#editDialog').html(), |
| | | success: function (layero, dIndex) { |
| | | form.on('submit(editSubmit)', function (data) { |
| | | var loadIndex = layer.load(2); |
| | | layer.close(loadIndex); |
| | | layer.close(dIndex); |
| | | layer.open({ |
| | | type: 2, |
| | | title: '使用模板', |
| | | maxmin: true, |
| | | area: [top.detailWidth, top.detailHeight], |
| | | shadeClose: false, |
| | | content: 'reimburse_use.html?id=' + id + '&item_id=' + data.field.itemId + "&title=" + title, |
| | | success: function(layero, index){ |
| | | // layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); |
| | | } |
| | | }); |
| | | return false; |
| | | }); |
| | | $(layero).children('.layui-layer-content').css('overflow', 'visible'); |
| | | layui.form.render('select'); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | |
| | | // 关闭动作 |
| | | $(document).on('click','#data-detail-close', function () { |
| | | parent.layer.closeAll(); |
| | | }); |
| | | |
| | | function tableReload(child) { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | searchData[this.name] = this.value; |
| | | }); |
| | | (child ? parent.tableIns : tableIns).reload({ |
| | | where: searchData, |
| | | page: { |
| | | curr: pageCurr |
| | | }, |
| | | done: function (res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } |
| | | pageCurr=curr; |
| | | if (res.data.length === 0 && count !== 0) { |
| | | tableIns.reload({ |
| | | where: searchData, |
| | | page: { |
| | | curr: pageCurr-1 |
| | | } |
| | | }); |
| | | pageCurr -= 1; |
| | | } |
| | | limit(child); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | function setFormVal(el, data, showImg) { |
| | | for (var val in data) { |
| | | var find = el.find(":input[id='" + val + "']"); |
| | | find.val(data[val]); |
| | | if (showImg){ |
| | | var next = find.next(); |
| | | if (next.get(0)){ |
| | | if (next.get(0).localName === "img") { |
| | | find.hide(); |
| | | next.attr("src", data[val]); |
| | | next.show(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | function clearFormVal(el) { |
| | | $(':input', el) |
| | | .val('') |
| | | .removeAttr('checked') |
| | | .removeAttr('selected'); |
| | | } |
| | | |
| | | function detailScreen(index) { |
| | | var detail = layer.getChildFrame('#data-detail', index); |
| | | var height = detail.height()+60; |
| | | if (height > ($(window).height()*0.9)) { |
| | | height = ($(window).height()*0.9); |
| | | } |
| | | layer.style(index, { |
| | | top: (($(window).height()-height)/3)+"px", |
| | | height: height+'px' |
| | | }); |
| | | $(".layui-layer-shade").remove(); |
| | | } |
| | | |
| | | $('body').keydown(function () { |
| | | if (event.keyCode === 13) { |
| | | $("#search").click(); |
| | | } |
| | | }); |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html lang="en"> |
| | | <head> |
| | | <meta charset="utf-8"> |
| | | <title></title> |
| | | <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, maximum-scale=1"> |
| | | <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all"> |
| | | <link rel="stylesheet" href="../../static/css/admin.css?v=318" media="all"> |
| | | <link rel="stylesheet" href="../../static/css/cool.css" media="all"> |
| | | </head> |
| | | <body> |
| | | |
| | | <div class="layui-fluid"> |
| | | <div class="layui-card"> |
| | | <div class="layui-card-body"> |
| | | |
| | | <table class="layui-hide" id="reimburse" lay-filter="reimburse"></table> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <script type="text/html" id="toolbar"> |
| | | <div class="layui-btn-container"> |
| | | <button class="layui-btn layui-btn-sm" lay-event="addData">新增</button> |
| | | <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="deleteData">删除</button> |
| | | </div> |
| | | </script> |
| | | |
| | | <script type="text/html" id="operate"> |
| | | <a class="layui-btn layui-btn-xs btn-edit" lay-event="edit">模板</a> |
| | | <a class="layui-btn layui-btn-primary layui-btn-xs btn-edit" lay-event="use">使用</a> |
| | | <a class="layui-btn layui-btn-primary layui-btn-xs btn-edit" lay-event="status">状态</a> |
| | | <a class="layui-btn layui-btn-danger layui-btn-xs btn-edit" lay-event="del">删除</a> |
| | | </script> |
| | | |
| | | <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script> |
| | | <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/reimburse/reimburse.js" charset="utf-8"></script> |
| | | <!-- 表单弹窗 --> |
| | | <script type="text/html" id="editDialog"> |
| | | <div id="detail" lay-filter="detail" class="layui-form admin-form model-form"> |
| | | <input name="id" type="hidden"> |
| | | <div class="layui-row"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label layui-form-required">项目名: </label> |
| | | <div class="layui-input-block cool-auto-complete"> |
| | | <input class="layui-input" name="itemId" placeholder="请输入项目名" style="display: none" lay-verify="required"> |
| | | <input id="itemId$" name="itemId$" class="layui-input cool-auto-complete-div" onclick="autoShow(this.id)" type="text" placeholder="请输入项目名" onfocus=this.blur()> |
| | | <div class="cool-auto-complete-window"> |
| | | <input class="cool-auto-complete-window-input" data-key="itemQueryBydirector" onkeyup="autoLoad(this.getAttribute('data-key'))"> |
| | | <select class="cool-auto-complete-window-select" data-key="itemQueryBydirectorSelect" onchange="confirmed(this.getAttribute('data-key'))" multiple="multiple"> |
| | | </select> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <hr class="layui-bg-gray"> |
| | | <div class="layui-form-item text-right"> |
| | | <button class="layui-btn" lay-filter="editSubmit" lay-submit="">保存</button> |
| | | <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button> |
| | | </div> |
| | | </div> |
| | | </script> |
| | | |
| | | <!-- 表单弹窗 --> |
| | | <script type="text/html" id="editStatus"> |
| | | <div id="editStatusDetail" lay-filter="editStatusDetail" class="layui-form admin-form model-form"> |
| | | <input name="id" type="hidden"> |
| | | <div class="layui-row"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label layui-form-required">状态: </label> |
| | | <div class="layui-input-block"> |
| | | <select name="status" lay-vertype="tips" lay-verify="required"> |
| | | <option value="">请选择状态</option> |
| | | <option value="1">正常</option> |
| | | <option value="0">禁止</option> |
| | | </select> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <hr class="layui-bg-gray"> |
| | | <div class="layui-form-item text-right"> |
| | | <button class="layui-btn" lay-filter="editSubmit" lay-submit="">保存</button> |
| | | <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button> |
| | | </div> |
| | | </div> |
| | | </script> |
| | | </body> |
| | | </html> |
| | | |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html> |
| | | <head> |
| | | <meta charset="utf-8"> |
| | | <title>excel</title> |
| | | <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all"> |
| | | <link rel='stylesheet' href='../../static/plugins/css/pluginsCss.css' /> |
| | | <link rel='stylesheet' href='../../static/plugins/plugins.css' /> |
| | | <link rel='stylesheet' href='../../static/css/luckysheet.css' /> |
| | | <link rel='stylesheet' href='../../static/assets/iconfont/iconfont.css' /> |
| | | <script src="../../static/js/luckysheet_js/plugin.js"></script> |
| | | <script src="../../static/js/luckysheet_js/luckysheet.umd.js"></script> |
| | | <script src="../../static/js/luckysheet_js/luckyexcel.umd.js"></script> |
| | | <script src="../../static/js/luckysheet_js/exceljs.min.js"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/export.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/pako.es5.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/base64.min.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/print.min.js" charset="utf-8"></script> |
| | | </head> |
| | | <body> |
| | | <div style="display: flex;position: absolute;top: 20px;left:30px;z-index: 9999;"> |
| | | <!-- <div><button type="button" id="export">导出Execel</button></div>--> |
| | | <div> |
| | | <input type="file" style="display: none;" id="uploadFile"> |
| | | <button type="button" class="layui-btn layui-btn-xs" id="upload-button"> |
| | | <i class="layui-icon"></i>上传模板 |
| | | </button> |
| | | </div> |
| | | <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="save">保存</button></div> |
| | | <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="allprint">全部打印</button></div> |
| | | <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="print">选区打印</button></div> |
| | | </div> |
| | | <div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height: 100vh;left: 0px;top: 0px;"></div> |
| | | <script> |
| | | $(function () { |
| | | var layer = layui.layer; |
| | | |
| | | //配置项 |
| | | var options = { |
| | | container: 'luckysheet' ,//luckysheet为容器id |
| | | title: '核价模板', //工作簿名称 |
| | | lang: 'zh', //设定表格语言 国际化设置,允许设置表格的语言,支持中文("zh")和英文("en") |
| | | allowEdit: true, //是否允许前台编辑 |
| | | sheetFormulaBar: true, //是否显示公式栏 |
| | | forceCalculation: true,//强制计算公式 |
| | | myFolderUrl: '' //左上角<返回按钮的链接 |
| | | } |
| | | |
| | | if(getUrlParams('id') == false){ |
| | | //新增 |
| | | luckysheet.create(options) |
| | | $("#luckysheet_info_detail_update").hide() |
| | | $("#luckysheet_info_detail_save").hide() |
| | | $("#luckysheet_info_detail_title").hide() |
| | | }else{ |
| | | //修改 |
| | | $.ajax({ |
| | | type:"get", |
| | | url: baseUrl + "/reimburse/" + getUrlParams('id') + "/auth", |
| | | dataType:"json", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | success:function(res) { |
| | | options.data = unzip(res.data.sheetData) |
| | | options.title = res.data.title |
| | | luckysheet.create(options) |
| | | $("#luckysheet_info_detail_update").hide() |
| | | $("#luckysheet_info_detail_save").hide() |
| | | $("#luckysheet_info_detail_title").hide() |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | //点击上传 |
| | | $("#upload-button").on("click",() => { |
| | | $("#uploadFile").click() |
| | | }) |
| | | |
| | | //响应上传 |
| | | $("#uploadFile").on("change",(evt) => { |
| | | var files = evt.target.files; |
| | | if(files==null || files.length==0){ |
| | | alert("No files wait for import"); |
| | | return; |
| | | } |
| | | |
| | | let name = files[0].name; |
| | | let suffixArr = name.split("."), suffix = suffixArr[suffixArr.length-1]; |
| | | if(suffix!="xlsx"){ |
| | | alert("Currently only supports the import of xlsx files"); |
| | | return; |
| | | } |
| | | LuckyExcel.transformExcelToLucky(files[0], function(exportJson, luckysheetfile){ |
| | | |
| | | if(exportJson.sheets==null || exportJson.sheets.length==0){ |
| | | alert("Failed to read the content of the excel file, currently does not support xls files!"); |
| | | return; |
| | | } |
| | | window.luckysheet.destroy(); |
| | | |
| | | window.luckysheet.create({ |
| | | container: 'luckysheet', //luckysheet is the container id |
| | | data:exportJson.sheets, |
| | | title:exportJson.info.name, |
| | | userInfo:exportJson.info.name.creator, |
| | | lang: 'zh', //设定表格语言 国际化设置,允许设置表格的语言,支持中文("zh")和英文("en") |
| | | allowEdit: true, //是否允许前台编辑 |
| | | sheetFormulaBar: true, //是否显示公式栏 |
| | | forceCalculation: true,//强制计算公式 |
| | | }); |
| | | }); |
| | | }) |
| | | |
| | | $("#export").on("click",() => { |
| | | console.log('export') |
| | | exportExcel(luckysheet.getluckysheetfile()).then((e) => { |
| | | saveFile(e,'file'); |
| | | }) |
| | | }) |
| | | |
| | | //保存到服务器 |
| | | $("#save").on("click",async () => { |
| | | if (getUrlParams('id') == false) { |
| | | //新增 |
| | | $.ajax({ |
| | | url: baseUrl + "/reimburse/add/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify({ |
| | | title: luckysheet.toJson().title, |
| | | sheetData: zip(luckysheet.getAllSheets()) |
| | | }), |
| | | method: 'POST', |
| | | dataType: "json", |
| | | contentType:'application/json;charset=UTF-8', |
| | | success: function (res) { |
| | | if (res.code == 200) { |
| | | layer.msg('保存成功', {time: 1000}, () => { |
| | | parent.location.reload() |
| | | }) |
| | | } else { |
| | | layer.msg(res.msg, {time: 1000}) |
| | | } |
| | | } |
| | | }); |
| | | } else { |
| | | //修改 |
| | | $.ajax({ |
| | | url: baseUrl + "/reimburse/update/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify({ |
| | | id: getUrlParams('id'), |
| | | title: luckysheet.toJson().title, |
| | | sheetData: zip(luckysheet.getAllSheets()) |
| | | }), |
| | | method: 'POST', |
| | | dataType: "json", |
| | | contentType:'application/json;charset=UTF-8', |
| | | success: function (res) { |
| | | if (res.code == 200) { |
| | | layer.msg('保存成功', {time: 1000}, () => { |
| | | parent.location.reload() |
| | | }) |
| | | } else { |
| | | layer.msg(res.msg, {time: 1000}) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | }) |
| | | |
| | | $("#allprint").on("click",() => { |
| | | printExcel() |
| | | }) |
| | | |
| | | $("#print").on("click",() => { |
| | | let src = luckysheet.getScreenshot(); // 生成base64图片 |
| | | const style = '@page {margin:0 10mm};' |
| | | printJS({ |
| | | printable: src, |
| | | type: 'image', |
| | | style: style |
| | | }) // Print.js插件 |
| | | }) |
| | | |
| | | // 获取表格中包含内容的row,column |
| | | function getExcelRowColumn() { |
| | | const sheetData = luckysheet.getSheetData(); |
| | | let objRowColumn = { |
| | | row: [null, null], //行 |
| | | column: [null, null], //列 |
| | | }; |
| | | sheetData.forEach((item, index) => { |
| | | //行数 |
| | | item.forEach((it, itemIndex) => { |
| | | if (it !== null) { |
| | | if (objRowColumn.row[0] == null) objRowColumn.row[0] = index; // row第一位 |
| | | objRowColumn.row[1] = index; //row第二位 |
| | | if (objRowColumn.column[0] == null) |
| | | objRowColumn.column[0] = itemIndex; //column第一位 |
| | | objRowColumn.column[1] = itemIndex; //column第二位 |
| | | } |
| | | }); |
| | | }); |
| | | return objRowColumn; |
| | | } |
| | | |
| | | function printExcel() { |
| | | let RowColumn = this.getExcelRowColumn() // 获取有值的行和列 |
| | | RowColumn.column[0] = 0 //因需要打印左边的边框,需重新设置 |
| | | luckysheet.setRangeShow(RowColumn) // 进行选区操作 |
| | | let src = luckysheet.getScreenshot(); // 生成base64图片 |
| | | const style = '@page {margin:0 10mm};' |
| | | printJS({ |
| | | printable: src, |
| | | type: 'image', |
| | | style: style |
| | | }) // Print.js插件 |
| | | } |
| | | |
| | | function getUrlParams(name) { |
| | | var url = window.location.search; |
| | | if (url.indexOf('?') == -1) { return false; } |
| | | url = url.substr(1); |
| | | url = url.split('&'); |
| | | var name = name || ''; |
| | | var nameres; |
| | | for (var i = 0; i < url.length; i++) { |
| | | var info = url[i].split('='); |
| | | var obj = {}; |
| | | obj[info[0]] = decodeURI(info[1]); |
| | | url[i] = obj; |
| | | } |
| | | if (name) { |
| | | for (var i = 0; i < url.length; i++) { |
| | | for (var key in url[i]) { |
| | | if (key == name) { |
| | | nameres = url[i][key]; |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | nameres = url; |
| | | } |
| | | return nameres; |
| | | } |
| | | |
| | | // 压缩 |
| | | function zip(data) { |
| | | if (!data) return data |
| | | // 判断数据是否需要转为JSON |
| | | const dataJson = typeof data !== 'string' && typeof data !== 'number' ? JSON.stringify(data) : data |
| | | |
| | | // 使用Base64.encode处理字符编码,兼容中文 |
| | | const str = Base64.encode(dataJson) |
| | | let binaryString = pako.gzip(str); |
| | | let arr = Array.from(binaryString); |
| | | let s = ""; |
| | | arr.forEach((item, index) => { |
| | | s += String.fromCharCode(item) |
| | | }) |
| | | return btoa(s) |
| | | } |
| | | |
| | | // 解压 |
| | | function unzip(b64Data) { |
| | | let strData = atob(b64Data); |
| | | let charData = strData.split('').map(function (x) { |
| | | return x.charCodeAt(0); |
| | | }); |
| | | let binData = new Uint8Array(charData); |
| | | let data = pako.ungzip(binData); |
| | | |
| | | // ↓切片处理数据,防止内存溢出报错↓ |
| | | let str = ''; |
| | | const chunk = 8 * 1024 |
| | | let i; |
| | | for (i = 0; i < data.length / chunk; i++) { |
| | | str += String.fromCharCode.apply(null, data.slice(i * chunk, (i + 1) * chunk)); |
| | | } |
| | | str += String.fromCharCode.apply(null, data.slice(i * chunk)); |
| | | // ↑切片处理数据,防止内存溢出报错↑ |
| | | |
| | | const unzipStr = Base64.decode(str); |
| | | let result = '' |
| | | |
| | | // 对象或数组进行JSON转换 |
| | | try { |
| | | result = JSON.parse(unzipStr) |
| | | } catch (error) { |
| | | if (/Unexpected token o in JSON at position 0/.test(error)) { |
| | | // 如果没有转换成功,代表值为基本数据,直接赋值 |
| | | result = unzipStr |
| | | } |
| | | } |
| | | return result |
| | | } |
| | | |
| | | </script> |
| | | </body> |
| | | </html> |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html> |
| | | <head> |
| | | <meta charset="utf-8"> |
| | | <title>execel</title> |
| | | <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all"> |
| | | <link rel='stylesheet' href='../../static/plugins/css/pluginsCss.css' /> |
| | | <link rel='stylesheet' href='../../static/plugins/plugins.css' /> |
| | | <link rel='stylesheet' href='../../static/css/luckysheet.css' /> |
| | | <link rel='stylesheet' href='../../static/assets/iconfont/iconfont.css' /> |
| | | <script src="../../static/js/luckysheet_js/plugin.js"></script> |
| | | <script src="../../static/js/luckysheet_js/luckysheet.umd.js"></script> |
| | | <script src="../../static/js/luckysheet_js/luckyexcel.umd.js"></script> |
| | | <script src="../../static/js/luckysheet_js/exceljs.min.js"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/export.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/pako.es5.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/base64.min.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/luckysheet_js/print.min.js" charset="utf-8"></script> |
| | | </head> |
| | | <body> |
| | | <div style="display: flex;position: absolute;top: 20px;left:30px;z-index: 9999;"> |
| | | <!-- <div>上传Execel:<input type="file" id="Luckyexcel-demo-file" /></div>--> |
| | | <!-- <div><button type="button" id="export">导出Execel</button></div>--> |
| | | <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="save">保存</button></div> |
| | | <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="allprint">全部打印</button></div> |
| | | <div><button type="button" class="layui-btn layui-btn-primary layui-btn-xs btn-edit" id="print">选区打印</button></div> |
| | | </div> |
| | | <div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height: 100vh;left: 0px;top: 0px;"></div> |
| | | <script> |
| | | $(function () { |
| | | var layer = layui.layer; |
| | | |
| | | //配置项 |
| | | var options = { |
| | | container: 'luckysheet' ,//luckysheet为容器id |
| | | title: 'Excel表格DEMO', //工作簿名称 |
| | | lang: 'zh', //设定表格语言 国际化设置,允许设置表格的语言,支持中文("zh")和英文("en") |
| | | allowEdit: true, //是否允许前台编辑 |
| | | sheetFormulaBar: true, //是否显示公式栏 |
| | | forceCalculation: true,//强制计算公式 |
| | | myFolderUrl: '' //左上角<返回按钮的链接 |
| | | } |
| | | |
| | | if(getUrlParams('id') == false || getUrlParams('id') == undefined){ |
| | | //新增 |
| | | luckysheet.create(options) |
| | | $("#luckysheet_info_detail_update").hide() |
| | | $("#luckysheet_info_detail_save").hide() |
| | | $("#luckysheet_info_detail_title").hide() |
| | | }else{ |
| | | //修改 |
| | | $.ajax({ |
| | | type:"get", |
| | | url: baseUrl + "/reimburse/" + getUrlParams('id') + "/auth", |
| | | dataType:"json", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | success:function(res) { |
| | | options.data = unzip(res.data.sheetData) |
| | | options.title = res.data.title |
| | | luckysheet.create(options) |
| | | $("#luckysheet_info_detail_update").hide() |
| | | $("#luckysheet_info_detail_save").hide() |
| | | $("#luckysheet_info_detail_title").hide() |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | $("#Luckyexcel-demo-file").on("change",(evt) => { |
| | | var files = evt.target.files; |
| | | if(files==null || files.length==0){ |
| | | alert("No files wait for import"); |
| | | return; |
| | | } |
| | | |
| | | let name = files[0].name; |
| | | let suffixArr = name.split("."), suffix = suffixArr[suffixArr.length-1]; |
| | | if(suffix!="xlsx"){ |
| | | alert("Currently only supports the import of xlsx files"); |
| | | return; |
| | | } |
| | | LuckyExcel.transformExcelToLucky(files[0], function(exportJson, luckysheetfile){ |
| | | |
| | | if(exportJson.sheets==null || exportJson.sheets.length==0){ |
| | | alert("Failed to read the content of the excel file, currently does not support xls files!"); |
| | | return; |
| | | } |
| | | window.luckysheet.destroy(); |
| | | |
| | | window.luckysheet.create({ |
| | | container: 'luckysheet', //luckysheet is the container id |
| | | data:exportJson.sheets, |
| | | title:exportJson.info.name, |
| | | userInfo:exportJson.info.name.creator, |
| | | lang: 'zh', //设定表格语言 国际化设置,允许设置表格的语言,支持中文("zh")和英文("en") |
| | | allowEdit: true, //是否允许前台编辑 |
| | | sheetFormulaBar: true, //是否显示公式栏 |
| | | forceCalculation: true,//强制计算公式 |
| | | }); |
| | | }); |
| | | }) |
| | | |
| | | $("#export").on("click",() => { |
| | | console.log('export') |
| | | exportExcel(luckysheet.getluckysheetfile()).then((e) => { |
| | | saveFile(e,'file'); |
| | | }) |
| | | }) |
| | | |
| | | //保存到服务器 |
| | | $("#save").on("click",() => { |
| | | //需要压缩数据再上传 |
| | | $.ajax({ |
| | | url: baseUrl + "/reimburseOnline/add/auth", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify({ |
| | | title: getUrlParams('title'), |
| | | sheetData: zip(luckysheet.getAllSheets()), |
| | | itemId: getUrlParams('item_id'), |
| | | priId: getUrlParams('id') |
| | | }), |
| | | method: 'POST', |
| | | dataType: "json", |
| | | contentType:'application/json;charset=UTF-8', |
| | | success: function (res) { |
| | | if (res.code == 200) { |
| | | layer.msg('保存成功',{time:1000},() => { |
| | | parent.location.reload() |
| | | }) |
| | | }else{ |
| | | layer.msg(res.msg,{time:1000}) |
| | | } |
| | | } |
| | | }) |
| | | }) |
| | | |
| | | }) |
| | | |
| | | $("#allprint").on("click",() => { |
| | | printExcel() |
| | | }) |
| | | |
| | | $("#print").on("click",() => { |
| | | let src = luckysheet.getScreenshot(); // 生成base64图片 |
| | | const style = '@page {margin:0 10mm};' |
| | | printJS({ |
| | | printable: src, |
| | | type: 'image', |
| | | style: style |
| | | }) // Print.js插件 |
| | | }) |
| | | |
| | | // 获取表格中包含内容的row,column |
| | | function getExcelRowColumn() { |
| | | const sheetData = luckysheet.getSheetData(); |
| | | let objRowColumn = { |
| | | row: [null, null], //行 |
| | | column: [null, null], //列 |
| | | }; |
| | | sheetData.forEach((item, index) => { |
| | | //行数 |
| | | item.forEach((it, itemIndex) => { |
| | | if (it !== null) { |
| | | if (objRowColumn.row[0] == null) objRowColumn.row[0] = index; // row第一位 |
| | | objRowColumn.row[1] = index; //row第二位 |
| | | if (objRowColumn.column[0] == null) |
| | | objRowColumn.column[0] = itemIndex; //column第一位 |
| | | objRowColumn.column[1] = itemIndex; //column第二位 |
| | | } |
| | | }); |
| | | }); |
| | | return objRowColumn; |
| | | } |
| | | |
| | | function printExcel() { |
| | | let RowColumn = this.getExcelRowColumn() // 获取有值的行和列 |
| | | RowColumn.column[0] = 0 //因需要打印左边的边框,需重新设置 |
| | | luckysheet.setRangeShow(RowColumn) // 进行选区操作 |
| | | let src = luckysheet.getScreenshot(); // 生成base64图片 |
| | | const style = '@page {margin:0 10mm};' |
| | | printJS({ |
| | | printable: src, |
| | | type: 'image', |
| | | style: style |
| | | }) // Print.js插件 |
| | | } |
| | | |
| | | function getUrlParams(name) { |
| | | var url = window.location.search; |
| | | if (url.indexOf('?') == -1) { return false; } |
| | | url = url.substr(1); |
| | | url = url.split('&'); |
| | | var name = name || ''; |
| | | var nameres; |
| | | for (var i = 0; i < url.length; i++) { |
| | | var info = url[i].split('='); |
| | | var obj = {}; |
| | | obj[info[0]] = decodeURI(info[1]); |
| | | url[i] = obj; |
| | | } |
| | | if (name) { |
| | | for (var i = 0; i < url.length; i++) { |
| | | for (var key in url[i]) { |
| | | if (key == name) { |
| | | nameres = url[i][key]; |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | nameres = url; |
| | | } |
| | | return nameres; |
| | | } |
| | | |
| | | // 压缩 |
| | | function zip(data) { |
| | | if (!data) return data |
| | | // 判断数据是否需要转为JSON |
| | | const dataJson = typeof data !== 'string' && typeof data !== 'number' ? JSON.stringify(data) : data |
| | | |
| | | // 使用Base64.encode处理字符编码,兼容中文 |
| | | const str = Base64.encode(dataJson) |
| | | let binaryString = pako.gzip(str); |
| | | let arr = Array.from(binaryString); |
| | | let s = ""; |
| | | arr.forEach((item, index) => { |
| | | s += String.fromCharCode(item) |
| | | }) |
| | | return btoa(s) |
| | | } |
| | | |
| | | // 解压 |
| | | function unzip(b64Data) { |
| | | let strData = atob(b64Data); |
| | | let charData = strData.split('').map(function (x) { |
| | | return x.charCodeAt(0); |
| | | }); |
| | | let binData = new Uint8Array(charData); |
| | | let data = pako.ungzip(binData); |
| | | |
| | | // ↓切片处理数据,防止内存溢出报错↓ |
| | | let str = ''; |
| | | const chunk = 8 * 1024 |
| | | let i; |
| | | for (i = 0; i < data.length / chunk; i++) { |
| | | str += String.fromCharCode.apply(null, data.slice(i * chunk, (i + 1) * chunk)); |
| | | } |
| | | str += String.fromCharCode.apply(null, data.slice(i * chunk)); |
| | | // ↑切片处理数据,防止内存溢出报错↑ |
| | | |
| | | const unzipStr = Base64.decode(str); |
| | | let result = '' |
| | | |
| | | // 对象或数组进行JSON转换 |
| | | try { |
| | | result = JSON.parse(unzipStr) |
| | | } catch (error) { |
| | | if (/Unexpected token o in JSON at position 0/.test(error)) { |
| | | // 如果没有转换成功,代表值为基本数据,直接赋值 |
| | | result = unzipStr |
| | | } |
| | | } |
| | | return result |
| | | } |
| | | </script> |
| | | </body> |
| | | </html> |