<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018年7月16日 下午2:18:45  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_prj500_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con_prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
        //锁屏

        function lock_window() {
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
        }

        //解屏

        function unlock_window() {
            Leaf.Masker.unmask(Ext.getBody());
        }

        //确定

        function con_confirm() {
            //
            var record = $('contract_modify_result_ds').getCurrentRecord();
            lock_window();
            Leaf.request({
                url: '${/request/@context_path}/autocrud/cont.CON350.con350_modify_insurance/update',
                para: {
                    contract_id: '${/parameter/@contract_id}',
                    insurance_number: record.get('insurance_number'),
                    real_insurance_date: record.get('real_insurance_date'),
                    insurance_end_date: record.get('insurance_end_date'),
                    machine_number: record.get('machine_number')
                },
                success: function (res) {
                    Leaf.SideBar.show({
                        msg: '操作成功',
                        duration: 2000
                    });
                    unlock_window();
                    con_cancel();
                },
                error: function () {
                    unlock_window();
                },
                failure: function () {
                    unlock_window();
                },
                sync: true,
                scope: this
            });
        }

        //取消

        function con_cancel() {
            $('con_insurance_modify_link_winId').close();
        }

        function ds_doc_render_func(value, record, name) {
            var check_id = record.get('check_id');
            var url;
            var text;
            var contract_id = record.get('contract_id');
            if (name == 'attachment') {
                return '<a href="javascript:attachment_window_open(\'' + contract_id + '\',\'' + record.id + '\',\'' + record.ds.id + '\');">' + '附件上传' + '</a>';
            }
        }


        function attachment_window_open(contract_id,record_id,ds_id){
            url = $('con_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CONTRACT_INSURANCE&header_id=' + contract_id;
            wd = new Leaf.Window({
                id: 'attachment_up_window',
                url: url,
                title: '附件上传',
                height: 350,
                width: 850
            });
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="contract_modify_result_ds" autoQuery="true" fetchAll="true"
                       model="cont.CON350.con350_insurance_result"
                       queryUrl="${/request/@context_path}/autocrud/cont.CON350.con350_insurance_result/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="contract_number" readOnly="true"/>
                    <a:field name="bp_id_tenant_n" readOnly="true"/>
                    <a:field name="insurance_number"/>
                    <a:field name="real_insurance_date"/>
                    <a:field name="lease_term" readOnly="true"/>
                    <a:field name="insurance_end_date"/>
                    <a:field name="machine_number"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <!--<a:screenTitle/>-->
                <a:gridButton click="con_cancel" text="取消"/>
                <a:gridButton click="con_confirm" text="确定"/>
            </a:screenTopToolbar>
            <a:grid id="cont_change_result_ds_id" bindTarget="contract_modify_result_ds" width="1200" height="250"
                    navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="合同编号" width="200"/>
                    <a:column name="bp_id_tenant_n" prompt="客户名" width="200"/>
                    <a:column name="insurance_number" prompt="保单号" editor="tf_id" width="200"/>
                    <a:column name="real_insurance_date" prompt="实际投保日" renderer="Leaf.formatDate" editor="dp_id"
                              width="120"/>
                    <a:column name="lease_term" prompt="租赁期间" width="100"/>
                    <a:column name="insurance_end_date" prompt="保单到期日" renderer="Leaf.formatDate" editor="dp_id"
                              width="120"/>
                    <!--<a:column name="machine_number" prompt="机号" editor="tf_id" width="120"/>-->
                    <a:column name="attachment" align="center" prompt="附件上传" renderer="ds_doc_render_func" width="100"/>

                </a:columns>
                <a:editors>
                    <a:numberField id="nf_id" allowDecimals="true" allowNegative="false"/>
                    <a:textField id="tf_id"/>
                    <a:datePicker id="dp_id"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>