From 69e2baf5518079bfc16cfadc2fb29842fb3de85d Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 14 一月 2020 21:02:48 +0800
Subject: [PATCH] 加入userName

---
 WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js |  110 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js b/WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js
index 5a7d2a3..4e98ec9 100644
--- a/WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js
+++ b/WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js
@@ -1,46 +1,70 @@
-(function(vc){
+(function (vc) {
     vc.extends({
         propTypes: {
-            parentModal:vc.propTypes.string,
-            callBackListener:vc.propTypes.string, //鐖剁粍浠跺悕绉�
-            callBackFunction:vc.propTypes.string //鐖剁粍浠剁洃鍚柟娉�
+            parentModal: vc.propTypes.string,
+            callBackListener: vc.propTypes.string, //鐖剁粍浠跺悕绉�
+            callBackFunction: vc.propTypes.string //鐖剁粍浠剁洃鍚柟娉�
         },
-        data:{
-            unitSelect2Info:{
-                units:[],
-                floorId:'-1',
-                unitId:'',
-                unitNum:'',
-                unitName:'',
+        data: {
+            unitSelect2Info: {
+                units: [],
+                floorId: '-1',
+                unitId: '-1',
+                unitNum: '',
+                unitName: '',
+                unitSelector: {}
             }
         },
-        watch:{
-            unitSelect2Info:{
+        watch: {
+            unitSelect2Info: {
                 deep: true,
-                handler:function(){
-                    vc.emit($props.callBackListener,$props.callBackFunction,vc.component.unitSelect2Info);
+                handler: function () {
+                    vc.emit($props.callBackListener, $props.callBackFunction, this.unitSelect2Info);
+                    console.log('鏄惁鎵ц watch', $props.callBackListener, $props.callBackFunction, this.unitSelect2Info);
+                    vc.emit($namespace, 'roomSelect2', "transferRoom", this.unitSelect2Info);
                 }
             }
         },
-        _initMethod:function(){
-                vc.component._initUnitSelect2();
+        _initMethod: function () {
+            this._initUnitSelect2();
         },
-        _initEvent:function(){
+        _initEvent: function () {
             //鐩戝惉 modal 鎵撳紑
-           /* $('#'+$props.parentModal).on('show.bs.modal', function () {
-                 vc.component._initUnitSelect2();
-            })*/
-           vc.on('unitSelect2', "transferFloor",function (_param) {
-                vc.copyObject(_param, vc.component.unitSelect2Info);
-           });
+            /* $('#'+$props.parentModal).on('show.bs.modal', function () {
+                  this._initUnitSelect2();
+             })*/
+            vc.on('unitSelect2', "transferFloor", function (_param) {
+                vc.copyObject(_param, this.unitSelect2Info);
+            });
+            vc.on('unitSelect2', 'setUnit', function (_param) {
+                vc.copyObject(_param, this.unitSelect2Info);
+                /* $(".unitSelector").val(_param.unitId).select2();*/
+                var option = new Option(_param.unitNum, _param.unitId, true, true);
+                this.unitSelect2Info.unitSelector.append(option);
+            });
+            vc.on('unitSelect2', 'clearUnit', function (_param) {
+                this.unitSelect2Info = {
+                    units: [],
+                    floorId: '-1',
+                    unitId: '-1',
+                    unitNum: '',
+                    unitName: '',
+                    unitSelector: {}
+                };
+            });
         },
         methods: {
             _initUnitSelect2: function () {
                 console.log("璋冪敤_initUnitSelect2 鏂规硶");
-                $.fn.modal.Constructor.prototype.enforceFocus = function () {};
+                $.fn.modal.Constructor.prototype.enforceFocus = function () {
+                };
                 $.fn.select2.defaults.set('width', '100%');
-                $('.unitSelector').select2({
+                this.unitSelect2Info.unitSelector = $('#unitSelector').select2({
                     placeholder: '蹇呭~锛岃閫夋嫨鍗曞厓',
+                    allowClear: true,//鍏佽娓呯┖
+                    escapeMarkup: function (markup) {
+                        return markup;
+                    }, // 鑷畾涔夋牸寮忓寲闃叉xss娉ㄥ叆
                     ajax: {
                         url: "/callComponent/unitSelect2/loadUnits",
                         dataType: 'json',
@@ -48,51 +72,53 @@
                         data: function (params) {
                             console.log("param", params);
                             var _term = "";
-                            if(params.hasOwnProperty("term")){
+                            if (params.hasOwnProperty("term")) {
                                 _term = params.term;
                             }
                             return {
                                 unitNum: _term,
                                 page: 1,
-                                row:10,
-                                floorId:vc.component.unitSelect2Info.floorId,
-                                communityId:vc.getCurrentCommunity().communityId
+                                row: 10,
+                                floorId: this.unitSelect2Info.floorId,
+                                communityId: vc.getCurrentCommunity().communityId
                             };
                         },
                         processResults: function (data) {
-                            console.log(data, vc.component._filterUnitData(data));
+                            console.log(data, this._filterUnitData(data));
                             return {
-                                results: vc.component._filterUnitData(data)
+                                results: this._filterUnitData(data)
                             };
                         },
                         cache: true
                     }
                 });
-                $('.floorSelector').on("select2:select", function (evt) {
+                $('#unitSelector').on("select2:select", function (evt) {
                     //杩欓噷鏄�変腑瑙﹀彂鐨勪簨浠�
                     //evt.params.data 鏄�変腑椤圭殑淇℃伅
-                    console.log('select',evt);
-                    vc.component.unitSelect2Info.unitId = evt.params.data.id;
-                    vc.component.unitSelect2Info.unitName = evt.params.data.text;
+                    console.log('select', evt);
+                    this.unitSelect2Info.unitId = evt.params.data.id;
+                    this.unitSelect2Info.unitName = evt.params.data.text;
                 });
 
-                $('.floorSelector').on("select2:unselect", function (evt) {
+                $('#unitSelector').on("select2:unselect", function (evt) {
                     //杩欓噷鏄彇娑堥�変腑瑙﹀彂鐨勪簨浠�
                     //濡傞厤缃產llowClear: true鍚庯紝瑙﹀彂
-                    console.log('unselect',evt)
+                    console.log('unselect', evt);
+                    this.unitSelect2Info.unitId = '-1';
+                    this.unitSelect2Info.unitName = '';
 
                 });
             },
-            _filterUnitData:function (_units) {
+            _filterUnitData: function (_units) {
                 var _tmpUnits = [];
                 for (var i = 0; i < _units.length; i++) {
                     var _tmpUnit = {
-                        id:_units[i].unitId,
-                        text:_units[i].unitNum
+                        id: _units[i].unitId,
+                        text: _units[i].unitNum
                     };
                     _tmpUnits.push(_tmpUnit);
                 }
-                return _tmpUnit;
+                return _tmpUnits;
             }
         }
     });

--
Gitblit v1.8.0