瀏覽代碼

Template - Communication

master
Kobus 5 年之前
父節點
當前提交
19692bb531

+ 80
- 17
src/components/communication/templateDetail.vue 查看文件

8
         <div class="col-md-12">
8
         <div class="col-md-12">
9
           <div class="d-flex">
9
           <div class="d-flex">
10
             <div class="p-2 mr-auto">
10
             <div class="p-2 mr-auto">
11
-              <h2>Detailed Item</h2>
11
+              <h2>Template - Detail</h2>
12
             </div>
12
             </div>
13
             <div class="p-2">
13
             <div class="p-2">
14
-              <div class="btn btn-primary myBackground">Add New</div>
14
+              <div class="btn btn-primary myBackground" v-if="!editable" @click="onEdit()">Edit</div>
15
             </div>
15
             </div>
16
             <div class="p-2">
16
             <div class="p-2">
17
-              <div class="btn btn-primary myBackground">Edit</div>
18
-            </div>
19
-            <div class="p-2">
20
-              <div class="btn btn-primary myBackground">Close</div>
17
+              <div class="btn btn-primary myBackground" @click="onClose()">Save/Close</div>
21
             </div>
18
             </div>
22
           </div>
19
           </div>
23
         </div>
20
         </div>
32
                 <b>I</b>
29
                 <b>I</b>
33
               </span>
30
               </span>
34
             </div>
31
             </div>
35
-            <input class="form-control" type="number" step="any" name="levy" v-model="item.id" />
32
+            <input
33
+              class="form-control"
34
+              type="number"
35
+              step="any"
36
+              name="levy"
37
+              v-model="item.id"
38
+              disabled
39
+            />
36
           </div>
40
           </div>
37
         </div>
41
         </div>
38
         <div class="col-md-8 text-left">
42
         <div class="col-md-8 text-left">
43
                 <b>N</b>
47
                 <b>N</b>
44
               </span>
48
               </span>
45
             </div>
49
             </div>
46
-            <input class="form-control" type="text" step="any" name="levy" v-model="item.name" />
50
+            <input
51
+              class="form-control"
52
+              type="text"
53
+              step="any"
54
+              name="levy"
55
+              v-model="item.name"
56
+              :disabled="!editable"
57
+            />
47
           </div>
58
           </div>
48
         </div>
59
         </div>
49
         <div class="col-md-12">
60
         <div class="col-md-12">
57
                 <b>S</b>
68
                 <b>S</b>
58
               </span>
69
               </span>
59
             </div>
70
             </div>
60
-            <input class="form-control" type="text" step="any" name="levy" v-model="item.subject" />
71
+            <input
72
+              class="form-control"
73
+              type="text"
74
+              step="any"
75
+              name="levy"
76
+              v-model="item.subject"
77
+              :disabled="!editable"
78
+            />
61
           </div>
79
           </div>
62
         </div>
80
         </div>
63
         <div class="col-md-12">
81
         <div class="col-md-12">
112
                     step="any"
130
                     step="any"
113
                     name="levy"
131
                     name="levy"
114
                     v-model="item.body"
132
                     v-model="item.body"
133
+                    :disabled="!editable"
115
                   />
134
                   />
116
                 </div>
135
                 </div>
117
               </div>
136
               </div>
135
               <h2>Coded Fields</h2>
154
               <h2>Coded Fields</h2>
136
             </div>
155
             </div>
137
             <div class="p-2">
156
             <div class="p-2">
138
-              <div class="btn btn-primary myBackground" @click="addClose()">{{btnCaption}}</div>
157
+              <div
158
+                class="btn btn-primary myBackground"
159
+                @click="addClose()"
160
+                v-if="editable"
161
+              >{{btnCaption}}</div>
139
             </div>
162
             </div>
140
           </div>
163
           </div>
141
         </div>
164
         </div>
142
-        <div
143
-          class="col-md-12"
144
-          v-if="showNew"
145
-          style="background-color:rgba(255,255,255,0.75); border:silver solid thin;border-radius:10px;padding:10px;padding:10px 30px;"
146
-        >
147
-          <TemplateInnerItem />
165
+        <div class="col-md-12" v-if="showNew">
166
+          <TemplateInnerItem @onItemAdd="onItemAdd" />
148
         </div>
167
         </div>
149
         <div class="col-md-12">
168
         <div class="col-md-12">
150
           <hr />
169
           <hr />
151
         </div>
170
         </div>
152
         <div class="col-md-12">
171
         <div class="col-md-12">
153
-          <ListView :items="item.placeHolders" :hideSearch="true" />
172
+          <ListView
173
+            :items="item.placeHolders"
174
+            :hideSearch="true"
175
+            :showNew="false"
176
+            :deleteable="editable"
177
+            @onDelete="onItemDelete"
178
+          />
154
         </div>
179
         </div>
155
       </div>
