<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure outputPath="/parameter">
        <a:model-query model="basic.hls_fnd_attribute_sequence" rootPath="header"/>
        <a:import-excel header_id="${/model/header/record/@header_id}" separator=","
                        status_field="/parameter/@ImportSuccess" template_code="HLS_LEASE_ITEM_GPS_IMPORT"
                        user_id="${/session/@user_id}"/>
        <a:model-query
                defaultWhereClause="header_id=${/model/header/record/@header_id} and TEMPLATE_CODE = &apos;HLS_LEASE_ITEM_GPS_IMPORT&apos;"
                model="basic.hls_fnd_attribute_status" rootPath="status"/>
        <a:model-execute model="hls.HLS204N.hls_lease_item_gps_list_tmp"/>
    </a:init-procedure>
    <a:view>
        <a:link id="save_import_hls_lease_item_gps_data_link_id" model="hls.HLS204N.hls_lease_item_gps_list_tmp"
                modelaction="insert"/>
        <style>
            .prompt-position {
                float:right;
                font-weight: bold;
                margin-top:20px;
                margin-left: 10px;
                font-size: 10px;
            }
            .period-exists span::before{
                content: ' ';
                height: 10px;
                position:relative;
                width: 10px;
                background:#FFE4C4;
                display: inline-block;
                bottom: -1px;
                margin-right: 2px;
            }
            .import-error span::before{
                content: ' ';
                height: 10px;
                position:relative;
                width: 10px;
                display: inline-block;
                bottom: -1px;
                margin-right: 2px;
                background: #FC9492;
            }
        </style>
        <script type="text/javascript"><![CDATA[

        function backBtn() {
            parent._input_window.close();
        }

        function checkBtn() {
            var ds = $('hls_lease_item_gps_import_ds');
            var records = ds.getAll();
            var header_id = records[0].get('header_id');
            // alert(header_id);
            Leaf.request({
                url: $('save_import_hls_lease_item_gps_check_link_id').getUrl(),
                para: {
                    header_id: header_id
                },
                scope: this,
                success: function () {
                    $('hls_lease_item_gps_import_ds').query();
                    Leaf.SideBar.show({
                        msg: '校验成功',
                        duration: 2000
                    });
                }
            })
        }

        var import_flag = 0;
        var import_over_write_flag = 'N';

        function importBtn() {
            var msg = '确定要导入信息吗';
            var ds = $('hls_lease_item_gps_import_ds');
            var records = ds.getAll();
            var saveData = [];
            for (var i = 0; i < records.length; i++) {
                var record = records[i];
                if (record.get('status') == 'ERROR') {
                    import_flag = 1;
                    Leaf.showInfoMessage('提示', '导入数据存在错误，请核对并重新导入');
                    return;
                }
                if (record.get('exists_flag') == 'Y') {
                    import_over_write_flag = 'Y';
                }
            }
            if (import_over_write_flag == 'Y') {
                msg = '租赁物存在已导入的期间，<font color="red">导入将覆盖该期间数据</font>，确定要导入信息吗'
            }
            if (import_flag == 0) {
                //导入数据
                Leaf.showConfirm('提示', msg, function () {
                    Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                    $('importBtn').disable();
                    Leaf.request({
                        url: $('save_import_hls_lease_item_gps_data_link_id').getUrl(),
                        para: {
                            header_id: '${/model/header/record/@header_id}'
                        },
                        success: function () {
                            $('hls_lease_item_gps_import_ds').query();
                            // Leaf.Masker.unmask(Ext.getBody());
                            Leaf.SideBar.show({
                                msg: '导入成功',
                                duration: 2000
                            });
                            Leaf.Masker.unmask(Ext.getBody());
                            $('importBtn').enable();
                            backBtn();
                        },
                        failure: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                });
            }
        }

        function change_background_color(record) {
            if (record.get('status') == 'ERROR'){
                return 'background-color:#FC9492';
            }
            if (record.get('exists_flag') == 'Y') {
                return 'background-color:#FFE4C4';
            }
        }


        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls_lease_item_gps_import_ds" autoQuery="true" fetchAll="true"
                       model="hls.HLS204N.hls_lease_item_gps_list_tmp"
                       queryUrl="${/request/@context_path}/autocrud/hls.HLS204N.hls_lease_item_gps_list_tmp/query?header_id=${/model/header/record/@header_id}">
                <a:fields>
                    <a:field name="error_message" readOnly="true"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="backBtn" text="取消"/>
                <!--                    <a:gridButton click="checkBtn" text="数据校验"/>-->
                <a:gridButton id="importBtn" click="importBtn" text="确认导入"/>
                <div style="float:right;" class="prompt-position period-exists"><span>租赁物期间已存在</span></div>
                <div style="float:right;" class="prompt-position import-error"><span>导入信息错误</span></div>
            </a:screenTopToolbar>
            <a:grid id="grid_ds_id" bindTarget="hls_lease_item_gps_import_ds" height="480" navBar="true"
                    width="1050" rowRenderer="change_background_color">
                <a:columns>
                    <a:column name="error_message" editor="textArea_e" prompt="错误信息" width="180"/>
                    <a:column name="line_number" prompt="excel行号" width="80" align="right"/>
                    <a:column name="attribute_1" prompt="合同编号" width="130"/>
                    <a:column name="attribute_2" prompt="客户名称" width="120"/>
                    <a:column name="attribute_3" prompt="代理店" width="120"/>
                    <a:column name="attribute_4" prompt="机型" width="120" align="center"/>
                    <a:column name="attribute_5" prompt="机号" width="120" align="center"/>
                    <a:column name="attribute_6" prompt="期间" width="110" align="center"/>
                    <a:column name="attribute_7" prompt="最新工作小时数（总）" width="120" align="right"/>
                    <a:column name="attribute_8" prompt="本月工作小时数" width="120" align="right"/>
                    <a:column name="attribute_9" editor="textArea_e" prompt="机器位置（省市）" width="120"/>
                    <a:column name="attribute_10" prompt="备注" width="150"/>
                    <a:column name="attribute_11" prompt="要注意" width="80"/>
                    <a:column name="attribute_12" editor="textArea_e" prompt="完整机号" width="140"/>
                </a:columns>
                <a:editors>
                    <a:textArea id="textArea_e" readOnly="true" height="50" width="240"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[

	  	]]></script>
    </a:view>
</a:screen>
