<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:c="leaf.application.action" xmlns:a="http://www.leaf-framework.org/application" xmlns:p="uncertain.proc" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON632.PRJ_PROJECT_BP_TENANT" rootPath="con632_get_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="save_con_collection_tool_id" model="cont.CON632.con_collection_tool_insert" modelaction="update"/>
        <a:link id="execute_con_collection_tool" model="cont.CON632.con_collection_tool_insert" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
            function con_collection_save() {
                if ($('con_collection_tool_query_ds').validate()) {
                    var record = $('con_collection_tool_query_ds').getAt(0);

                    var v_collection_id;
                    Leaf.request({
                        url: $('save_con_collection_tool_id').getUrl(),
                        para: {
                            contract_id: record.get('contract_id'),
                            project_id: record.get('project_id'),
                            staff_id: record.get('staff_id'),
                            times: record.get('times'),
                            collection_measures: record.get('collection_measures'),
                            visit_address: record.get('visit_address'),
                            province: record.get('province'),
                            city: record.get('city'),
                            detailed_address: record.get('detailed_address'),
                            visit_address_b: record.get('visit_address_b'),
                            province_b: record.get('province_b'),
                            city_b: record.get('city_b'),
                            detailed_address_b: record.get('detailed_address_b'),
                            register_record: record.get('register_record'),
                            collection_id: v_collection_id,
                            col_id: '${/parameter/@col_id}',
                            collection_cost: record.get('collection_cost'),
                            lawsuit_reason: record.get('lawsuit_reason'),
                            take_reason:record.get('take_reason'),
                            take_imformation_add:record.get('take_imformation_add')
                        },
                        success: function(rsc) {
                            Leaf.request({
                                url: $('execute_con_collection_tool').getUrl(),
                                para: {
                                    collection_id: rsc.result.collection_id
                                },
                                success: function(rsc) {
                                    Leaf.SideBar.show({
                                        msg: '操作成功',
                                        duration: 2000
                                    });
                                    $('Collection_tool_id').close();
                                },
                                scope: this
                            });
            
                        },
                        failure: function(rsc) {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function(rsc) {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                }
            }
            
            function con_collection_tool_update(ds, record, name, value, oldVlaue) {

                if (name == 'collection_measures') {
                    if (value == 'VISIT') {
                        record.getField('visit_address_n').setReadOnly(false);
                        record.getField('visit_address_n').setRequired(true);
                    }
                    /*  if (value == 'LAWSUIT') {
                     record.getField('lawsuit_reason').setReadOnly(false);
                     record.getField('lawsuit_reason').setRequired(false);
                     } */
                    else {
                        record.getField('visit_address_n').setRequired(false);
                        record.getField('visit_address_n').setReadOnly(true);
                        record.set('visit_address_n', '');
                        record.set('province_n', '');
                        record.set('city_n', '');
                        record.set('detailed_address', '');
            
                        //record.getField('lawsuit_reason').setReadOnly(true);
                        //record.set('lawsuit_reason', '');
                    }
            
                }
                if (name == 'visit_address') {
                    if (value == 'ID_ADDRESS') {
                        record.set('detailed_address', '${/model/con632_get_info/record/@address_on_resident_booklit}');
                        record.set('province_n', '${/model/con632_get_info/record/@add_province_n}');
                        record.set('city_n', '${/model/con632_get_info/record/@add_city_n}');
                        record.set('province', '${/model/con632_get_info/record/@add_province}');
                        record.set('city', '${/model/con632_get_info/record/@add_city}');
                    } else if (value == 'LIVIING_ADDRESS') {
                        record.set('detailed_address', '${/model/con632_get_info/record/@living_address}');
                        record.set('province_n', '${/model/con632_get_info/record/@liv_province_n}');
                        record.set('city_n', '${/model/con632_get_info/record/@liv_city_n}');
                        record.set('province', '${/model/con632_get_info/record/@liv_province}');
                        record.set('city', '${/model/con632_get_info/record/@liv_city}');
                    }
                }
                if (name == 'visit_address_b') {
                    if (value == 'ID_ADDRESS') {
                        record.set('detailed_address_b', '${/model/con632_get_info/record/@address_on_resident_booklit}');
                        record.set('province_b_n', '${/model/con632_get_info/record/@add_province_n}');
                        record.set('city_b_n', '${/model/con632_get_info/record/@add_city_n}');
                        record.set('province_b', '${/model/con632_get_info/record/@add_province}');
                        record.set('city_b', '${/model/con632_get_info/record/@add_city}');
                    } else if (value == 'LIVIING_ADDRESS') {
                        record.set('detailed_address_b', '${/model/con632_get_info/record/@living_address}');
                        record.set('province_b_n', '${/model/con632_get_info/record/@liv_province_n}');
                        record.set('city_b_n', '${/model/con632_get_info/record/@liv_city_n}');
                        record.set('province_b', '${/model/con632_get_info/record/@liv_province}');
                        record.set('city_b', '${/model/con632_get_info/record/@liv_city}');
                    }
                }
            }
            
            function con_collection_back() {
                $('Collection_tool_id').close();
            }
        ]]></script>
        <a:dataSets>
            <!-- <a:dataSet id="province_ds"  autoQuery="true"  fetchAll="true" model="app.lov.app_fnd_province"/> -->
            <!-- <a:dataSet id="city_ds"  autoQuery="true"  fetchAll="true" model="app.lov.app_fnd_city"/> -->
            <a:dataSet id="ADDRESS_TYPES_ds" lookupCode="ADDRESS_TYPES"/>
            <a:dataSet id="COLLECTION_MEASURES_ds" autoQuery="true" queryUrl="${/request/@context_path}/autocrud/cont.CON630.con_collection_way/query?type_id=${/parameter/@type_id}"/>
            <a:dataSet id="con_collection_tool_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="project_id" defaultValue="${/parameter/@project_id}"/>
                    <a:field name="contract_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="contract_number" defaultValue="${/parameter/@contract_number}" readOnly="true"/>
                    <a:field name="project_number" defaultValue="${/parameter/@project_number}" readOnly="true"/>
                    <a:field name="person" defaultValue="${/parameter/@staff_name}" readOnly="true"/>
                    <a:field name="staff_id" defaultValue="${/parameter/@staff_id}"/>
                    <a:field name="times" defaultValue="${/parameter/@times}" readOnly="true"/>
                    <a:field name="collection_measures_n" displayField="description" options="COLLECTION_MEASURES_ds" required="true" returnField="collection_measures" valueField="methods_name"/>
                    <a:field name="collection_measures"/>
                    <a:field name="visit_address_n" displayField="code_value_name" options="ADDRESS_TYPES_ds" returnField="visit_address" valueField="code_value"/>
                    <a:field name="visit_address"/>
                    <a:field name="province_n" readOnly="true"/>
                    <a:field name="province" readOnly="true"/>
                    <a:field name="city_n" readOnly="true"/>
                    <a:field name="city" readOnly="true"/>
                    <a:field name="visit_address_b_n" displayField="code_value_name" options="ADDRESS_TYPES_ds" returnField="visit_address_b" valueField="code_value"/>
                    <a:field name="visit_address_b"/>
                    <a:field name="province_b_n" readOnly="true"/>
                    <a:field name="province_b" readOnly="true"/>
                    <a:field name="city_b_n" readOnly="true"/>
                    <a:field name="city_b" readOnly="true"/>
                    <a:field name="detailed_address" readOnly="true"/>
                    <a:field name="detailed_address_b" readOnly="true"/>
                    <a:field name="register_record"/>
                    <a:field name="lawsuit_reason"/>
                    <a:field name="take_reason"/>
                    <a:field name="take_imformation_add"/>
                    <!-- <a:field name="collection_cost" required="true"/> -->
                </a:fields>
                <a:events>
                    <a:event name="update" handler="con_collection_tool_update"/>
                </a:events>
            </a:dataSet>
            <!--  <a:dataSet id="con_collection_tool_ds" model="cont.CON632.con_collection_tool" queryDataSet=""/> -->
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="con_collection_back" text="退出"/>
                <a:gridButton click="con_collection_save" text="提交"/>
            </a:screenTopToolbar>
            <a:form labelWidth="100" title="催收工具" width="950">
                <a:hBox>
                    <a:textField name="contract_number" bindTarget="con_collection_tool_query_ds" prompt="合同编号"/>
                    <a:textField name="project_number" bindTarget="con_collection_tool_query_ds" prompt="申请编号"/>
                    <a:datePicker name="times" bindTarget="con_collection_tool_query_ds" prompt="时间"/>
                    <a:comboBox name="person" bindTarget="con_collection_tool_query_ds" prompt="电催人员"/>
                </a:hBox>
                <a:hBox>
                    <a:comboBox name="collection_measures_n" bindTarget="con_collection_tool_query_ds" prompt="催收措施"/>
                    <a:comboBox name="visit_address_n" bindTarget="con_collection_tool_query_ds" prompt="家访地址A"/>
                    <a:comboBox name="visit_address_b_n" bindTarget="con_collection_tool_query_ds" prompt="家访地址B"/>
                    <!-- <a:placeHolder id="prj_dynamicButton_id"/> -->
                    <!-- <a:numberField name="collection_cost" allowDecimals="true" bindTarget="con_collection_tool_query_ds" decimalPrecision="2" prompt="催收费用"/> -->
                </a:hBox>
                <a:hBox>
                    <a:comboBox name="province_n" bindTarget="con_collection_tool_query_ds" prompt="省A"/>
                    <a:comboBox name="city_n" bindTarget="con_collection_tool_query_ds" prompt="市A"/>
                    <a:textField name="detailed_address" bindTarget="con_collection_tool_query_ds" prompt="详细地址A" width="390"/>
                </a:hBox>
                <a:hBox>
                    <a:comboBox name="province_b_n" bindTarget="con_collection_tool_query_ds" prompt="省B"/>
                    <a:comboBox name="city_b_n" bindTarget="con_collection_tool_query_ds" prompt="市B"/>
                    <a:textField name="detailed_address_b" bindTarget="con_collection_tool_query_ds" prompt="详细地址B" width="390"/>
                </a:hBox>
                <a:hBox>
                    <a:textArea name="register_record" bindTarget="con_collection_tool_query_ds" colspan="2" prompt="登记记录" width="680"/>
                </a:hBox>
                <a:hBox>
                    <a:textArea name="lawsuit_reason" bindTarget="con_collection_tool_query_ds" colspan="2" prompt="诉讼事由" width="680"/>
                </a:hBox>
                <a:hBox>
                    <a:textArea name="take_reason" bindTarget="con_collection_tool_query_ds" colspan="2" prompt="收车原因" width="680"/>
                </a:hBox>
                <a:hBox>
                    <a:textArea name="take_imformation_add" bindTarget="con_collection_tool_query_ds" colspan="2" prompt="收车信息补充" width="680"/>
                </a:hBox>
            </a:form>
        </a:screenBody>
    </a:view>
    <!-- <a:view-config>
        <c:create-config targetId="prj_dynamicButton_id">
            <p:switch test="/parameter/@project_id">
                <p:case value="123">
                    <c:process-config>
                        <a:comboBox name="XXXX" bindTarget="con_collection_tool_query_ds" prompt="分配家访员"/>
                    </c:process-config>
                </p:case>
            </p:switch>
        </c:create-config>
    </a:view-config> -->
</a:screen>