279 lines
10 KiB
HTML

{extend name="common/base"/}
{block name="style"}
<style>
.layui-table-min th{font-size:13px; text-align:center; background-color:#f8f8f8;}
.layui-table-min td{font-size:13px; padding:6px;text-align:center;}
</style>
<link rel="stylesheet" href="{__JS__}/module/dtree/dtree.css">
<link rel="stylesheet" href="{__JS__}/module/dtree/font/dtreefont.css">
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form body-content">
<h3>报销信息</h3>
{if condition="($id == 0)"}
<table class="layui-table">
<tr>
<td class="layui-td-gray2">报销凭证编号<span style="color: red">*</span></td>
<td>
<input type="text" name="code" autocomplete="off" lay-verify="required" placeholder="报销凭证编号" lay-reqText="请填写报销凭证编号" class="layui-input" value="">
</td>
<td class="layui-td-gray">入账月份<span style="color: red">*</span></td>
<td>
<input type="text" class="layui-input" id="income_month" name="income_month" lay-verify="required" placeholder="请选择入账月份" lay-reqText="请选择入账月份" readonly value="">
</td>
<td class="layui-td-gray2">原始单据日期<span style="color: red">*</span></td>
<td>
<input type="text" class="layui-input" id="expense_time" name="expense_time" lay-verify="required" placeholder="请选择原始单据日期" lay-reqText="请选择原始单据日期" readonly value="">
</td>
</tr>
<tr>
<td class="layui-td-gray2">报销人<span style="color: red">*</span></td>
<td>
<input type="text" name="name" placeholder="请选择报销人" readonly class="layui-input" lay-verify="required" lay-reqText="请选择报销人" value="{$user.name}" readonly>
<input type="hidden" name="uid" autocomplete="off" class="layui-input" value="{$user.id}">
</td>
<td class="layui-td-gray">报销部门</td>
<td>
<input type="text" name="department" readonly class="layui-input" value="{$user.department}" readonly>
<input type="hidden" name="did" autocomplete="off" class="layui-input" value="{$user.did}">
</td>
</tr>
<tr>
<td class="layui-td-gray2">费用金额<span style="color: red">*</span><button class="layui-btn layui-btn-normal layui-btn-sm" type="button" id="addInterfix">+报销选项</button></td>
<td colspan="5">
<div>
<table id="interfix" class="layui-table layui-table-min">
<tr>
<th width="200">报销金额</th>
<th width="300">报销项目</th>
<th>备注信息</th>
<th width="100">操作</th>
</tr>
<tr class="more_interfix">
<td><input type="text" name="amount[]" value="" class="layui-input" lay-verify="required|number" lay-reqText="请完善报销金额"></td>
<td style="text-align:left">
<select name="cate_id[]" lay-verify="required" lay-reqText="请选择报销项目">
<option value="">请选择</option>
{volist name="$expense_cate" id="vo"}
<option value="{$vo.id}">{$vo.title}</option>
{/volist}
</select>
</td>
<td><input type="text" name="remarks[]" class="layui-input" value=""><input type="hidden" name="expense_id[]" class="layui-input" value="0"></td>
<td><a class="layui-btn layui-btn-danger layui-btn-xs" data-id="0" lay-event="del">删除</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
{else/}
<table class="layui-table">
<tr>
<td class="layui-td-gray2">报销凭证编号<span style="color: red">*</span></td>
<td>
<input type="text" name="code" autocomplete="off" lay-verify="required" placeholder="报销凭证编号" lay-reqText="请填写报销凭证编号" class="layui-input" value="{$expense.code}">
</td>
<td class="layui-td-gray">入账月份<span style="color: red">*</span></td>
<td>
<input type="text" class="layui-input" id="income_month" name="income_month" lay-verify="required" placeholder="请选择入账月份" lay-reqText="请选择入账月份" readonly value="{$expense.income_month}">
</td>
<td class="layui-td-gray2">原始单据日期<span style="color: red">*</span></td>
<td>
<input type="text" class="layui-input" id="expense_time" name="expense_time" lay-verify="required" placeholder="请选择原始单据日期" lay-reqText="请选择原始单据日期" readonly value="{$expense.expense_time}">
</td>
</tr>
<tr>
<td class="layui-td-gray2">报销人<span style="color: red">*</span></td>
<td>
<input type="text" name="name" placeholder="请选择报销人" readonly class="layui-input" lay-verify="required" lay-reqText="请选择报销人" value="{$expense.user_name}" readonly>
<input type="hidden" name="uid" autocomplete="off" class="layui-input" value="{$expense.uid}">
</td>
<td class="layui-td-gray">报销部门</td>
<td>
<input type="text" name="department" readonly class="layui-input" value="{$expense.department}" readonly>
<input type="hidden" name="did" autocomplete="off" class="layui-input" value="{$expense.did}">
</td>
</tr>
<tr>
<td class="layui-td-gray2">费用金额<span style="color: red">*</span><button class="layui-btn layui-btn-normal layui-btn-sm" type="button" id="addInterfix">+报销选项</button></td>
<td colspan="5">
<div>
<table id="interfix" class="layui-table layui-table-min">
<tr>
<th width="200">报销金额</th>
<th width="300">报销类别</th>
<th>备注信息</th>
<th width="100">操作</th>
</tr>
{volist name="$expense.list" id="val"}
<tr class="more_interfix">
<td><input type="text" name="amount[]" value="{$val.amount}" class="layui-input" lay-verify="required|number" lay-reqText="请完善报销金额"></td>
<td style="text-align:left">
<select name="cate_id[]" lay-verify="required" lay-reqText="请选择报销项目">
<option value="">请选择</option>
{volist name="$expense_cate" id="vo"}
<option value="{$vo.id}" {eq name="$vo.id" value="$val.cate_id"} selected{/eq}>{$vo.title}</option>
{/volist}
</select>
</td>
<td><input type="text" name="remarks[]" class="layui-input" value="{$val.remarks}"><input type="hidden" name="expense_id[]" class="layui-input" value="{$val.id}"></td>
<td><a class="layui-btn layui-btn-danger layui-btn-xs" data-id="{$val.id}" lay-event="del">删除</a></td>
</tr>
{/volist}
</table>
</div>
</td>
</tr>
</table>
{/if}
<div class="layui-form-item" style="padding-top:10px;">
<input name="id" id="id" type="hidden" value="{$id}">
<button class="layui-btn" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
<div id="selectTem" style="display:none;">
<select name="cate_id[]" lay-verify="required" lay-reqText="请选择报销项目">
<option value="">请选择</option>
{volist name="$expense_cate" id="vo"}
<option value="{$vo.id}">{$vo.title}</option>
{/volist}
</select>
</div>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
function init(layui){
var form = layui.form
,layer = layui.layer
,table = layui.table
,employeepicker = layui.employeepicker//很重要
,laydate = layui.laydate;
laydate.render({
elem: '#income_month',
type:'month',
showBottom: false
});
laydate.render({
elem: '#expense_time',
max:0,
showBottom: false
});
// 选择员工
$('.body-content').on('click','[name="name"]',function(){
var that = $(this);
var names = that.val(), ids = $('[name="uid"]').val();
employeepicker.init({
ids: ids,
names: names,
type: 0,
department_url:"{:url('/home/api/get_department_tree')}",
employee_url:"{:url('/home/api/get_employee')}",
callback: function (ids, names, dids, departments) {
$('[name="uid"]').val(ids);
$('[name="did"]').val(dids);
$('[name="department"]').val(departments);
that.val(names);
}
})
});
//监听提交
form.on('submit(webform)', function(data){
var interfix = $('.more_interfix');
if(interfix.length <1 ){
layer.msg('至少要保留一个报销选项');
return false;
}
$.ajax({
url:"{:url('/home/expense/post_submit')}",
type:'post',
data:data.field,
success:function(e){
layer.msg(e.msg);
if(e.code==0){
parent.location.reload();
}
}
})
return false;
});
//添加报销信息表格
$('#addInterfix').on('click',function(){
var html = '';
var selectTem=$('#selectTem').html();
html += '<tr class="more_interfix">\
<td><input type="text" name="amount[]" class="layui-input" lay-verify="required|number" lay-reqText="请完善报销金额"></td>\
<td style="text-align:left">'+selectTem+'</td>\
<td><input type="text" name="remarks[]" class="layui-input"><input type="hidden" name="expense_id[]" class="layui-input" value="0"></td>\
<td><a class="layui-btn layui-btn-danger layui-btn-xs" data-id="0" lay-event="del">删除</a></td>\
</tr>';
$("#interfix").append(html).find('.tr-none').remove();
form.render();
});
$('#interfix').on('click', '[lay-event="del"]', function() {
if($('.more_interfix').length<2){
layer.msg('至少保留一个报销选项');
return false;
}
var that=$(this);
var _id = that.data('id');
if(_id>0){
layer.confirm('确定删除该报销数据项?', {
icon: 3,
title: '提示'
}, function(index) {
$.ajax({
url: "{:url('home/api/del_expense_interfix')}",
data: {
id: _id
},
success: function(res) {
layer.msg(res.msg);
if (res.code == 0) {
that.parents(".more_interfix").remove();
}
}
})
layer.close(index);
});
}
else{
that.parents(".more_interfix").remove();
}
});
//报销成员修改
$('[name="nickname"]').on('click',function() {
var that=$(this);
var ids=that.next().val(),names=that.val();
employeepicker.init({
ids:ids,
names:names,
type:0,
callback:function(ids,names,dids,departments){
that.val(names);
that.next().val(ids);
$('[name="department"]').val(departments);
$('[name="did"]').val(dids);
}
});
});
}
</script>
{include file="common/layui" base='base' extend="['employeepicker']" callback="init" /}
{/block}
<!-- /脚本 -->