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/unitPackage/unit-select2/unitSelect2.js |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 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 fa17fcb..4e98ec9 100644
--- a/WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js
+++ b/WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js
@@ -12,6 +12,7 @@
                 unitId: '-1',
                 unitNum: '',
                 unitName: '',
+                unitSelector: {}
             }
         },
         watch: {
@@ -19,6 +20,7 @@
                 deep: true,
                 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);
                 }
             }
@@ -36,7 +38,19 @@
             });
             vc.on('unitSelect2', 'setUnit', function (_param) {
                 vc.copyObject(_param, this.unitSelect2Info);
-                $(".unitSelector").val(_param.unitId).select2();
+                /* $(".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: {
@@ -45,8 +59,12 @@
                 $.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',
@@ -85,7 +103,9 @@
                 $('#unitSelector').on("select2:unselect", function (evt) {
                     //杩欓噷鏄彇娑堥�変腑瑙﹀彂鐨勪簨浠�
                     //濡傞厤缃產llowClear: true鍚庯紝瑙﹀彂
-                    console.log('unselect', evt)
+                    console.log('unselect', evt);
+                    this.unitSelect2Info.unitId = '-1';
+                    this.unitSelect2Info.unitName = '';
 
                 });
             },

--
Gitblit v1.8.0