<title>月份统计</title>

<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">
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
			<div class="layui-form-item">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<div class="layui-input-inline">
							<input type="text" name="month" class="layui-input" placeholder="月份" id="create" autocomplete="off">
						</div>
					</div>
				</div>
				<div class="layui-inline">
					<div class="layui-input-inline">
						<script type="text/html" template lay-url="{{ layui.setter.apidomain }}yyds/user/index" lay-done="layui.data.done(d);">
						<select name="uid">
							<option value="">录单人</option>
							{{# layui.each(d.data, function(index, item){ }}
							<option value="{{item.id}}">{{item.username}}</option>
							{{# }) }}
						</select>
						</script>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-data-front-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<table id="LAY-data-month" lay-filter="LAY-data-month"></table>
			<script type="text/html" id="table-useradmin-webuser">
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">详情</a>
			</script>
		</div>
	</div>
</div>

<script>
	layui.data.done = function(d){
		classifyData = d.data;
		layui.use('form', function(){
			var form = layui.form;
			form.render('select');
		});
	};
	layui.use(['table', 'laydate', 'layer'], function() {
		var $ = layui.$,
			admin = layui.admin,
			setter = layui.setter,
			view = layui.view,
			table = layui.table,
			laydate = layui.laydate,
			layer = layui.layer,
			form = layui.form;

		//监听搜索
		form.on('submit(LAY-data-front-search)', function(data) {
			var field = data.field;

			//执行重载
			table.reload('LAY-data-month', {
				where: field
			});
		});

		laydate.render({
			elem: '#create',
			type: 'month'
		});

		//事件
		var active = {
			detail: function() {
				admin.popup({
					title: '详情',
					area: ['500px', '450px'],
					id: 'LAY-month-person',
					success: function(layero, index) {
						view(this.id).render('statistics/months/person_list').done(function() {

						});
					}
				});
			}
		};

		$('.layui-btn.layuiadmin-btn-useradmin').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		var rr = setter.request.tokenName,
			tt = setter.tableName;
		//订单列表
		table.render({
			elem: '#LAY-data-month',
			url: setter.apidomain + 'yyds/order/month',
			headers: {
				jtoken: layui.data(tt)[rr]
			},
			cols: [
				[{
					field: 'month',
					title: '月份'
				}, {
					field: 'nums',
					title: '订单数',
					sort: true
				}, {
					field: 'aprice',
					title: '订单总金额',
					sort: true
				}, {
					field: 'dprice',
					title: '剩余尾款总金额',
					sort: true
				}, {
					title: '操作',
					align: 'center',
					fixed: 'right',
					toolbar: '#table-useradmin-webuser'
				}]
			],
			page: false,
			toolbar: true
		});

		table.on('tool(LAY-data-month)', function(obj) {
			if (obj.event == 'detail') {
				console.log(obj);
				layer.open({
					type: 1,
					title: '详情',
					content: '<div style="padding: 15px;"><table id="LAY-month-person" lay-filter="LAY-month-person"></table></div>',
					area: ['800px', '600px'],
					success: function() {
						//订单列表
						table.render({
							elem: '#LAY-month-person',
							url: setter.apidomain + 'yyds/order/month',
							where: {detail: 1, month: obj.data.month},
							headers: {
								jtoken: layui.data(tt)[rr]
							},
							cols: [
								[{
									field: 'uname',
									title: '姓名',
									sort: true
								}, {
									field: 'nums',
									title: '订单数',
									sort: true
								}, {
									field: 'aprice',
									title: '订单总金额',
									sort: true
								}, {
									field: 'dprice',
									title: '剩余尾款总金额',
									sort: true
								}]
							],
							page: false,
							limit: 20,
							limits: [20, 50, 100, 1000],
							toolbar: true
						});
					}
				})
			}
		})
	});
</script>
