business_contact_list.lview 6.07 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
<?xml version="1.0" encoding="UTF-8"?>

<!--
    $Author: huangtianyang
    $Date: 2018/9/17 上午9:43
    $Revision: 1.0 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view template="default" package="leaf.ui.std">
        <a:link id="contact_list_query_link" model="contact.contact_list" modelaction="query"/>
        <div></div>
        <script type="text/javascript"><![CDATA[
        //查询
        function contact_list_query() {
            $('contact_list_ds').query();
        }

        //重置
        function contact_list_reset() {
            $('contact_list_query_ds').reset();
        }

        //提交
        function contact_list_submit() {
            var selection = user_record.get('user_ids');
            console.log(selection);
            var userIds = selection.join(';');


            Leaf.request({
                url: $('contact_list_query_link').getUrl(),
                scope: userIds,
                para: {
                    user_ids: selection.filter(function (value) {
                        return value != undefined && value != '';
                    }).join()
                },
                success: function (res) {
                    var userIds = this;
                    var records = res.result.record;
                    if (!(res.result.record instanceof Array)) {
                        records = new Array(records);
                    }
                    var users = records.map(function (value) {
                        return value.description;
                    }).join(';');

                    if ('${/parameter/@type}' === 'to') {
                        $('mailCreateDs').data[0].set('mail_to_id', userIds);
                        $('mailCreateDs').data[0].set('mail_to', users);
                    } else {
                        $('mailCreateDs').data[0].set('mail_cc_id', userIds);
                        $('mailCreateDs').data[0].set('mail_cc', users);
                    }

                }
            })

            // var users = selection.map(function (value) {
            //     var arr = $('contact_list_ds').data;
            //     for (var i = 0; i < arr.length; i++) {
            //         if (arr[i].get('user_id') == value) {
            //             return arr[i].get('description');
            //         }
            //     }
            // }).join(';');
            //
            // console.log(users);
            // if ('${/parameter/@type}' === 'to') {
            //     $('mailCreateDs').data[0].set('mail_to_id', userIds);
            //     $('mailCreateDs').data[0].set('mail_to', users);
            // } else {
            //     $('mailCreateDs').data[0].set('mail_cc_id', userIds);
            //     $('mailCreateDs').data[0].set('mail_cc', users);
            // }
        }


        var user_record;
        init_user_ds();

        function contact_list_handler(ds) {


            if ('${/parameter/@type}' === 'to') {
                user_record = $('user_to_ds').data[0];
            } else {
                user_record = $('user_cc_ds').data[0];
            }

            var userIds = user_record.get('user_ids');

            var records = ds.getAll();

            var selecteds = userIds.map(function (value) {
                for (var i = 0; i < records.length; i++) {
                    if (value == records[i].get('user_id')) {
                        return records[i];
                    }
                }
            });
            selecteds.forEach(function (value) {
                ds.select(value);
            });
        }

        function contact_list_select_handler(ds, record) {
            if (user_record.get('user_ids').every(function (value) {
                return value != record.get('user_id');
            })) {
                user_record.get('user_ids').push(record.get('user_id'));
            }
        }

        function contact_list_unselect_handler(ds, record) {
            var arr = user_record.get('user_ids');
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == record.get('user_id')) {
                    arr.splice(i, 1);
                    break;
                }
            }
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="contact_list_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="description"/>
                    <a:field name="user_name"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="contact_list_ds" autoQuery="true" selectable="true" selectionModel="multiple"
                       model="contact.contact_list" fetchAll="true" queryDataSet="contact_list_query_ds">
                <a:events>
                    <a:event name="load" handler="contact_list_handler"/>
                    <a:event name="select" handler="contact_list_select_handler"/>
                    <a:event name="unselect" handler="contact_list_unselect_handler"/>
                </a:events>
            </a:dataSet>

        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <!--<a:BaseViewComponent></a:BaseViewComponent>-->
                <a:gridButton click="contact_list_query" text="HLS.QUERY"/>
                <a:gridButton click="contact_list_reset" text="HLS.RESET"/>
                <a:gridButton click="contact_list_submit" text="HLS.SUBMIT"/>
            </a:screenTopToolbar>
            <a:form column="3" labelWidth="110" title="HLS.QUERY_TITLE">
                <a:textField bindTarget="contact_list_query_ds" name="user_name" prompt="id"/>
                <a:textField bindTarget="contact_list_query_ds" name="description" prompt="用户名"/>
            </a:form>
            <a:grid id="contact_list_grid" autoAdjust="true" bindTarget="contact_list_ds" height="340"
                    width="400" navBar="true">
                <a:columns>
                    <a:column name="user_name" prompt="id"/>
                    <a:column name="description" prompt="用户名"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>