180
       </div>
156
     </div>
181
     </div>
157
   </div>
182
   </div>
158
 </template>
183
 </template>
159
 <script>
184
 <script>
185
+import { mapActions } from 'vuex';
160
 import ListView from '../shared/listView.vue';
186
 import ListView from '../shared/listView.vue';
161
 import TemplateInnerItem from './templateInnerItem.vue';
187
 import TemplateInnerItem from './templateInnerItem.vue';
162
 
188
 
172
   },
198
   },
173
   props: {
199
   props: {
174
     item: {},
200
     item: {},
201
+    editable: {
202
+      default: false,
203
+    },
175
   },
204
   },
176
   computed: {
205
   computed: {
177
     btnCaption() {
206
     btnCaption() {
178
       return this.showNew ? 'Close' : 'New';
207
       return this.showNew ? 'Close' : 'New';
179
     },
208
     },
209
+    ItemList() {
210
+      return this.item.placeHolders;
211
+    },
180
   },
212
   },
181
   methods: {
213
   methods: {
214
+    ...mapActions('template', ['addItem', 'editItem']),
182
     addClose() {
215
     addClose() {
183
       if (this.showNew) {
216
       if (this.showNew) {
184
         this.showNew = false;
217
         this.showNew = false;
185
       } else this.showNew = true;
218
       } else this.showNew = true;
186
     },
219
     },
220
+    onClose() {
221
+      if (this.item.id > 0) {
222
+        // edit
223
+        this.editItem(this.item);
224
+      } else {
225
+        // add.
226
+        this.addItem(this.item);
227
+      }
228
+      console.log(JSON.stringify(this.item));
229
+      this.$emit('onClose');
230
+    },
231
+    onItemDelete(item) {
232
+      this.item.placeHolders = _.remove(
233
+        this.item.placeHolders,
234
+        x => x !== item,
235
+      );
236
+    },
237
+    onEdit() {
238
+      this.editable = true;
239
+    },
240
+    onItemAdd(item) {
241
+      const myList = this.item.placeHolders ? this.item.placeHolders : [];
242
+      myList.push({
243
+        name: item.name,
244
+        boundTo: item.property,
245
+        boundToClassDisplay: item.class.name,
246
+        boundToClass: item.class.fullName,
247
+      });
248
+      this.item.placeHolders = myList;
249
+    },
187
   },
250
   },
188
 };
251
 };
189
 </script>
252
 </script>

+ 26
- 1
src/components/communication/templateInnerItem.vue 查看文件

1
 <template>
1
 <template>
2
   <div class="row">
2
   <div class="row">
3
+    <div class="col-md-12" v-if="message !== undefined">
4
+      <Alert :text="message" :type="'ERROR'" />
5
+    </div>
3
     <div class="col-md-3">
6
     <div class="col-md-3">
4
       <input
7
       <input
5
         class="form-control"
8
         class="form-control"
21
       </select>
24
       </select>
22
     </div>
25
     </div>
23
     <div class="col-md-3">
26
     <div class="col-md-3">
24
-      <div class="btn btn-primary myBackground w-100">Add</div>
27
+      <div class="btn btn-primary myBackground w-100" @click="onItemAdd()">Add</div>
25
     </div>
28
     </div>
26
   </div>
29
   </div>
27
 </template>
30
 </template>
28
 <script>
31
 <script>
29
 import { mapState, mapActions } from 'vuex';
32
 import { mapState, mapActions } from 'vuex';
33
+import Alert from '../shared/alert.vue';
30
 
34
 
