<%@ 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}/lib/font/iconfont.css" />
    <style>
        @font-face {
            font-family: 'iconfont';
            src: url('${ctxPlugin}/lib/font/iconfont.eot');
            src: url('${ctxPlugin}/lib/font/iconfont.eot?#iefix') format('embedded-opentype'),
            url('${ctxPlugin}/lib/font/iconfont.woff2') format('woff2'),
            url('${ctxPlugin}/lib/font/iconfont.woff') format('woff'),
            url('${ctxPlugin}/lib/font/iconfont.ttf') format('truetype'),
            url('${ctxPlugin}/lib/font/iconfont.svg#iconfont') format('svg');
        }
        .iconfont {
            font-family: "iconfont" !important;
            font-size: 16px;
            font-style: normal;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
    </style>
</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="XTSZ_XMXXSZ_T" html='<a href="${ctx}/sysSettings/projectInfoSetting/index"><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 " lay-submit lay-filter="LAY-user-back-search" data-type="reload">
                  <i class="layui-icon fs-12">&#xe615;</i>
                  查询
              </button>
          </ul>
      </div>
      <div class="layui-card-body" id="searchForm">
          <div class="layui-form-item">
              <div class="layui-col-lg2 layui-col-sm2">
                  <label class="layui-form-label">产品编号：</label>
                  <div class="layui-input-block">
                      <input type="text" name="code" id="code" autocomplete="off" class="layui-input">
                  </div>
              </div>
              <div class="layui-col-lg2 layui-col-sm2">
                  <label class="layui-form-label">产品名称：</label>
                  <div class="layui-input-block">
                      <input type="text" name="name" id="name" autocomplete="off" class="layui-input">
                  </div>
              </div>
<%--              <div class="layui-col-lg3 layui-col-sm3">--%>
<%--                  <label class="layui-form-label">项目公司：</label>--%>
<%--                  <div class="layui-input-block">--%>
<%--                      <select name="projectCompanyId" >--%>
<%--                          <option value="">请选择</option>--%>
<%--                          <c:forEach items="${company}" var="company">--%>
<%--                              <option value="${company.columns.id}" >${company.columns.name}</option>--%>
<%--                          </c:forEach>--%>
<%--                      </select>--%>
<%--                  </div>--%>
<%--              </div>--%>
              <div class="layui-col-lg2 layui-col-sm2">
                  <label class="layui-form-label">所属产品线：</label>
                  <div class="layui-input-block">
                      <select name="productLineId" >
                          <option value="">请选择</option>
                          <c:forEach items="${productLine}" var="productLine">
                              <option value="${productLine.columns.id}" >${productLine.columns.name}</option>
                          </c:forEach>
                      </select>
                  </div>
              </div>
              <div class="layui-col-lg3 layui-col-sm3">
                  <label class="layui-form-label">所属资方：</label>
                  <div class="layui-input-block">
                      <select name="partnerId" >
                          <option value="">请选择</option>
                          <c:forEach items="${partnerList}" var="partner">
                              <option value="${partner.id}" >${partner.name}</option>
                          </c:forEach>
                      </select>
                  </div>
              </div>
              <div class="layui-col-lg2 layui-col-sm2">
                  <label class="layui-form-label">状态：</label>
                  <div class="layui-input-block">
                      <select name="status" >
                          <option value="">请选择</option>
                          <option value="0">已启用</option>
                          <option value="2">已停用</option>
                      </select>
                  </div>
              </div>
          </div>

      </div>
  </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">
                    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_ADD_B" html='<button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
                    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_DRCP_B" html=' <button class="layui-btn layui-btn-sm" lay-event="importProjectInfo"><i class="layui-icon layui-icon-export"></i>导入产品</button>'/>
                    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_DRCS_B" html=' <button class="layui-btn layui-btn-sm" lay-event="importProjectInfoParameter"><i class="layui-icon layui-icon-export"></i>导入参数</button>'/>
                   <%-- <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_EDIT_B" html='<button class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>'/>
                    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_DELETE_B" html='<button class="layui-btn layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>'/>--%>
                </div>
            </script>
        </div>
    </div>

</div>

<script type="text/html" id="table-toolbar">

    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_LOOK_B" html='<a href="#" class="layui-table-link" lay-event="look">查看</a>'/>
    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_EDIT_B" html='<a href="#" class="layui-table-link" lay-event="edit">编辑</a>'/>
    {{# if(d.status == '0'){ }}
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_JY_B" html='<a class="layui-table-opt-link" lay-event="disabled">禁用</a>'/>
    {{# }else if(d.status == '2'){ }}
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_QY_B" html='<a class="layui-table-opt-link" lay-event="canUse">启用</a>'/>
    {{# } }}
    <sfTags:pagePermission authFlag="XTSZ_XMXXSZ_XMXXSZ_DELETE_B" html='<a href="#" class="layui-table-link" lay-event="del">删除</a>'/>
</script>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/font/iconfont.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer','laydate','form'], function(){
        $ = layui.$;
        table = layui.table;
        layer = layui.layer;
        laypage = layui.laypage;
        var  form = layui.form;

        table.render({
            elem: '#test',
            height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , method:"post"
            , url: '${ctx}/sysSettings/projectInfoSetting/ajaxForList'
            , cols: [[
                {type: 'numbers',title:'序号'}
                , {field: 'id', type: 'checkbox'}
                , {field: 'code', title: '产品编号', sort: false, align: 'center'}
                , {field: 'name', title: '产品名称', align: 'center'}
                , {field: 'productLineName', title: '所属产品线', align: 'center'}
                , {field: 'partnerName', title: '所属资方',minWidth: 230, align: 'center'}
                , {field: 'attribute', title: '业务属性', align: 'center'
                    , templet: function(d){
                        if(d.attribute == '1'){
                            return '纯租25年业务';
                        }else if(d.attribute == '2'){
                            return '经营性租赁';
                        }else if(d.attribute == '3'){
                            return '融资租赁';
                        }else if(d.attribute == '4'){
                            return '光伏贷';
                        }else if(d.attribute == '5'){
                            return '全款';
                        }else if(d.attribute == '6'){
                            return '其它';
                        }
                        return '';
                    }}
                // , {field: 'companyName', title: '所属项目公司', align: 'center'}
                , {field: 'epc_price', title: 'EPC单价', align: 'center'}
                , {field: 'pay_cycle', title: '租金支付周期', align: 'center'
                    , templet: function(d){
                        if(d.pay_cycle == '1'){
                            return '按月支付';
                        }else if(d.pay_cycle == '2'){
                            return '按季支付';
                        }else if(d.pay_cycle == '3'){
                            return '按年支付';
                        }
                        return '';
                    }}
                // , {field: 'id', title: '租金设置', align: 'center'
                //    ,templet:function(d){
                //         if(d.attribute == '1'){
                //             return '<a href="#" class="layui-table-link" onclick="lookVariables(\''+d.id+'\')">查看</a>';
                //         }else{
                //             return '--';
                //         }
                //
                //     }
                // }
                , {field: 'create_time', title: '创建时间', sort: false, align: 'center'}
                ,{field:'processId', title: '操作',toolbar: '#table-toolbar',align: 'center',minWidth: 130}
            ]]
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            //var count = obj.config.page.count;  开启分页后又用
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'importProjectInfo':
                    layer.open({
                        type: 2,
                        title:"导入产品",
                        resize:false,
                        area: ['40%', '43%'],
                        content: '${ctx}/sysSettings/projectInfoSetting/importProjectInfoForm'
                    });
                    break;
                case 'importProjectInfoParameter':
                    layer.open({
                        type: 2,
                        title:"导入参数",
                        resize:false,
                        area: ['40%', '43%'],
                        content: '${ctx}/sysSettings/projectInfoSetting/importProjectInfoParameter'
                    });
                    break;
                case 'add':
                    layer.open({
                        type: 2
                        ,title: '新增'
                        ,content: '${ctx}/sysSettings/projectInfoSetting/toAdd'
                        ,area: ['90%','100%']
                        ,success : function(layero) {
                            layero.find('.layui-layer-btn').css('text-align', 'center');
                            layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                        }
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var id = data.id;
            switch(obj.event){
                case 'look':
                    layer.open({
                        type: 2
                        ,title: '详情'
                        , content: '${ctx}/sysSettings/projectInfoSetting/projectInfoDetail?id=' +id
                        ,area: ['90%','100%']
                        ,success : function(layero) {
                            layero.find('.layui-layer-btn').css('text-align', 'center');
                            layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                        }
                    });
                    break;
                case 'edit':
                    layer.open({
                        type: 2
                        ,title: '编辑'
                        , content: '${ctx}/sysSettings/projectInfoSetting/toAdd?id=' +id
                        ,area: ['90%','100%']
                        ,success : function(layero) {
                            layero.find('.layui-layer-btn').css('text-align', 'center');
                            layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                        }
                    });
                    break;
                case 'disabled':
                    layer.confirm('确定禁用？',{
                        btn: ['确定', '取消'],
                        success: function (layero, index) {
                            this.enterEsc = function (event) {
                                if (event.keyCode == 13 ) {
                                    //确认  执行的代码
                                    changeStatus(id,'2');
                                  //  console.log("id------------->",id)
                                    //关闭弹窗
                                    layer.close(index);
                                    console.log("回车确认时事件")
                                    //取消连续回车键，导致不断弹出询问框
                                    $(':focus').blur();
                                }
                            };
                            //监听键盘事件
                            $(document).on('keydown', this.enterEsc);
                            //esc键触发取消
                            this.escQuit = (ev) => {
                                let code_val = ev.which;
                                if(code_val == 0x1B){
                                    $('.layui-layer-btn1').click();
                                    return false;
                                }
                            };
                            $(document).on('keydown', this.escQuit);
                        },
                        end: function () {
                            //取消键盘监听事件
                            $(document).off('keydown', this.enterEsc);
                            $(document).off('keydown', this.escQuit);
                        },
                        yes: function () {
                            //确认执行的代码
                            changeStatus(id,'2');
                        },
                        no: function () {

                        }
                    });
                    break;
                case 'canUse':
                    layer.confirm('确认启用？',{
                        btn: ['确定', '取消'],
                        success: function (layero, index) {
                            this.enterEsc = function (event) {
                                if (event.keyCode == 13 ) {
                                    //确认  执行的代码
                                    changeStatus(id,'0');
                                    //关闭弹窗
                                    layer.close(index);
                                    console.log("回车确认时事件")
                                    //取消连续回车键，导致不断弹出询问框
                                    $(':focus').blur();
                                }
                            };
                            //监听键盘事件
                            $(document).on('keydown', this.enterEsc);
                            //esc键触发取消
                            this.escQuit = (ev) => {
                                let code_val = ev.which;
                                if(code_val == 0x1B){
                                    $('.layui-layer-btn1').click();
                                    return false;
                                }
                            };
                            $(document).on('keydown', this.escQuit);
                        },
                        end: function () {
                            //取消键盘监听事件
                            $(document).off('keydown', this.enterEsc);
                            $(document).off('keydown', this.escQuit);
                        },
                        yes: function () {
                            //确认执行的代码
                            changeStatus(id,'0');
                        },
                        no: function () {

                        }
                    });
                    break
                case 'del':
                    layer.confirm('确认要删除选中数据吗？',{
                        btn: ['确定', '取消'],
                        success: function (layero, index) {
                            this.enterEsc = function (event) {
                                if (event.keyCode == 13 ) {
                                    //确认  执行的代码
                                    delData(id);
                                    //关闭弹窗
                                    layer.close(index);
                                    console.log("回车确认时事件")
                                    //取消连续回车键，导致不断弹出询问框
                                    $(':focus').blur();
                                }
                            };
                            //监听键盘事件
                            $(document).on('keydown', this.enterEsc);
                            //esc键触发取消
                            this.escQuit = (ev) => {
                                let code_val = ev.which;
                                if(code_val == 0x1B){
                                    $('.layui-layer-btn1').click();
                                    return false;
                                }
                            };
                            $(document).on('keydown', this.escQuit);
                        },
                        end: function () {
                            //取消键盘监听事件
                            $(document).off('keydown', this.enterEsc);
                            $(document).off('keydown', this.escQuit);
                        },
                        yes: function () {
                            //确认执行的代码
                            delData(id);
                        },
                        no: function () {

                        }
                    });
                    break;
            };
        })

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });

    });


    function changeStatus(id,status){
        $.post('${ctx}/sysSettings/projectInfoSetting/changeProjectSettingStatus', {id: id,status:status}, function(result){
            if("200" == result.code){
                layer.msg('操作成功', {time: 2000}, function () {
                    reload();
                });
            }else{
                layer.msg(result.errMsg);
            }
        });
    }

    function delData(id){
        $.ajax({
            url: '${ctx}/sysSettings/projectInfoSetting/delete',
            type: 'post',
            data: {
                ids: id
            },
            success: function (data) {
                if (data.code == "200") {
                    layer.msg('操作成功', {time: 2000}, function () {
                        table.reload('test');
                    });
                } else {
                    layer.msg(data.errMsg);
                }
            },
            complete: function () {
                noRepeat = false;
            }
        });
    }

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

    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

    function lookVariables(id){
        layer.open({
            type: 2
            ,title: '查看'
            ,content: '${ctx}/sysSettings/projectInfoSetting/lookVariables?id=' +id
            ,area: ['60%','40%']
            ,success : function(layero) {
            }
        });
    }
</script>
</body>
</html>

