<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: peter soong  
    $Date: 2014-08-27 16:33:57  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:view>
        <a:link id="rsc_value_assessment_save" url="${/request/@context_path}/modules/rsc/RSC504/rsc_value_assessment_save.lsc"/>
        <a:link id="rsc_value_assessment_detail" url="${/request/@context_path}/modules/rsc/RSC505/rsc_value_assessment_detail.lview"/>
        <a:link id="rsc_value_assessment" url="${/request/@context_path}/modules/rsc/RSC504/rsc_value_assessment.lview"/>
        <script type="text/javascript"><![CDATA[
            function submitScreen_quit() {
                $('rsc_value_assessment_submit_id').close();
            }
            
            var assess_hd_id;
            
            function submitScreen_save(value) {
            
                var bp_id_tenant = '${/parameter/@bp_id_tenant}';
                var lns_ds = $('submitDs');
                var lns_reords = lns_ds.getAll();
                var datas = [];
                for (var i = 0;i < lns_reords.length;i++) {
                    var data = lns_reords[i].data;
                    datas.push(data);
                }
                var queryParams = new Object();
                queryParams['details'] = datas;
                queryParams['bp_id_tenant'] = bp_id_tenant;
            
            
                if (lns_reords.length == 0) {
                    Leaf.showWarningMessage('消息', '请先点击新增,再保存。', null, 300, 100);
                } else {
                    if (lns_ds.validate()) {
                        Leaf.Masker.mask(Ext.getBody(), '${l:HLS.SAVING}');
                        Leaf.request({
                            url: $('rsc_value_assessment_save').getUrl(),
                            para: queryParams,
                            success: function(args) {
                                assess_hd_id = args.result.assess_hd_id;
                                if (value == 'sub') {
                                    submitScreen_submit();
                                } else {
                                    Leaf.SideBar.show({
                                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                                        duration: 2000
                                    });
                                    Leaf.Masker.unmask(Ext.getBody());
                                    window.location.href = $('rsc_value_assessment_detail').getUrl() + '?assess_hd_id=' + assess_hd_id + '&bp_id_tenant=' + bp_id_tenant;
                                }
                            },
                            failure: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            error: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            scope: this
                        });
                    }
                }
            }
            
            function submitScreen_submit() {
                Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE_TO_SUBMIT}', function okFun() {
                    Leaf.Masker.mask(Ext.getBody(), '${l:HLS.SAVING}');
                    Leaf.request({
                        url: '${/request/@context_path}/autocrud/rsc.RSC504.rsc_value_assess_submit/execute',
                        para: {
                            assess_hd_id: assess_hd_id,
                            _status: 'execute'
                        },
                        success: function(res) {
                            Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
                            Leaf.Masker.unmask(Ext.getBody());
                            window.location.href = $('rsc_value_assessment').getUrl() + '?assess_hd_id=' + assess_hd_id + '&bp_id_tenant=' + bp_id_tenant;
                        },
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                }, Leaf.Masker.unmask(Ext.getBody()));
            }
            
            function submitScreen_save_submit() {
                submitScreen_save('sub');
            
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="asset_type_ds" lookupCode="RSC504_ASSET_TYPE"/>
            <a:dataSet id="asset_way_ds" lookupCode="RSC504_ASSET_WAY"/>
            <a:dataSet id="asset_method_ds" lookupCode="RSC504_ASSET_METHOD"/>
            <a:dataSet id="submitDs" autoPageSize="true" autoQuery="true" model="rsc.RSC504.rsc_value_assess_ln" queryUrl="${/request/@context_path}/autocrud/rsc.RSC504.rsc_value_assess_ln/query?bp_id_tenant=${/parameter/@bp_id_tenant}" selectable="true">
                <a:fields>
                    <a:field name="contract_number" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="rsc.RSC504.rsc_value_contract_lov?bp_id=${/parameter/@bp_id_tenant}" lovWidth="500" required="true" title="合同信息">
                        <a:mapping>
                            <a:map from="contract_id" to="contract_id"/>
                            <a:map from="contract_name" to="contract_name"/>
                            <a:map from="contract_number" to="contract_number"/>
                            <a:map from="contract_num" to="contract_num"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_id"/>
                    <a:field name="contract_name"/>
                    <a:field name="asset_type_desc" displayField="code_value_name" options="asset_type_ds" required="true" returnField="asset_type" valueField="code_value"/>
                    <a:field name="asset_type"/>
                    <a:field name="assess_way_desc" displayField="code_value_name" options="asset_way_ds" required="true" returnField="assess_way" valueField="code_value"/>
                    <a:field name="assess_way"/>
                    <a:field name="assess_method_desc" displayField="code_value_name" options="asset_method_ds" required="true" returnField="assess_method" valueField="code_value"/>
                    <a:field name="assess_method"/>
                    <a:field name="assess_name"/>
                    <a:field name="asset_detail"/>
                    <a:field name="orig_value"/>
                    <a:field name="assess_value" required="true"/>
                    <a:field name="assess_date" required="true"/>
                    <a:field name="last_assess_value"/>
                    <a:field name="last_assess_date"/>
                    <a:field name="operator"/>
                    <a:field name="comments"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton bind="submitDs_grid" type="add"/>
                <a:gridButton bind="submitDs_grid" type="clear"/>
                <!-- <a:gridButton bind="submitDs_grid" type="delete"/> -->
                <a:gridButton click="submitScreen_save" text="HLS.SAVE"/>
                <!-- <a:gridButton click="submitScreen_save_submit" text="HLS.SUBMIT"/> -->
                <a:gridButton bind="submitDs_grid" type="excel"/>
                <a:gridButton click="submitScreen_quit" text="HLS.EXIT"/>
            </a:screenTopToolbar>
            <a:grid id="submitDs_grid" bindTarget="submitDs" marginHeight="250" marginWidth="30" navBar="true">
                <a:columns>
                    <!-- <a:column name="contract_num" prompt="HLS.CONTRACT_NUM" width="120"/> -->
                    <a:column name="contract_number" editor="grid_lov" prompt="HLS.CONTRACT_NUMBER" width="120"/>
                    <a:column name="assess_name" editor="grid_tf" prompt="评估物品名称" width="200"/>
                    <a:column name="asset_type_desc" editor="grid_cb" prompt="资产类型" width="100"/>
                    <a:column name="asset_detail" editor="grid_tf" prompt="资产明细" width="120"/>
                    <a:column name="orig_value" editor="grid_nf" prompt="设备原值" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="assess_value" editor="grid_nf" prompt="本次评估价值" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="assess_date" editor="grid_dp" prompt="本次评估日期" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="last_assess_value" editor="grid_nf" prompt="上次评估价值" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="last_assess_date" editor="grid_dp" prompt="上次评估日期" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="assess_way_desc" editor="grid_cb" prompt="评估方式" width="100"/>
                    <a:column name="assess_method_desc" editor="grid_cb" prompt="评估方法" width="100"/>
                    <a:column name="operator" editor="grid_tf" prompt="评估机构" width="100"/>
                    <a:column name="comments" editor="grid_tf" prompt="备注" width="220"/>
                </a:columns>
                <a:editors>
                    <a:lov id="grid_lov"/>
                    <a:textField id="grid_tf"/>
                    <a:comboBox id="grid_cb"/>
                    <a:datePicker id="grid_dp"/>
                    <a:numberField id="grid_nf"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>