maa3606 2 жил өмнө
parent
commit
292f1788e5

+ 19 - 17
resources/js/src/views/lottery/Draw.vue

@@ -18,9 +18,23 @@
         </b-card>
         </b-card>
       </b-col>
       </b-col>
 
 
+      <b-col md="6">
+        <b-card title="抽獎紀錄" style="height:70vh;">
+          <b-table responsive sticky-header=true :items="recipientsList" bordered :fields="recipientsTableFields"
+            style="max-height: 60vh; overflow: auto;">
+            <template #cell(ICON)="data">
+              <div class="text-center">
+                <feather-icon :icon="data.value" />
+              </div>
+            </template>
+          </b-table>
+        </b-card>
+      </b-col>
+
+      <!--Model Start-->
       <b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
       <b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
         <label>獎品:</label>
         <label>獎品:</label>
-        <b-form-input v-model="prizeName" :disabled=true />
+        <b-form-input v-model="drawOption.prize_name" :disabled=true />
         <br>
         <br>
         <label>地區: </label>
         <label>地區: </label>
         <v-select multiple v-model="drawOption.region" :options="regionOption" />
         <v-select multiple v-model="drawOption.region" :options="regionOption" />
@@ -92,19 +106,7 @@
           Accept
           Accept
         </b-button>
         </b-button>
       </b-modal>
       </b-modal>
-
-      <b-col md="6">
-        <b-card title="抽獎紀錄" style="height:70vh;">
-          <b-table responsive sticky-header=true :items="recipientsList" bordered :fields="recipientsTableFields"
-            style="max-height: 60vh; overflow: auto;">
-            <template #cell(ICON)="data">
-              <div class="text-center">
-                <feather-icon :icon="data.value" />
-              </div>
-            </template>
-          </b-table>
-        </b-card>
-      </b-col>
+      <!--Model End-->
     </b-row>
     </b-row>
   </div>
   </div>
 </template>
 </template>
@@ -146,10 +148,10 @@ export default {
       recipientsTableFields: ['prize_name', 'user_id', 'user_name', 'created_at'],
       recipientsTableFields: ['prize_name', 'user_id', 'user_name', 'created_at'],
       regionOption: ['北區', '中區', '南區', '來賓'],
       regionOption: ['北區', '中區', '南區', '來賓'],
 
 
-      prizeName: '',
       drawOption: {
       drawOption: {
         activity_id: this.$route.params.activity_id,
         activity_id: this.$route.params.activity_id,
         prize_id: '0',
         prize_id: '0',
+        prize_name: '',
         region: ['北區', '中區', '南區', '來賓'],
         region: ['北區', '中區', '南區', '來賓'],
         draw_one: true,
         draw_one: true,
       },
       },
@@ -185,7 +187,7 @@ export default {
         + ':' + d.getMinutes().toString().padStart(2, '0')
         + ':' + d.getMinutes().toString().padStart(2, '0')
         + ':' + d.getSeconds().toString().padStart(2, '0');
         + ':' + d.getSeconds().toString().padStart(2, '0');
     },
     },
