<?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="pageLink_bpQueryScreen_welcome" url="${/request/@context_path}/welcome.lview"/>
        <a:link id="rsc_value_assessment_detail_link" url="${/request/@context_path}/modules/rsc/RSC505/rsc_value_assessment_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            function bpQueryScreen_forward() {
                history.go(1);
            }
            
            function bpQueryScreen_back() {
                history.go(-1);
            }
            
            function bpMaintainScreen_query() {
                $('bpMaintainDs').query();
            }
            
            function bpMaintainScreen_reset() {
                $('para_bpMaintainDs').reset();
            }
            
            function bpMaintainScreen_quit() {
                location.href = $('pageLink_bpQueryScreen_welcome').getUrl();
                parent.shMenu('show');
            }
            
            function construct_from_to() {
                var config = ['bp_code', 'bp_code_desc', 'search_term_1', 'search_term_2'];
                var pattern = ['_from', '_to'];
                var obj = {};
                for (var i = 0,
                    j = config.length;i < j;i++) {
                    for (var m = 0,
                        n = pattern.length;m < n;m++) {
                        obj[config[i] + pattern[m]] = config[i] + pattern[n - 1 - m];
                    }
                }
                return obj;
            }
            
            function onUpdate_para_bpMaintainDs(ds, record, name, value, oldvalue) {
                var from_to = construct_from_to();
                var opposite_name = from_to[name];
                if (!Ext.isEmpty(opposite_name)) {
                    var opposite_value = record.get(opposite_name);
                    if (!Ext.isEmpty(value) && Ext.isEmpty(opposite_value)) {
                        record.set(opposite_name, value);
                    }
                }
            
            }
            
            
            
            function assess_number_renderer(value, record, name) {
                if ( !! record) {
                    if (name == 'assess_number') {
                        var assess_hd_id = record.get('assess_hd_id');
                        if (!Ext.isEmpty(assess_hd_id) && !Ext.isEmpty(value)) {
                            return '<a href="javascript:winOpen_bpMaintainScreen(' + assess_hd_id + ');">' + value + '</a>';
                        }
                    }
                    return '';
                }
            }
            
            function winOpen_bpMaintainScreen(assess_hd_id) {
                // var assess_hd_id = $('bpMaintainDs').getCurrentRecord().get('assess_hd_id');
                var bp_id_tenant = $('bpMaintainDs').getCurrentRecord().get('bp_id_tenant');
                new Leaf.Window({
                    id: 'rsc_value_assessment_detail_id',
                    url: $('rsc_value_assessment_detail_link').getUrl() + '?assess_hd_id=' + assess_hd_id + '&bp_id_tenant=' + bp_id_tenant,
                    title: '价值评估维护',
                    fullScreen: true
                }).on('close', bpMaintainScreen_query);
            
            }
            
            function bpMaintainScreen_delete() {
                //var assess_hd_id = $('bpMaintainDs').getCurrentRecord().get('assess_hd_id');
                var records = $('bpMaintainDs').getSelected();
            
                Leaf.showConfirm('${l:HLS.PROMPT}', '确认删除?', function okFun() {
                    Leaf.Masker.mask(Ext.getBody(), '操作中。。');
            
                    for (var i = 0;i < records.length;i++) {
                        Leaf.request({
                            url: '${/request/@context_path}/autocrud/rsc.RSC505.rsc_value_assess_hd_delete/execute',
                            para: {
                                assess_hd_id: records[i].get('assess_hd_id'),
                                _status: 'execute'
                            },
                            success: function(res) {
                                Leaf.SideBar.show({
                                    msg: '${l:HLS.SUBMIT_SUCCESS}',
                                    duration: 2000
                                });
                                Leaf.Masker.unmask(Ext.getBody());
                                bpMaintainScreen_query();
                            },
                            failure: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            error: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            scope: this
                        });
            
                    }
            
                }, Leaf.Masker.unmask(Ext.getBody()));
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="approval_status_ds">
                <a:datas>
                    <a:record code_value="NEW" code_value_name="新建"/>
                    <a:record code_value="REJECT" code_value_name="拒绝"/>
                    <a:record code_value="APPROVING" code_value_name="审批中"/>
                    <a:record code_value="APPROVED" code_value_name="通过"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="para_bpMaintainDs" model="hls.HLS212.hls_bp_master_all_data_v">
                <a:fields>
                    <a:field name="bp_code_from" lovGridHeight="350" lovHeight="500" lovService="basic.hls_bp_master_v_for_lov" lovWidth="500" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code_to" lovGridHeight="350" lovHeight="500" lovService="basic.hls_bp_master_v_for_lov" lovWidth="500" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_name"/>
                    <a:field name="approval_status_desc" displayField="code_value_name" options="approval_status_ds" prompt="审批状态" returnField="approval_status" valueField="code_value"/>
                    <a:field name="approval_status"/>
                    <a:field name="assess_number"/>
                    <a:field name="req_date"/>
                </a:fields>
                <!-- <a:events>
                    <a:event name="update" handler="onUpdate_para_bpMaintainDs"/>
                </a:events> -->
            </a:dataSet>
            <a:dataSet id="bpMaintainDs" autoPageSize="true" autoQuery="true" model="rsc.RSC504.rsc_value_assess_hd" queryDataSet="para_bpMaintainDs" selectable="true">
                <a:fields>
                    <a:field name="approval_status_desc" displayField="code_value_name" options="approval_status_ds" prompt="审批状态" returnField="approval_status" valueField="code_value"/>
                    <a:field name="approval_status" defaultValue="NEW"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!-- <a:gridButton click="bpQueryScreen_back" text="HLS.BACK"/>
                <a:gridButton click="bpQueryScreen_forward" text="HLS.FORWARD"/> -->
                <a:gridButton click="bpMaintainScreen_query" text="HLS.QUERY"/>
                <a:gridButton click="bpMaintainScreen_reset" text="HLS.RESET"/>
                <a:gridButton click="bpMaintainScreen_quit" text="HLS.EXIT"/>
                <!-- <a:gridButton click="bpMaintainScreen_delete" text="HLS.REMOVE"/> -->
                <!-- <a:gridButton click="bpQueryScreen_inspect_asset_create" text="创建"/> -->
            </a:screenTopToolbar>
            <a:form column="5" labelWidth="120" marginWidth="30" title="HLS.QUERY_TITLE">
                <a:textField name="assess_number" bindTarget="para_bpMaintainDs" prompt="CSH502.CSH_REQ_NO"/>
                <!-- <a:lov name="bp_code_from" bindTarget="para_bpMaintainDs" prompt="HLS.BP_CODE_FROM">
                    <a:events>
                        <a:event name="focus" handler="on_std_focus"/>
                    </a:events>
                </a:lov>
                <a:lov name="bp_code_to" bindTarget="para_bpMaintainDs" prompt="HLS.BP_CODE_TO">
                    <a:events>
                        <a:event name="focus" handler="on_std_focus"/>
                    </a:events>
                </a:lov> -->
                <a:textField name="bp_code" bindTarget="para_bpMaintainDs" prompt="HLS.BP_CODE"/>
                <a:textField name="bp_name" bindTarget="para_bpMaintainDs" prompt="HLS.BP_NAME"/>
                <a:datePicker name="req_date" bindTarget="para_bpMaintainDs" prompt="CSH502.CSH_REQ_DATE"/>
                <a:comboBox name="approval_status_desc" bindTarget="para_bpMaintainDs" prompt="审批状态"/>
                <!-- <a:comboBox name="approval_status_desc"/> -->
            </a:form>
            <a:grid id="bpMaintainDs_grid" bindTarget="bpMaintainDs" marginHeight="250" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="assess_number" prompt="CSH502.CSH_REQ_NO" renderer="assess_number_renderer" width="150"/>
                    <a:column name="req_date" align="center" prompt="CSH502.CSH_REQ_DATE" renderer="Leaf.formatDate"/>
                    <a:column name="bp_code" prompt="商业伙伴编码" width="100"/>
                    <a:column name="bp_name" prompt="商业伙伴名称" width="180"/>
                    <a:column name="approval_status_desc" prompt="审批状态" width="100"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>