31
 export default {
35
 export default {
36
+  components: {
37
+    Alert,
38
+  },
32
   mounted() {
39
   mounted() {
33
     this.init();
40
     this.init();
34
   },
41
   },
35
   data() {
42
   data() {
36
     return {
43
     return {
44
+      message: undefined,
37
       item: {
45
       item: {
38
         name: undefined,
46
         name: undefined,
39
         class: undefined,
47
         class: undefined,
49
     onClassChanged() {
57
     onClassChanged() {
50
       this.getProperties(this.item.class);
58
       this.getProperties(this.item.class);
51
     },
59
     },
60
+    onItemAdd() {
61
+      let msg = '';
62
+      if (this.item.name === undefined) {
63
+        msg += 'Please give a name...';
64
+      }
65
+      if (this.item.class == undefined) {
66
+        msg += 'Please choose a class...';
67
+      }
68
+      if (this.item.property == undefined) {
69
+        msg += 'Please choose a property...';
70
+      }
71
+      if (msg.length > 0) {
72
+        this.message = msg;
73
+      } else {
74
+        this.$emit('onItemAdd', this.item);
75
+      }
76
+    },
52
   },
77
   },
53
 };
78
 };
54
 </script>
79
 </script>

+ 11
- 3
src/components/communication/templatePage.vue 查看文件

13
     </div>
13
     </div>
14
     <div class="row">
14
     <div class="row">
15
       <div :class="listClass">
15
       <div :class="listClass">
16
-        <ListView :items="list" @onRowClick="onRowClick" />
16
+        <ListView :items="list" @onRowClick="onRowClick" @onNew="onNew" :showNew="true" />
17
       </div>
17
       </div>
18
       <div class="col-md-6" v-if="showDetailView">
18
       <div class="col-md-6" v-if="showDetailView">
19
-        <DetailView :item="detailItem" />
19
+        <DetailView :item="detailItem" @onClose="onDetailClose" :editable="clickedNew" />
20
       </div>
20
       </div>
21
     </div>
21
     </div>
22
 
22
 
33
   data() {
33
   data() {
34
     return {
34
     return {
35
       detailItem: undefined,
35
       detailItem: undefined,
36
+      clickedNew: false,
36
     };
37
     };
37
   },
38
   },
38
   components: {
39
   components: {
56
   methods: {
57
   methods: {
57
     ...mapActions('template', ['getList']),
58
     ...mapActions('template', ['getList']),
58
     onRowClick(item) {
59
     onRowClick(item) {
59
-      console.log(item);
60
       this.detailItem = item;
60
       this.detailItem = item;
61
+      this.clickedNew = false;
62
+    },
63
+    onNew() {
64
+      this.detailItem = {};
65
+      this.clickedNew = true;
66
+    },
67
+    onDetailClose() {
68
+      this.detailItem = undefined;
61
     },
69
     },
62
   },
70
   },
63
 };
71
 };

+ 11
- 2
src/components/shared/listView.vue 查看文件

2
 /* eslint-disable guard-for-in */
2
 /* eslint-disable guard-for-in */
3
 <template>
3
 <template>
4
   <div>
4
   <div>
5
-    <div class="d-flex justify-content-between" v-if="!hideSearch">
6
-      <div class="p-2">
5
+    <div class="d-flex justify-content-between">
6
+      <div class="p-2" v-if="!hideSearch">
7
         <input v-model="searchItem" class="form-control" placeholder="Search ..." />
7
         <input v-model="searchItem" class="form-control" placeholder="Search ..." />
8
       </div>
8
       </div>
9
+      <div class="p-2" v-if="showNew">
10
+        <div class="btn btn-primary myBackground" @click="onNew()">New</div>
11
+      </div>
9
     </div>
12
     </div>
10
     <div v-if="items && items.length > 0">
13
     <div v-if="items && items.length > 0">
11
       <table id="table" class="table table-bordered table-hover">
14
       <table id="table" class="table table-bordered table-hover">
96
     hideSearch: {
99
     hideSearch: {
97
       default: false,
100
       default: false,
98
     },
101
     },
102
+    showNew: {
103
+      default: true,
104
+    },
99
     items: undefined,
105
     items: undefined,
100
     editable: {
106
     editable: {
101
       default: false,
107
       default: false,
119
     };
125
     };
120
   },
126
   },
121
   methods: {
127
   methods: {
128
+    onNew() {
129
+      this.$emit('onNew');
130
+    },
122
     isObject(item) {
131
     isObject(item) {
123
       return !!item && item.constructor === Object;
132
       return !!item && item.constructor === Object;
124
     },
133
     },

+ 1
- 1
src/components/timeshare/sell/sellPage.vue 查看文件

296
                 </div>
296
                 </div>
297
               </div>
297
               </div>
298
             </div>
298
             </div>
299
-            <DetailIndividual :currentUser="sellItem.owner" :showBank="true" />
299
+            <DetailIndividual :currentUser="sellItem.owner" :showBank="true" :showAddress="true" />
300
             <hr />
300
             <hr />
301
           </div>
301
           </div>
302
           <br />
302
           <br />

+ 17
- 0
src/store/modules/communication/template.js 查看文件

5
   state: {
5
   state: {
6
     list: [],
6
     list: [],
7
     item: {},
7
     item: {},
8
+    message: undefined,
8
   },
9
   },
9
   mutations: {
10
   mutations: {
10
     setList(state, list) {
11
     setList(state, list) {
21
         .then(result => commit('setList', result.data))
22
         .then(result => commit('setList', result.data))
22
         .catch(console.error);
23
         .catch(console.error);
23
     },
24
     },
25
+    addItem({
26
+      dispatch,
27
+    }, item) {
28
+      axios
29
+        .post('/api/template', item)
30
+        .then(() => dispatch('getList'))
31
+        .catch(console.error);
32
+    },
33
+    editItem({
34
+      dispatch,
35
+    }, item) {
36
+      axios
37
+        .put(`/api/template/${item.id}`, item)
38
+        .then(() => dispatch('getList'))
39
+        .catch(console.error);
40
+    },
24
   },
41
   },
25
 };
42
 };

Loading…
取消
儲存