<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<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.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="XMGL_YWCXM_YWCXM_T" html='<a href="${ctx}/accountMagement/accountDetail/detailListPage"><li class="layui-this">总资产明细</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询</button>
            </ul>
        </div>
        <form class="layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">产品编号：</label>
                    <div class="layui-input-block" >
                        <select name="projectCode" id="projectId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${projectList}" var="project">
                                <option value="${project.columns.id}">${project.columns.code}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">产品名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="projectName" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站编码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="traderName" id="traderName" class="layui-input" autocomplete="off">
                    </div>
                </div>


                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">代理商名称：</label>
                        <div class="layui-input-block" >
                            <input type="text" name="powerStationCode" id="powerStationCode" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">代理商电话：</label>
                        <div class="layui-input-block">
                            <input type="text" name="traderMobile" class="layui-input" autocomplete="off">
                        </div>
                    </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">业主姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="tenantName" id="tenantName" class="layui-input" autocomplete="off">
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">联系方式：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" id="mobile" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站状态：</label>
                    <div class="layui-input-block" >
                        <select name="status">
                            <option value="">请选择</option>
                          <%--  <option value="0">暂存</option>
                            <option value="1">待审核</option>
                            <option value="2">审核驳回</option>
                            <option value="3">待下单</option>
                            <option value="4">待收货</option>
                            <option value="5">待安装</option>
                            <option value="6">待并网</option>
                            <option value="7">待验收</option>
                            <option value="10">验收驳回</option>--%>
                            <option value="8">待交付</option>
                            <option value="9">待归档</option>
                            <option value="11">归档驳回</option>
                            <option value="a">已完成</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">屋顶类型：</label>
                    <div class="layui-input-block" >
                        <select name="roofType" id="roofType">
                            <option value="">请选择</option>
                            <option value="平屋顶">平屋顶</option>
                            <option value="斜屋顶">斜屋顶</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" id="remarks" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">划转方式：</label>
                    <div class="layui-input-block" >
                        <select name="repaymentMethod" id="repaymentMethod">
                            <option value="">请选择</option>
                            <option value="1">二类卡</option>
                            <option value="2">光E宝</option>
                            <option value="0">其它</option>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">审核备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="examineRemarks" id="examineRemarks" class="layui-input" >
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">方案名称：</label>
                    <div class="layui-input-block" >
                        <select name="plan" id="flag">
                            <option value="">请选择</option>
                            <c:forEach items="${plans}" var="plan">
                                <option value="${plan.columns.id}">${plan.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">审核时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="matchTimeMin" class="layui-input pointer" readonly id="examineTimeStartTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="matchTimeMax" class="layui-input pointer" readonly id="examineTimeEndTime" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" id="addBtn" lay-event="addGe"><i class="layui-icon layui-icon-add-1"></i>批量导入 </button>
                    <sfTags:pagePermission authFlag="XMGL_XMGD_XMGD_DC_B" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出</button>'/>
                </div>
            </script>
        </div>
    </div>
</div>
<!-- 电站编码 -->
<script type="text/html" id="stationCodeTpl">
    <a href="#" class="layui-table-link" onclick="psDetail('{{d.id}}')">{{d.power_station_code}}</a>
</script>
<!-- 验收报告 -->
<script type="text/html" id="reportTpl">
    <a href="#" class="layui-table-link" onclick="downloadReport('{{d.id}}')">查看</a>
</script>
<!-- 发票 -->
<script type="text/html" id="billTpl">
    {{#if(!isBlank(d.bill)){    }}
    <a href="#" class="layui-table-opt-link" lay-event="viewBill">查看</a>
    {{#}    }}
</script>
<!-- 合同 -->
<script type="text/html" id="contractTpl">
    {{#if(!isBlank(d.contract)){    }}
    <a href="#" class="layui-table-opt-link" lay-event="viewContract">查看</a>
    {{#}    }}
</script>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>

    var entrycount=0;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        //开始日期
        var endStartTime = laydate.render({
            elem: '#examineTimeStartTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#examineTimeEndTime'
            ,done: function(value, date){
            }
        });

        tableExt.render({
            elem: '#test'
            , title:'总资产明细'
            , height: 'full-220'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/accountMagement/accountDetail/ajaxForWaitOrder'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',rowspan:'2' , fixed: 'left'}
                , {field: 'power_station_code', title: '电站编码',minWidth: 200, sort: false, align: 'center', fixed: 'left',exportable:true, templet: '#stationCodeTpl'}

                , {field: 'scheme_type',title: '设计方案',minWidth: 100,sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        return d.scheme_type === '1'? '标准方案': d.scheme_type === '2'? '组合方案': '';
                    },expFormat: function (d) {
                        return d.scheme_type === '1'? '标准方案': d.scheme_type === '2'? '组合方案': '';
                    }
                }
                , {field: 'planName',title: '方案名称',minWidth: 150,sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        if (d.scheme_type === '1') {
                            if (isBlank(d.scheme_id)) {
                                return '——';
                            }
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\'' + d.id + '\')">' + d.planName + '</a>';
                        } else if (isBlank(d.planName)) {
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\'' + d.id + '\')">查看方案</a>';
                        } else {
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\'' + d.id + '\')">' + d.planName + '</a>';
                        }
                    }
                },{field: 'bill',title: '发票',minWidth: 100,sort: false,align: 'center',exportable: false,templet: '#billTpl'}
                 ,{field: 'contract',title: '购售电合同',minWidth: 100,sort: false,align: 'center',exportable: false,templet: '#contractTpl'}
                , {field: 'scheme_id',title: '验收报告',minWidth: 100,sort: false,align: 'center',exportable: false,templet: '#reportTpl'}
                , {field: 'remarks', title: '备注',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'projectCode', title: '产品编号',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'projectName', title: '产品名称',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'traderName', title: '代理商名称',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'traderMobile', title: '代理商电话',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'tenant_name', title: '业主姓名',minWidth: 150, sort: false, align: 'center', exportable:true}
                , {field: 'mobile', title: '联系方式',minWidth: 130, sort: false, align: 'center', exportable:true}
                , {field: 'id_code', title: '身份证号',minWidth: 180, sort: false, align: 'center', exportable:true}
                , {field: 'roof_type', title: '屋顶类型',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'address', title: '安装地址',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'distance', title: '并网距离（米）',minWidth: 180, sort: false, align: 'center',exportable:true}
                , {field: 'azimuth',title: '方位角',minWidth: 130,sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        if (d.azimuth === '1') {
                            return '正南';
                        }
                        if (d.azimuth === '2') {
                            return '南偏东';
                        }
                        if (d.azimuth === '3') {
                            return '南偏西';
                        }
                        return '';
                    },expFormat: function (d) {
                        if (d.azimuth === '1') {
                            return '正南';
                        }
                        if (d.azimuth === '2') {
                            return '南偏东';
                        }
                        if (d.azimuth === '3') {
                            return '南偏西';
                        }
                        return '';
                    }
                }
                , {field: 'building_height', title: '建筑高度（米）',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'shoot_type',title: '拍摄方式',minWidth: 130,sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        if (d.shoot_type === '1') {
                            return '无人机拍摄';
                        }
                        if (d.shoot_type === '2') {
                            return '手机拍摄';
                        }
                        return '';
                    },expFormat: function (d) {
                        if (d.shoot_type === '1') {
                            return '无人机拍摄';
                        }
                        if (d.shoot_type === '2') {
                            return '手机拍摄';
                        }
                        return '';
                    }
                },{field: 'repayment_method',title: '划转方式',minWidth: 130,sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        if (d.repayment_method === '1') {
                            return '二类卡';
                        }else if(d.repayment_method === '2') {
                            return '光E宝';
                        }else if(d.repayment_method === '0'){
                            return '其它';
                        }
                        return '';
                    },expFormat: function (d) {
                        if (d.repayment_method === '1') {
                            return '二类卡';
                        }else if(d.repayment_method === '2') {
                            return '光E宝';
                        }else if(d.repayment_method === '0'){
                            return '其它';
                        }
                        return '';
                    }
                }
                , {field: 'create_time', title: '登记时间',minWidth: 180, sort: false, align: 'center',exportable:true}
               /* , {field: 'to_examine_time', title: '提交时间',minWidth: 180, sort: false, align: 'center',exportable:true}*/
                , {field: 'examine_time', title: '审核时间',minWidth: 180, sort: false, align: 'center',exportable:true}
                , {field: 'examine_remarks', title: '审核备注',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'totalAccount', title: '资产',minWidth: 130, sort: false, align: 'center',exportable:true}   //资产计算公式：资产=电站总安装容量*每W定价 两个值均来源于第一次进件审核通过后的【装机容量】与【每W定价】
                , {field: 'etd', title: '当期新增发电量',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'eto', title: '累计发电量',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'etdc', title: '当期新增发电收入',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'etoc', title: '累计发电收入',minWidth: 130, sort: false, align: 'center',exportable:true}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '总资产明细',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '总资产明细',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            },done: function(res, curr, count){
                //得到数据总量
                entrycount = count;
            }
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            debugger
            if (layEvent === 'viewContract') {
                window.open('${commonStaticImgPath}' + data.contract)
            } else if (layEvent === 'viewGdsContract') {
                window.open('${commonStaticImgPath}' + data.gsd_contract)
            } else if (layEvent === 'secEntryApply') {
                //二次进件申请
                preInputEntry(data.id)
            }else if(layEvent === 'viewBill'){
                window.open('${commonStaticImgPath}' + data.bill)
            }  else if (layEvent === 'sureAccept') {
                //验收
                layer.open({
                    type: 2,
                    title: '验收报告',
                    content: '${ctx}/customerEntry/toMergeAccept?opt=mergeAccept&id=' + data.id,
                    area: ['80%', '80%']
                });
            }
        });

        table.on('toolbar(test)',function(obj) {
            if (obj.event === 'addGe') {
                layer.open({
                    title: '批量导入',
                    type: 2,
                    area: ['550px', '300px'],
                    content: '${ctx}/accountMagement/accountDetail/toImportCustomerEntryGe'
                });
            }
        });


        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page:{
                    curr:1
                },done: function (res, curr, count) {
                    entrycount = count;
                    console.log("zongshu ::" +
                        ""+entrycount)
                }
            });
        });


        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });
    })

    function downloadReport(id){
        layer.open({
            type: 2,
            title: '验收报告',
            content: '${ctx}/customerEntry/toMergeAccept?opt=view&id=' + id,
            area: ['80%','80%']
        });
    }

    function downloadAttach(attach){
        attach=decodeURI(attach);
        attach = attach.replace(/\+/g,"%2B"); //
        window.location.href = '${commonStaticImgPath}' + attach;
    }

    function searchOrder() {
        //执行重载
        table.reload('test', {
            where: function (){
                return _serializeJson($("#searchForm"));
            }
        });
    }

    //查看详情
    function psDetail(id){
        layer.open({
            type: 2
            , title: '电站详情'
            , content: '${ctx}/customerEntry/entryDetail?entryId=' + id
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }

    function planDetail(entryId){
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/planManage/viewMatchedPlan?entryId=' + entryId,
            area: ['80%','80%']
        });
    }

    function downloadImg(attach) {
        var name = attach.substring(0, attach.lastIndexOf(".") - 1);
        var suffix = attach.substring(attach.lastIndexOf("."));
        window.open('${commonStaticImgPath}'+attach)
        //  location.href = '${ctx}/technical/imgDownload?path=' + '${commonStaticImgPath}' + attach + "&fileGS=" + suffix + "&name=" + name;
    }

    function inDoc(id){

    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>


