<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="acr.ACR603.hls_business_type" rootPath="hls_business_type_list"/>
        <a:model-query fetchAll="true" model="acr.ACR603.hls_cashflow_item" rootPath="hls_cashflow_item_list"/>
        <a:model-query fetchAll="true" model="acr.ACR603.hls_cashflow_type" rootPath="hls_cashflow_type_list"/>
        <a:model-query fetchAll="true" model="acr.ACR603.hls_division" rootPath="hls_division_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="acr_update_link" model="acr.ACR603.ds_tax_class_num" modelaction="batch_update"/>

        <script type="text/javascript"><![CDATA[
        function acr603_information_query() {
            $('ds_tax_class_num_info').query();
        }

        function acr603_information_reset() {
            $('ds_tax_class_num_ds').reset();
        }

        function update_cf_item1(dataSet, record, name, value, oldvalue) {
            $('ds_tax_class_num_ds').getCurrentRecord().set('cf_type_n_f','');

            if (name == 'cf_item'&& value != '1') {

                record.getField('cf_type_n_f').setReadOnly(true);
            } else if (name == 'cf_item' && value == '1') {

                record.getField('cf_type_n_f').setReadOnly(false);
            }
        }

        function update_cf_item2(dataSet, record, name, value, oldvalue) {
            if (dataSet.id == "ds_tax_class_num_info") {
                if (name == 'cf_item') {
                    $('ds_tax_class_num_info').getCurrentRecord().set('cf_type_n', '');
                    $('ds_tax_class_num_info').getCurrentRecord().set('cf_type', '');
                }
                if (name == 'cf_item' && value != '1') {
                    //record.getField('cf_type_n').setReadOnly(true);
                    record.getField('cf_type_n').setRequired(false);
                } else if (name == 'cf_item' && value == '1') {
                    //record.getField('cf_type_n').setReadOnly(false);
                    record.getField('cf_type_n').setRequired(true);
                }
            }
        }

        function acr603_information_grid_add() {
            $('ds_tax_class_num_info').create();
        }

        function acr603_information_remove() {
            var records = $('ds_tax_class_num_info').getSelected();
            if (!records.length) {
                Leaf.showMessage('${l:PROMPT}', '请至少选择一条记录');
                return;
            }
            else {
                $('ds_tax_class_num_info_grid_id').remove();
            }
        }

        function acr603_information_submit() {

            //Leaf.showConfirm('${l:PROMPT}', '是否保存', save_info, null, 100, 300);

            var records = $('ds_tax_class_num_info').getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请至少选择一条数据进行保存!');
                return;
            }
            var post_data = [];

            for (var i = 0; i < records.length; i++) {
                post_data.push({
                    'class_id': records[i].get('class_id'),
                    'contract_type': records[i].get('contract_type'),
                    'division': records[i].get('division'),
                    'cf_item': records[i].get('cf_item'),
                    'tax_class_num': records[i].get('tax_class_num'),
                    'goods_version': records[i].get('goods_version'),
                    '_status': 'update'
                });
            }
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('acr_update_link').getUrl(),
                para: post_data,
                success: function () {
                    $('ds_tax_class_num_info').query();
                    Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
                }, failure: function () {
                    Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
                },
                scope: this
            });


        }

        function save_info() {
            $('ds_tax_class_num_info').submit();
        }

        function version_valid(record, name, value) {
            debugger;
            if (value != null && value != "") {
                var isVersion = /^[1-9][0-9]*$/;
                if (isVersion.test(value)) {
                    return true;
                }
                else {
                    return '编码版本号错误!';
                }
            } else {
                return true;
            }
        }


        ]]></script>
        <a:dataSets>
            <a:dataSet id="contract_type_options">
                <a:datas dataSource="/model/hls_business_type_list"/>
            </a:dataSet>
            <a:dataSet id="division_options">
                <a:datas dataSource="/model/hls_division_list"/>
            </a:dataSet>
            <a:dataSet id="cf_item_options">
                <a:datas dataSource="/model/hls_cashflow_item_list"/>
            </a:dataSet>
            <a:dataSet id="cf_type_options">
                <a:datas dataSource="/model/hls_cashflow_type_list"/>
            </a:dataSet>
            <a:dataSet id="ds_tax_class_num_ds">
                <a:fields>
                    <a:field name="contract_type"/>
                    <a:field name="contract_type_n" options="contract_type_options" displayField="description"
                             returnField="contract_type" valueField="business_type"/>
                    <a:field name="division"/>
                    <a:field name="division_n" options="division_options" displayField="description"
                             returnField="division" valueField="division"/>
                    <a:field name="cf_item"/>
                    <a:field name="cf_item_n" options="cf_item_options" displayField="description" returnField="cf_item"
                             valueField="cf_item"/>
                    <!-- <a:field name="cf_type" />
                     <a:field name="cf_type_n_f" options="cf_type_options" displayField="description" returnField="cf_type" valueField="cf_type" />-->
                </a:fields>
                <a:events>
                    <a:event name="update" handler="update_cf_item1"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="ds_tax_class_num_info" selectable="true" fetchAll="true" model="acr.ACR603.ds_tax_class_num"
                       queryDataSet="ds_tax_class_num_ds" autoQuery="true">
                <a:fields>
                    <a:field name="contract_type"/>
                    <a:field name="contract_type_n" options="contract_type_options" displayField="description"
                             returnField="contract_type" valueField="business_type" required="true" prompt="合同类型"/>
                    <a:field name="division"/>
                    <a:field name="division_n" options="division_options" displayField="description"
                             returnField="division" valueField="division" required="true" prompt="产品线"/>
                    <a:field name="cf_item"/>
                    <a:field name="cf_item_n" options="cf_item_options" displayField="description" returnField="cf_item"
                             valueField="cf_item" required="true" prompt="现金流项目"/>
                    <a:field name="cf_type"/>
                    <!--<a:field name="cf_type_n" options="cf_type_options" displayField="description" returnField="cf_type" valueField="cf_type" readOnly="true" prompt="本金/利息"/>-->
                    <a:field name="tax_class_num" required="true"/>
                    <a:field name="goods_version" validator="version_valid" required="true" prompt="编码版本号"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="update_cf_item2"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="acr603_information_query" text="查询"/>
                <a:gridButton click="acr603_information_reset" text="重置"/>
                <a:gridButton click="acr603_information_grid_add" text="新增"/>
                <a:gridButton click="acr603_information_remove" text="删除"/>
                <a:gridButton click="acr603_information_submit" text="保存"/>
            </a:screenTopToolbar>
            <a:form style="width:100%" title="查询条件">
                <a:hBox column="5">
                    <a:comboBox name="contract_type_n" bindTarget="ds_tax_class_num_ds" prompt="合同类型"/>
                    <a:comboBox name="division_n" bindTarget="ds_tax_class_num_ds" prompt="产品线"/>
                    <a:comboBox name="cf_item_n" bindTarget="ds_tax_class_num_ds" prompt="现金流项目"/>
                    <!-- <a:comboBox name="cf_type_n_f"  bindTarget="ds_tax_class_num_ds" prompt="本金/利息"/>-->
                    <a:textField name="tax_class_num" bindTarget="ds_tax_class_num_ds" prompt="税收编号"/>
                </a:hBox>
            </a:form>
            <a:grid id="ds_tax_class_num_info_grid_id" bindTarget="ds_tax_class_num_info" marginHeight="121"
                    marginWidth="45" navBar="true">
                <a:columns>
                    <a:column name="contract_type_n" editor="acr603_ds_tx_cb" prompt="合同类型" width="180"/>
                    <a:column name="division_n" editor="acr603_ds_tx_cb" prompt="产品线" width="180"/>
                    <a:column name="cf_item_n" editor="acr603_ds_tx_cb" prompt="现金流项目" width="180"/>
                    <!--<a:column name="cf_type_n" editor="acr603_ds_tx_cb"  prompt="本金/利息" width="180"/>-->
                    <a:column name="tax_class_num" editor="acr603_ds_tx_tf" prompt="税收编号" width="180"/>
                    <a:column name="goods_version" editor="acr603_ds_tx_tf" prompt="编码版本号" width="180"/>
                </a:columns>
                <a:editors>
                    <a:textField id="acr603_ds_tx_tf"/>
                    <a:comboBox id="acr603_ds_tx_cb"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>