From ecdac8a738f254db2b2ea28cbe3248f7a6a7eb2b Mon Sep 17 00:00:00 2001
From: mrzcc <121184950@qq.com>
Date: 星期五, 06 三月 2020 16:18:27 +0800
Subject: [PATCH] 优化采购申请组件

---
 WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.js |  108 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.js b/WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.js
index 8a8b622..ca780a8 100644
--- a/WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.js
+++ b/WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.js
@@ -1,46 +1,69 @@
-(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:{
-            roomSelect2Info:{
-                units:[],
-                floorId:'-1',
-                unitId:'-1',
-                roomId:'',
-                unitName:'',
+        data: {
+            roomSelect2Info: {
+                units: [],
+                floorId: '-1',
+                unitId: '-1',
+                roomId: '',
+                unitName: '',
+                roomSelector: {}
             }
         },
-        watch:{
-            roomSelect2Info:{
+        watch: {
+            roomSelect2Info: {
                 deep: true,
-                handler:function(){
-                    vc.emit($props.callBackListener,$props.callBackFunction,vc.component.roomSelect2Info);
+                handler: function () {
+                    vc.emit($props.callBackListener, $props.callBackFunction, this.roomSelect2Info);
                 }
             }
         },
-        _initMethod:function(){
-                vc.component._initRoomSelect2();
+        _initMethod: function () {
+            this._initRoomSelect2();
         },
-        _initEvent:function(){
+        _initEvent: function () {
             //鐩戝惉 modal 鎵撳紑
-           /* $('#'+$props.parentModal).on('show.bs.modal', function () {
-                 vc.component._initUnitSelect2();
-            })*/
-           vc.on('roomSelect2', "transferUnit",function (_param) {
-                vc.copyObject(_param, vc.component.roomSelect2Info);
-           });
+            /* $('#'+$props.parentModal).on('show.bs.modal', function () {
+                  this._initUnitSelect2();
+             })*/
+            vc.on('roomSelect2', "transferRoom", function (_param) {
+                vc.copyObject(_param, this.roomSelect2Info);
+            });
+            vc.on('roomSelect2', 'setRoom', function (_param) {
+                vc.copyObject(_param, this.roomSelect2Info);
+                /*$("#roomSelector").val(_param.roomId).select2();*/
+
+                var option = new Option(_param.roomNum, _param.roomId, true, true);
+                this.roomSelect2Info.roomSelector.append(option);
+            });
+            vc.on('roomSelect2', 'clearRoom', function (_param) {
+                this.roomSelect2Info = {
+                    units: [],
+                    floorId: '-1',
+                    unitId: '-1',
+                    roomId: '',
+                    unitName: '',
+                    roomSelector: {}
+                };
+            });
         },
         methods: {
             _initRoomSelect2: function () {
                 console.log("璋冪敤_initRoomSelect2 鏂规硶");
-                $.fn.modal.Constructor.prototype.enforceFocus = function () {};
+                $.fn.modal.Constructor.prototype.enforceFocus = function () {
+                };
                 $.fn.select2.defaults.set('width', '100%');
-                $('.roomSelector').select2({
+                this.roomSelect2Info.roomSelector = $('#roomSelector').select2({
                     placeholder: '蹇呭~锛岃閫夋嫨鎴垮眿',
+                    allowClear: true,//鍏佽娓呯┖
+                    escapeMarkup: function (markup) {
+                        return markup;
+                    }, // 鑷畾涔夋牸寮忓寲闃叉xss娉ㄥ叆
                     ajax: {
                         url: "/callComponent/roomSelect2/listRoom",
                         dataType: 'json',
@@ -48,47 +71,50 @@
                         data: function (params) {
                             console.log("param", params);
                             var _term = "";
-                            if(params.hasOwnProperty("term")){
+                            if (params.hasOwnProperty("term")) {
                                 _term = params.term;
                             }
                             return {
                                 roomNum: _term,
                                 page: 1,
-                                row:10,
-                                unitId:vc.component.roomSelect2Info.unitId,
-                                communityId:vc.getCurrentCommunity().communityId
+                                row: 10,
+                                unitId: this.roomSelect2Info.unitId,
+                                communityId: vc.getCurrentCommunity().communityId
                             };
                         },
                         processResults: function (data) {
-                            console.log(data, vc.component._filterRoomData(data));
+                            console.log(data, this._filterRoomData(data.rooms));
                             return {
-                                results: vc.component._filterRoomData(data)
+                                results: this._filterRoomData(data.rooms)
                             };
                         },
                         cache: true
                     }
                 });
-                $('.roomSelector').on("select2:select", function (evt) {
+                $('#roomSelector').on("select2:select", function (evt) {
                     //杩欓噷鏄�変腑瑙﹀彂鐨勪簨浠�
                     //evt.params.data 鏄�変腑椤圭殑淇℃伅
-                    console.log('select',evt);
-                    vc.component.roomSelect2Info.roomId = evt.params.data.id;
-                    vc.component.roomSelect2Info.roomNum = evt.params.data.text;
+                    console.log('select', evt);
+                    this.roomSelect2Info.roomId = evt.params.data.id;
+                    this.roomSelect2Info.roomNum = evt.params.data.text;
                 });
 
-                $('.roomSelector').on("select2:unselect", function (evt) {
+                $('#roomSelector').on("select2:unselect", function (evt) {
                     //杩欓噷鏄彇娑堥�変腑瑙﹀彂鐨勪簨浠�
                     //濡傞厤缃產llowClear: true鍚庯紝瑙﹀彂
-                    console.log('unselect',evt)
+                    console.log('unselect', evt);
+                    this.roomSelect2Info.roomId = '';
+                    this.roomSelect2Info.roomNum = '';
+
 
                 });
             },
-            _filterRoomData:function (_rooms) {
+            _filterRoomData: function (_rooms) {
                 var _tmpRooms = [];
                 for (var i = 0; i < _rooms.length; i++) {
                     var _tmpRoom = {
-                        id:_rooms[i].roomId,
-                        text:_rooms[i].roomNum
+                        id: _rooms[i].roomId,
+                        text: _rooms[i].roomNum
                     };
                     _tmpRooms.push(_tmpRoom);
                 }

--
Gitblit v1.8.0