-    counterId(id){
+    counterId(id) {
       return 'counter_' + id;
       return 'counter_' + id;
     },
     },
     showDraw() {
     showDraw() {
@@ -221,7 +223,7 @@ export default {
     click(params) {
     click(params) {
       this.drawList = [];
       this.drawList = [];
       if (params.count > 0) {
       if (params.count > 0) {
-        this.prizeName = params.name;
+        this.drawOption.prize_name = params.name;
         this.drawOption.prize_id = params.id;
         this.drawOption.prize_id = params.id;
         this.showDraw();
         this.showDraw();
       } else {
       } else {

+ 46 - 87
resources/js/src/views/lottery/Slot.vue

@@ -2,7 +2,7 @@
 	<div ref="body">
 	<div ref="body">
 
 
 		<div class="prize">
 		<div class="prize">
-			<span class="prize-text">{{ prizeName }}</span>
+			<span class="prize-text">{{ drawOption.prize_name }}</span>
 		</div>
 		</div>
 		<div class="slot counter_0">
 		<div class="slot counter_0">
 			<b-row>
 			<b-row>
@@ -37,7 +37,7 @@
 		<!--Model Start-->
 		<!--Model Start-->
 		<b-modal ref="draw-menu" title="獎項列表" centered no-stacking hide-footer>
 		<b-modal ref="draw-menu" title="獎項列表" centered no-stacking hide-footer>
 			<b-card style="height:75vh;">
 			<b-card style="height:75vh;">
-				<b-table responsive hover sticky-header=true :items="getPrizeList(prizeList)" bordered :fields="fields"
+				<b-table responsive hover sticky-header=true :items="prizeList" bordered :fields="prizeTableFields"
 					@row-clicked="click" style="max-height: 57vh; overflow: auto;">
 					@row-clicked="click" style="max-height: 57vh; overflow: auto;">
 					<template #cell(ICON)="data">
 					<template #cell(ICON)="data">
 						<div class="text-center">
 						<div class="text-center">
@@ -53,15 +53,17 @@
 		</b-modal>
 		</b-modal>
 		<b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
 		<b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
 			<label>獎品:</label>
 			<label>獎品:</label>
-			<b-form-input v-model="prizeName" :disabled=true />
+			<b-form-input v-model="drawOption.prize_name" :disabled=true />
 			<br>
 			<br>
 			<label>地區: </label>
 			<label>地區: </label>
-			<v-select multiple v-model="region" :options="regionOption" />
+			<v-select multiple v-model="drawOption.region" :options="regionOption" />
+			<br>
+
 			<b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-secondary" block
 			<b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-secondary" block
 				@click="hideModal">
 				@click="hideModal">
 				Close
 				Close
 			</b-button>
 			</b-button>
-			<b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="primary" block @click="hideModal()">
+			<b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="primary" block @click="hideModal">
 				Accept
 				Accept
 			</b-button>
 			</b-button>
 		</b-modal>
 		</b-modal>
@@ -76,13 +78,13 @@
 		</b-modal>
 		</b-modal>
 		<b-modal ref="add-prize" centered title="加碼" no-stacking hide-footer>
 		<b-modal ref="add-prize" centered title="加碼" no-stacking hide-footer>
 			<label>獎品:</label>
 			<label>獎品:</label>
-			<b-form-input v-model="addPrizeName" />
+			<b-form-input v-model="addPrizeOption.name" />
 			<br>
 			<br>
 			<label>加碼者: </label>
 			<label>加碼者: </label>
-			<b-form-input v-model="addPrizeUser" />
+			<b-form-input v-model="addPrizeOption.provider" />
 			<br>
 			<br>
 			<label>數量: </label>
 			<label>數量: </label>
-			<b-form-spinbutton v-model="addPrizeNumber" min="1" />
+			<b-form-spinbutton v-model="addPrizeOption.count" min="1" />
 
 
 			<b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-secondary" block
 			<b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-secondary" block
 				@click="hideModal">
 				@click="hideModal">
@@ -149,8 +151,6 @@ export default {
 			activity: {},
 			activity: {},
 			userList: [],
 			userList: [],
 			departmentList: [],
 			departmentList: [],
-			prizeList: [],
-			recipientsList: [],
 
 
 			fields: ['獎項', '數量'],
 			fields: ['獎項', '數量'],
 			regionOption: ['北區', '中區', '南區', '來賓'],
 			regionOption: ['北區', '中區', '南區', '來賓'],
@@ -170,9 +170,6 @@ export default {
 			notDrawnCount: 0,
 			notDrawnCount: 0,
 			isDrawn: false,
 			isDrawn: false,
 
 
-			addPrizeName: '',
-			addPrizeUser: '',
-			addPrizeNumber: 1,
 			departments: [
 			departments: [
 				"行管部庶務科",
 				"行管部庶務科",
 				"人力資源科",
 				"人力資源科",
@@ -211,6 +208,25 @@ export default {
 				"來賓"
 				"來賓"
 			],
 			],
 			messages: [],
 			messages: [],
+			prizeList: [],
+
+			prizeTableFields: ['name', 'provider', 'count'],
+			recipientsTableFields: ['prize_name', 'user_id', 'user_name', 'created_at'],
+			regionOption: ['北區', '中區', '南區', '來賓'],
+
+			drawOption: {
+				activity_id: this.$route.params.activity_id,
+				prize_id: '0',
+				prize_name: '',
+				region: ['北區', '中區', '南區', '來賓'],
+				draw_one: true,
+			},
+			addPrizeOption: {
+				activity_id: this.$route.params.activity_id,
+				name: '',
+				provider: '',
+				count: 1,
+			},
 		}
 		}
 	},
 	},
 	created() {
 	created() {
@@ -226,18 +242,14 @@ export default {
 			let message = data.message
 			let message = data.message
 			console.log(message);
 			console.log(message);
 
 
-			
-			if (message == "addPrize") {
+
+			if (message == "updateData") {
 				this.updateDataset()
 				this.updateDataset()
-			} else if (message && message.id) {
+			} else if (message && message.prize_id) {
 				this.clearResult()
 				this.clearResult()
-				this.prizeName = this.getPrizeName(message.id);
-				this.prizeId = message.id;
-				this.drawOne = true;
-				this.drawMax = message["數量"];
+				this.drawOption = message;
 				this.drawList = [];
 				this.drawList = [];
 			}
 			}
-
 		});
 		});
 
 
 		useJwt.postData('/api/activity/show', { activity_id: this.activityId }).then(res => {
 		useJwt.postData('/api/activity/show', { activity_id: this.activityId }).then(res => {
@@ -252,14 +264,10 @@ export default {
 			this.userList = res.data;
 			this.userList = res.data;
 		});
 		});
 
 
-		useJwt.postData('/api/prize/index_by_activity', { activity_id: this.activityId }).then(res => {
+		useJwt.postData('/api/prize/index_by_activity', { activity_id: this.$route.params.activity_id }).then(res => {
 			this.prizeList = res.data;
 			this.prizeList = res.data;
 		});
 		});
 
 
-		useJwt.postData('/api/recipients/index_by_activity', { activity_id: this.activityId }).then(res => {
-			this.recipientsList = res.data;
-		});
-
 		useJwt.postData('/api/department/index').then(res => {
 		useJwt.postData('/api/department/index').then(res => {
 			this.departmentList = res.data;
 			this.departmentList = res.data;
 		});
 		});
@@ -283,38 +291,9 @@ export default {
 				+ ':' + d.getMinutes().toString().padStart(2, '0')
 				+ ':' + d.getMinutes().toString().padStart(2, '0')
 				+ ':' + d.getSeconds().toString().padStart(2, '0');
 				+ ':' + d.getSeconds().toString().padStart(2, '0');
 		},
 		},
-		getPrizeList(prizeList) {
-			var output = [];
-			prizeList.forEach(element => {
-				output.push({ id: element.id, '獎項': element.name, '數量': element.count });
-			});
-			return output;
-		},
-		getPrizeName(prizeId) {
-			var output = '';
-			this.prizeList.forEach(element => {
-				if (prizeId == element.id) {
-					output = element.name;
-				}
-			});
-			return output;
-		},
-		getRecipientsList(recipientsList) {
-			var output = [];
-			recipientsList.forEach(element => {
-				output.push({ '獎項': this.getPrizeName(element.prize_id), '獲獎人': this.userList[element.user_id], '時間': this.dateFormat(element.created_at) });
-			});
-			return output;
-		},
 		counterId(id) {
 		counterId(id) {
 			return "counter_" + id;
 			return "counter_" + id;
 		},
 		},
-		drawNumber() {
-			if (this.drawOne) {
-				return 1;
-			}
-			return this.drawMax;
-		},
 		showDraw() {
 		showDraw() {
 			this.$refs['draw-modal'].show();
 			this.$refs['draw-modal'].show();
 		},
 		},
@@ -335,42 +314,30 @@ export default {
 			this.updateDataset();
 			this.updateDataset();
 		},
 		},
 		updateDataset() {
 		updateDataset() {
-			useJwt.postData('/api/prize/index_by_activity', { activity_id: this.activityId }).then(res => {
+			useJwt.postData('/api/prize/index_by_activity', { activity_id: this.$route.params.activity_id }).then(res => {
 				this.prizeList = res.data;
 				this.prizeList = res.data;
 			});
 			});
-			useJwt.postData('/api/recipients/index_by_activity', { activity_id: this.activityId }).then(res => {
-				this.recipientsList = res.data;
-			});
 		},
 		},
 		click(params) {
 		click(params) {
-			this.prizeName = this.getPrizeName(params.id);
-			this.prizeId = params.id;
-			this.drawOne = true;
-			this.drawMax = params["數量"];
-			this.drawList = [];
-			if (this.drawMax == 0) {
-				this.showDrawError();
-			} else {
+			if (params.count > 0) {
+				this.drawOption.prize_name = params.name;
+				this.drawOption.prize_id = params.id;
 				this.showDraw();
 				this.showDraw();
+			} else {
+				this.showDrawError();
 			}
 			}
 		},
 		},
 		draw() {
 		draw() {
 			if (!this.isDrawn) {
 			if (!this.isDrawn) {
 				this.isDrawn = true;
 				this.isDrawn = true;
-				useJwt.postData('/api/draw/draw', {
-					activity_id: this.activityId,
-					prize_id: this.prizeId,
-					region: this.region,
-					number: this.drawNumber()
-				}).then(res => {
+				useJwt.postData('/api/draw/draw', this.drawOption).then(res => {
 					if (res.data) {
 					if (res.data) {
 						this.drawList = res.data;
 						this.drawList = res.data;
 						if (this.drawList.length == 1) {
 						if (this.drawList.length == 1) {
-							//this.department_name = this.departmentList[this.drawList[0].department_id];
+							this.department_name = this.drawList[0].department_name;
 							this.user_id = this.drawList[0].user_id;
 							this.user_id = this.drawList[0].user_id;
 							this.user_name = this.drawList[0].user_name;
 							this.user_name = this.drawList[0].user_name;
 						}
 						}
-
 						setTimeout(() => {
 						setTimeout(() => {
 							this.animate();
 							this.animate();
 						}, 500);
 						}, 500);
@@ -391,12 +358,10 @@ export default {
 				});
 				});
 				useJwt.postData('/api/draw/store', {
 				useJwt.postData('/api/draw/store', {
 					users: idList,
 					users: idList,
-					prize_id: String(this.prizeId),
-					number: this.drawNumber()
+					prize_id: this.drawOption.prize_id,
 				}).then(res => {
 				}).then(res => {
 					if (res.data) {
 					if (res.data) {
 						console.log("store success");
 						console.log("store success");
-						this.count();
 					} else {
 					} else {
 						console.log("store error");
 						console.log("store error");
 					}
 					}
@@ -422,19 +387,13 @@ export default {
 			}
 			}
 		},
 		},
 		addPrize() {
 		addPrize() {
-			useJwt.postData('/api/prize/store', {
-				activity_id: this.activityId,
-				name: this.addPrizeName,
-				provider: this.addPrizeUser,
-				count: this.addPrizeNumber
-			}).then(res => {
+			useJwt.postData('/api/prize/store', this.addPrizeOption).then(res => {
 				if (res.data) {
 				if (res.data) {
 					console.log("add prize success");
 					console.log("add prize success");
-					this.hideModal();
 				} else {
 				} else {
 					console.log("add prize error");
 					console.log("add prize error");
 				}
 				}
-
+				this.hideModal();
 			});
 			});
 		},
 		},
 		animate() {
 		animate() {
@@ -443,7 +402,7 @@ export default {
 			var string = numbers;
 			var string = numbers;
 
 
 			this.drawList.forEach((element, index) => {
 			this.drawList.forEach((element, index) => {
-				var departmentName = this.departmentList[element.department_id];
+				var departmentName = element.department_name;
 				var deps = document.querySelectorAll("div.slot.counter_" + index + " > div > div:nth-child(1) > i")
 				var deps = document.querySelectorAll("div.slot.counter_" + index + " > div > div:nth-child(1) > i")
 				var allCounters = document.querySelectorAll("div.slot.counter_" + index + " > div > div:nth-child(2) > span > i");
 				var allCounters = document.querySelectorAll("div.slot.counter_" + index + " > div > div:nth-child(2) > span > i");
 
 

+ 26 - 24
resources/js/src/views/lottery/SlotManager.vue

@@ -18,9 +18,23 @@
 				</b-card>
 				</b-card>
 			</b-col>
 			</b-col>
 
 
+			<b-col md="6">
+				<b-card title="抽獎紀錄" style="height:70vh;">
+					<b-table responsive sticky-header=true :items="recipientsList" bordered
+						:fields="recipientsTableFields" style="max-height: 60vh; overflow: auto;">
+						<template #cell(ICON)="data">
+							<div class="text-center">
+								<feather-icon :icon="data.value" />
+							</div>
+						</template>
+					</b-table>
+				</b-card>
+			</b-col>
+
+			<!--Model Start-->
 			<b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
 			<b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
 				<label>獎品:</label>
 				<label>獎品:</label>
-				<b-form-input v-model="prizeName" :disabled=true />
+				<b-form-input v-model="drawOption.prize_name" :disabled=true />
 				<br>
 				<br>
 				<label>地區: </label>
 				<label>地區: </label>
 				<v-select multiple v-model="drawOption.region" :options="regionOption" />
 				<v-select multiple v-model="drawOption.region" :options="regionOption" />
@@ -65,19 +79,7 @@
 					Accept
 					Accept
 				</b-button>
 				</b-button>
 			</b-modal>
 			</b-modal>
-
-			<b-col md="6">
-				<b-card title="抽獎紀錄" style="height:70vh;">
-					<b-table responsive sticky-header=true :items="recipientsList" bordered
-						:fields="recipientsTableFields" style="max-height: 60vh; overflow: auto;">
-						<template #cell(ICON)="data">
-							<div class="text-center">
-								<feather-icon :icon="data.value" />
-							</div>
-						</template>
-					</b-table>
-				</b-card>
-			</b-col>
+			<!--Model End-->
 		</b-row>
 		</b-row>
 	</div>
 	</div>
 </template>
 </template>
@@ -120,10 +122,10 @@ export default {
 			recipientsTableFields: ['prize_name', 'user_id', 'user_name', 'created_at'],
 			recipientsTableFields: ['prize_name', 'user_id', 'user_name', 'created_at'],
 			regionOption: ['北區', '中區', '南區', '來賓'],
 			regionOption: ['北區', '中區', '南區', '來賓'],
 
 
-			prizeName: '',
 			drawOption: {
 			drawOption: {
 				activity_id: this.$route.params.activity_id,
 				activity_id: this.$route.params.activity_id,
 				prize_id: '0',
 				prize_id: '0',
+				prize_name: '',
 				region: ['北區', '中區', '南區', '來賓'],
 				region: ['北區', '中區', '南區', '來賓'],
 				draw_one: true,
 				draw_one: true,
 			},
 			},
@@ -193,36 +195,36 @@ export default {
 			this.updateDataset();
 			this.updateDataset();
 		},
 		},
 		updateDataset() {
 		updateDataset() {
-			useJwt.postData('/api/prize/index_by_activity', { activity_id: this.activityId }).then(res => {
+			useJwt.postData('/api/prize/index_by_activity', { activity_id: this.$route.params.activity_id }).then(res => {
 				this.prizeList = res.data;
 				this.prizeList = res.data;
 			});
 			});
-			useJwt.postData('/api/recipients/index_by_activity', { activity_id: this.activityId }).then(res => {
+			useJwt.postData('/api/recipients/index_by_activity', { activity_id: this.$route.params.activity_id }).then(res => {
 				this.recipientsList = res.data;
 				this.recipientsList = res.data;
 				this.recipientsList.forEach(element => {
 				this.recipientsList.forEach(element => {
 					element.created_at = this.dateFormat(element.created_at);
 					element.created_at = this.dateFormat(element.created_at);
 				});
 				});
 			});
 			});
 			useJwt.postData('/api/drawManager', {
 			useJwt.postData('/api/drawManager', {
-				message: "addPrize"
+				message: "updateData"
 			}).then(res => {
 			}).then(res => {
 				// console.log(res);
 				// console.log(res);
 			});
 			});
 		},
 		},
 		click(params) {
 		click(params) {
 			if (params.count > 0) {
 			if (params.count > 0) {
-				this.prizeName = params.name;
+				this.drawOption.prize_name = params.name;
 				this.drawOption.prize_id = params.id;
 				this.drawOption.prize_id = params.id;
 				this.showDraw();
 				this.showDraw();
-				useJwt.postData('/api/drawManager', {
-					message: params
-				}).then(res => {
-					// console.log(res);
-				});
 			} else {
 			} else {
 				this.showDrawError();
 				this.showDrawError();
 			}
 			}
 		},
 		},
 		sendDrawOptions() {
 		sendDrawOptions() {
+			useJwt.postData('/api/drawManager', {
+				message: this.drawOption
+			}).then(res => {
+				console.log(res);
+			});
 			this.hideModal();
 			this.hideModal();
 		},
 		},
 		addPrize() {
 		addPrize() {