<?xml version="1.0" encoding="UTF-8"?>

<!--
    $Author: chenlingfeng7543
$Date: 2018/7/26 15:02
$Revision: 1.0 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.business_type in (&apos;LEASE&apos;,&apos;LEASEBACK&apos;)"
                       fetchAll="true" model="basic.hls_business_type_for_lov" rootPath="business_type_path"/>
        <a:model-query fetchAll="true" model="basic.hls_lease_channel_for_lov" rootPath="lease_channel_path"/>
        <a:model-query fetchAll="true" model="basic.hls_division_for_lov" rootPath="hls_division_path"/>
        <a:model-query fetchAll="true" model="basic.get_sys_default_time" rootPath="default_date"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con1100_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="con1100_contract_modify_link"
                url="${/request/@context_path}/modules/cont/CON302N/con_contract_modify.lview"/>
        <a:link id="contract_cancel_link" model="cont.CON1100.con_contract_excuted"
                modelaction="insert"/>
        <script type="text/javascript"><![CDATA[
        function con1100_detail_renderer(value, record, name) {
            if (name == 'con1100_detail') {
                return '<a href="javascript:con1100_open_modify_win(' + record.id + ')">明细</a>';
            }

            return '';
        }

        function con1100_detail_renderer2(value, record, name) {
            if (name == 'con1100_detail') {
                return '<a href="javascript:con1100_open_modify_win2(' + record.id + ')">明细</a>';
            }

            return '';
        }

        function con1100_detail_renderer3(value, record, name) {
            if (name == 'con1100_detail') {
                return '<a href="javascript:con1100_open_read_win(' + record.id + ')">明细</a>';
            }

            return '';
        }

        function con1100_open_modify_win(id) {
            var ds_id = 'con1100_con_contract_for_excute_ds';
            var record = $(ds_id).findById(id);
            var param = record.data;
            if (record.get('lease_execution_flag') == 'C') {
                param['function_code'] = 'CON1100R';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY';
            } else {
                param['function_code'] = 'CON480_MODIFY';
                /* param['function_usage'] = 'QUERY'; */
                param['maintain_type'] = 'UPDATE';
            }
            param['bp_class'] = 'NP';
            param['winid'] = 'con_contract_modify_link_winid';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con1100_contract_get_layout_code_link_id', param, 'con1100_contract_modify_link', ds_id);

        }

        function con1100_open_read_win(id) {
            var ds_id = 'con1100_con_contract_excuted_ds';
            var record = $(ds_id).findById(id);
            var param = record.data;
            param['function_code'] = 'CON1100R';
            param['function_usage'] = 'QUERY';
            param['maintain_type'] = 'READONLY';
            param['bp_class'] = 'NP';
            param['winid'] = 'con_contract_modify_link_winid';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con1100_contract_get_layout_code_link_id', param, 'con1100_contract_modify_link', ds_id);

        }

        function con1100_open_modify_win2(id) {

            var ds_id = 'con1100_con_contract_not_passed_ds';
            var record = $(ds_id).findById(id);
            var param = record.data;
            param['function_code'] = 'CON480_MODIFY';
            param['maintain_type'] = 'UPDATE';
            param['winid'] = 'con_contract_modify_link_winid';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con1100_contract_get_layout_code_link_id', param, 'con1100_contract_modify_link', ds_id);

        }

        function con1100_calcConfigScreen_getTabType() {
            var config = {
                0: 'H',
                1: 'L',
                2: 'M'
            };
            return config[$('con1100_calcConfigScreen_tab').selectedIndex];

        }

        function con1100_calcConfigScreen_getDs() {
            var config = {
                'H': 'con1100_con_contract_for_excute_ds',
                'L': 'con1100_con_contract_not_passed_ds',
                'M': 'con1100_con_contract_excuted_ds'
            };
            return config[con1100_calcConfigScreen_getTabType()];
        }

        function con1100_query() {
            var dsName = con1100_calcConfigScreen_getDs();
            $(dsName).query();
        }

        function con1100_return() {
            history.go(-1);
        }

        function con1100_reset() {
            $('con1100_con_contract_for_excute_query_ds').reset();
        }

        function con1100_notice_call() {
            var records = $('con1100_con_contract_not_passed_ds').selected;
            var header = $jq('meta[name=_csrf_header]').attr('content');
            var token = $jq('meta[name=_csrf]').attr('content');
            $jq(document).ajaxSend(function (e, xhr, options) {
                xhr.setRequestHeader(header, token);
            });
            var data = [];

            records.forEach(function (value) {
                data.push(
                    {
                        noticeUserId: value.get('user_id'),
                        msgTitle: '回访',
                        msgBody: value.get('contract_number') + '该合同需要回访',
                        noticeType: 'NONE',
                        priority: 2,
                        noticeUrl: 'call/call_return_visit.lview',
                        sourceId: value.get('contract_id')
                    })
            });
            $jq.ajax({
                url: '${/request/@context_path}/sys/notice/msg/notice',
                type: 'post',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(data),
                success: function (res) {
                    if (res.success) {
                        Leaf.SideBar.show({
                            msg: '保存成功',
                            duration: 2000
                        });
                    }
                }
            })
        }


        function con1100_cancel() {
            var record = $('con1100_con_contract_excuted_ds').getCurrentRecord();
            if (record.length == 0) {
                Leaf.showMessage('${l:HLS.PROMPT}', '至少选择一条数据！');
                return;
            } else {
                var contract_id = record.get("contract_id");
                Leaf.showConfirm('${HLS.PROMPT}', '你确定取消合同吗?', function () {
                    Leaf.request({
                        url: $('contract_cancel_link').getUrl(),
                        para: {
                            contract_id: contract_id
                        },
                        success: function () {
                            $('con1100_con_contract_excuted_ds').query();
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                        },
                        scope: this
                    });

                }, null);

            }
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="con1100_business_type_ds">
                <a:datas dataSource="/model/business_type_path"/>
            </a:dataSet>
            <a:dataSet id="con1100_lease_channel_ds">
                <a:datas dataSource="/model/lease_channel_path"/>
            </a:dataSet>
            <a:dataSet id="con1100_hls_division_ds">
                <a:datas dataSource="/model/hls_division_path"/>
            </a:dataSet>
            <a:dataSet id="con1100_contract_status_ds" lookupCode="CON500_CONTRACT_STATUS"/>
            <a:dataSet id="con1100_execution_status_ds" lookupCode="EXECUTION_STATUS_DS"/>
            <a:dataSet id="con1100_yes_no_ds" lookupCode="YES_NO"/>
            <a:dataSet id="con1100_down_payment_status_ds" lookupCode="DOWN_PAYMENT_STATUS"/>
            <a:dataSet id="con1100_con_contract_for_excute_query_ds">
                <a:fields>
                    <a:field name="contract_status_n" displayField="code_value_name"
                             options="con1100_contract_status_ds"
                             returnField="contract_status" valueField="code_value"/>
                    <a:field name="business_type_n" displayField="description" options="con1100_business_type_ds"
                             returnField="business_type" valueField="business_type"/>
                    <a:field name="lease_channel_n" displayField="description" options="con1100_lease_channel_ds"
                             returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="division_n" displayField="description" options="con1100_hls_division_ds"
                             returnField="division" valueField="division"/>
                    <a:field name="execution_status_desc" displayField="code_value_name"
                             options="con1100_execution_status_ds"
                             returnField="execution_status" valueField="code_value"/>
                    <a:field name="bp_id_agent_level1_n" lovGridHeight="400" lovHeight="550"
                             lovService="basic.hls_bp_agent_for_lov" lovWidth="500" title="代理商">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_agent_level1"/>
                            <a:map from="bp_name" to="bp_id_agent_level1_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="information_completed_desc" displayField="code_value_name"
                             options="con1100_yes_no_ds"
                             returnField="information_completed" valueField="code_value"/>
                    <a:field name="lease_execution_date_from" datatype="date"
                             defaultValue="${/model/default_date/record/@month_first_day}"/>
                    <a:field name="lease_execution_date_to" datatype="date"
                             defaultValue="${/model/default_date/record/@month_last_day}"/>
                    <a:field name="down_payment_status_n" displayField="code_value_name"
                             options="con1100_down_payment_status_ds"
                             returnField="down_payment_status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>

            <a:dataSet id="con1100_con_contract_for_excute_ds" selectable="true" selectionModel="single"
                       queryDataSet="con1100_con_contract_for_excute_query_ds"
                       autoQuery="true" autoPageSize="true"
                       model="cont.CON1100.con_contract_for_excute"/>
            <a:dataSet id="con1100_con_contract_not_passed_ds" selectable="true" selectionModel="single"
                       queryDataSet="con1100_con_contract_for_excute_query_ds"
                       autoQuery="true" autoPageSize="true"
                       model="cont.CON1100.con_contract_not_passed"/>
            <a:dataSet id="con1100_con_contract_excuted_ds" selectable="true" selectionModel="single"
                       queryDataSet="con1100_con_contract_for_excute_query_ds"
                       autoQuery="true" autoPageSize="true"
                       model="cont.CON1100.con_contract_excuted"/>
        </a:dataSets>
        <a:screenBody>
            <a:tabPanel labelWidth="150" marginHeight="30" marginWidth="30">
                <a:tabs>
                    <a:tab width="300" prompt="合同执行">
                        <a:screenTopToolbar>
                            <!--<a:gridButton click="con1100_return" text="HLS.RETURN"/>-->
                            <a:gridButton click="con1100_query" text="HLS.QUERY"/>
                            <a:gridButton click="con1100_reset" text="HLS.RESET"/>

                            <a:gridButton click="con1100_cancel" text="合同取消" style="margin-left:100px"/>
                        </a:screenTopToolbar>
                        <a:form title="查询条件" labelWidth="120" column="4" marginWidth="50">
                            <a:comboBox bindTarget="con1100_con_contract_for_excute_query_ds" prompt="合同类型"
                                        name="business_type_n"/>
                            <a:lov bindTarget="con1100_con_contract_for_excute_query_ds" prompt="代理商"
                                   name="bp_id_agent_level1_n"/>
                            <a:comboBox bindTarget="con1100_con_contract_for_excute_query_ds" prompt="执行状态标注"
                                        name="execution_status_desc"/>
                            <a:comboBox bindTarget="con1100_con_contract_for_excute_query_ds" prompt="合同状态"
                                        name="contract_status_n"/>
                            <a:textField bindTarget="con1100_con_contract_for_excute_query_ds" prompt="承租人名称"
                                         name="bp_name"/>
                            <a:textField bindTarget="con1100_con_contract_for_excute_query_ds" prompt="代理商简称"
                                         name="agent_extra_nam"/>
                            <a:textField bindTarget="con1100_con_contract_for_excute_query_ds" prompt="call担当"
                                         name="user_name"/>
                            <a:comboBox bindTarget="con1100_con_contract_for_excute_query_ds" prompt="产品线"
                                        name="division_n"/>
                            <a:comboBox bindTarget="con1100_con_contract_for_excute_query_ds" prompt="商业模式"
                                        name="lease_channel_n"/>
                            <!--<a:textField bindTarget="con1100_con_contract_for_excute_query_ds" prompt="合同编号" name="contract_number"/>-->
                            <a:textField bindTarget="con1100_con_contract_for_excute_query_ds" prompt="合同编号"
                                         name="contract_number"/>
                            <!--<a:textField bindTarget="con1100_con_contract_for_excute_query_ds" prompt="承租人编号" name="bp_code"/>-->
                            <a:comboBox bindTarget="con1100_con_contract_for_excute_query_ds" prompt="信息录入是否完成"
                                        name="information_completed_desc"/>
                            <a:datePicker name="lease_execution_date_from"
                                          bindTarget="con1100_con_contract_for_excute_query_ds" prompt="执行日期从"/>
                            <a:datePicker name="lease_execution_date_to"
                                          bindTarget="con1100_con_contract_for_excute_query_ds" prompt="执行日期到"/>
                            <a:comboBox name="down_payment_status_n" prompt="首付状态"
                                        bindTarget="con1100_con_contract_for_excute_query_ds"/>

                        </a:form>
                        <a:tabPanel id="con1100_calcConfigScreen_tab" labelWidth="150" marginWidth="50"
                                    marginHeight="240">
                            <a:tabs>
                                <a:tab width="300" prompt="待执行合同清单">
                                    <a:grid id="con1100_grid_id" marginWidth="80" marginHeight="300"
                                            bindTarget="con1100_con_contract_for_excute_ds" navBar="true">
                                        <a:toolBar>
                                            <a:button type="excel" text="导出"/>
                                        </a:toolBar>
                                        <a:columns>
                                            <a:column name="con1100_detail" align="center" prompt="明细"
                                                      renderer="con1100_detail_renderer"/>
                                            <a:column name="contract_status_desc" prompt="合同状态"/>
                                            <a:column name="contract_number" prompt="合同编号"/>
                                            <a:column name="bp_name" prompt="客户名称"/>
                                            <a:column name="bp_class_n" prompt="客户类型"/>
                                            <a:column name="agent_extra_nam" prompt="代理商简称"/>
                                            <a:column name="pattern" prompt="机型"/>
                                            <a:column name="machine_number" prompt="机号"/>
                                            <a:column name="execution_status_desc" prompt="执行状态标注"/>
                                            <a:column name="factory_date" prompt="wholesale date"/>
                                            <a:column name="business_type_desc" prompt="业务类型"/>
                                            <a:column name="lease_channel_desc" prompt="商业模式"/>
                                            <a:column name="down_payment_write_off" prompt="前期款状态"/>
                                            <a:column name="lease_execution_flag_desc" prompt="执行状态"/>
                                            <a:column name="down_payment_status_n" prompt="首付状态"/>
                                            <a:column name="case_interface_name" prompt="起案类型"/>
                                            <a:column name="case_status" prompt="起案状态"/>
                                            <a:column name="agent_name" prompt="代理商"/>
                                            <a:column name="division_desc" prompt="产品线"/>
                                            <a:column name="finance_amount" prompt="融资额"/>
                                            <a:column name="user_name" prompt="call担当"/>
                                            <a:column name="area_distinguish" prompt="备注"/>
                                        </a:columns>
                                    </a:grid>
                                </a:tab>
                                <a:tab width="300" prompt="事前确认未通过">
                                    <a:grid id="con1100_grid2_id" marginWidth="80" marginHeight="300"
                                            bindTarget="con1100_con_contract_not_passed_ds" navBar="true">
                                        <a:toolBar>
                                            <a:button type="excel" text="导出"/>
                                            <a:button text="通知call担当" click="con1100_notice_call"/>
                                        </a:toolBar>
                                        <a:columns>
                                            <a:column name="con1100_detail" align="center" prompt="明细"
                                                      renderer="con1100_detail_renderer2"/>
                                            <a:column name="contract_number" prompt="合同编号"/>
                                            <a:column name="bp_name" prompt="客户姓名"/>
                                            <a:column name="pattern" prompt="机型"/>
                                            <a:column name="machine_number" prompt="机号"/>
                                            <a:column name="bp_id_agent_level1_n" prompt="代理商"/>
                                            <a:column name="agent_extra_nam" prompt="代理商简称"/>
                                            <a:column name="information_completed" prompt="信息录入是否完成" width="140"/>
                                            <a:column name="execution_status_desc" prompt="执行状态标注"/>
                                            <a:column name="down_payment_status_n" prompt="首付状态"/>
                                            <a:column name="call_status" prompt="外呼状态"/>
                                            <a:column name="tenant_verify_result" prompt="电话确认情况"/>
                                            <a:column name="tenant_class" prompt="未通过原因"/>
                                            <a:column name="description" prompt="备注"/>
                                            <a:column name="guarantor_1_name" prompt="担保人1名称"/>
                                            <a:column name="guarantor_1_verify_result" prompt="担保人1核实结果"/>
                                            <a:column name="guarantor_1_class" prompt="担保人1未通过原因"/>
                                            <a:column name="guarantor_2_name" prompt="担保人2名称"/>
                                            <a:column name="guarantor_2_verify_result" prompt="担保人2核实结果"/>
                                            <a:column name="guarantor_2_class" prompt="担保人2未通过原因"/>
                                            <a:column name="user_name" prompt="call担当"/>
                                            <a:column name="pattern" prompt="机型"/>
                                            <a:column name="machine_number" prompt="机号"/>
                                            <a:column name="factory_date" prompt="wholesale date"/>
                                            <a:column name="area_distinguish" prompt="备注"/>
                                            <a:column name="last_call_time" prompt="最后一次通话时间"/>
                                            <a:column name="record_times" prompt="通话次数"/>
                                        </a:columns>
                                    </a:grid>
                                </a:tab>
                                <a:tab width="300" prompt="已执行合同清单">
                                    <a:grid id="con1100_grid3_id" marginWidth="80" marginHeight="300"
                                            bindTarget="con1100_con_contract_excuted_ds" navBar="true">
                                        <a:toolBar>
                                            <a:button type="excel" text="导出"/>
                                        </a:toolBar>
                                        <a:columns>
                                            <a:column name="con1100_detail" align="center" prompt="明细"
                                                      renderer="con1100_detail_renderer3"/>
                                            <a:column name="contract_status_desc" prompt="合同状态"/>
                                            <a:column name="contract_number" prompt="合同编号"/>
                                            <a:column name="bp_name" prompt="客户名称"/>
                                            <a:column name="bp_class_n" prompt="客户类型"/>
                                            <a:column name="agent_extra_nam" prompt="代理商简称"/>
                                            <a:column name="pattern" prompt="机型"/>
                                            <a:column name="machine_number" prompt="机号"/>
                                            <a:column name="execution_status_desc" prompt="执行状态标注"/>
                                            <a:column name="lease_execution_date" prompt="执行日期"/>
                                            <a:column name="factory_date" prompt="wholesale date"/>
                                            <a:column name="business_type_desc" prompt="业务类型"/>
                                            <a:column name="lease_channel_desc" prompt="商业模式"/>
                                            <a:column name="down_payment_write_off" prompt="前期款状态"/>
                                            <a:column name="lease_execution_flag_desc" prompt="执行状态"/>
                                            <a:column name="down_payment_status_n" prompt="首付状态"/>
                                            <a:column name="case_interface_name" prompt="起案类型"/>
                                            <a:column name="case_status" prompt="起案状态"/>
                                            <a:column name="agent_name" prompt="代理商"/>
                                            <a:column name="division_desc" prompt="产品线"/>
                                            <a:column name="finance_amount" prompt="融资额"/>
                                            <a:column name="user_name" prompt="call担当"/>
                                            <a:column name="area_distinguish" prompt="备注"/>
                                        </a:columns>
                                    </a:grid>
                                </a:tab>

                            </a:tabs>
                        </a:tabPanel>
                    </a:tab>
                    <a:tab width="300" prompt="前期款下账"
                           ref="${/request/@context_path}/modules/csh/CSH531N/csh_bank_transfer_processing.lview">

                    </a:tab>
                    <a:tab width="300" prompt="放款申请"
                           ref="${/request/@context_path}/modules/csh/CSH501/csh_payment_create_entrance.lview?layout_code=CSH_CREATE_ENTRANCE&amp;function_code=CSH501">
                    </a:tab>
                    <a:tab width="300" prompt="客户信息管理"
                           ref="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_modify_entrance.lview?layout_code=BP_MODIFY_ENTRANCE&amp;function_code=HLS214N">
                    </a:tab>
                </a:tabs>
            </a:tabPanel>

        </a:screenBody>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>