ActivityAdd.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div>
  3. <b-card-code title="Horizontal Form">
  4. <b-form @submit.prevent>
  5. <b-row>
  6. <b-col cols="12">
  7. <b-form-group label="活動名稱" label-for="activity-name" label-cols-md="4">
  8. <b-form-input v-model="activity_name" id="activity-name" placeholder="活動名稱" />
  9. </b-form-group>
  10. </b-col>
  11. <b-col cols="12">
  12. <b-form-group label="活動時間" label-for="date" label-cols-md="4">
  13. <b-form-input v-model="date" id="date" type="date" placeholder="活動時間" />
  14. </b-form-group>
  15. </b-col>
  16. <b-col cols="12">
  17. <b-form-group label="活動地點" label-for="place" label-cols-md="4">
  18. <b-form-input v-model="place" id="place" placeholder="活動地點" />
  19. </b-form-group>
  20. </b-col>
  21. <b-col cols="12">
  22. <b-form-group label="報名截止時間" label-for="deadline" label-cols-md="4">
  23. <b-form-input v-model="deadline" id="deadline" type="time" placeholder="報名截止時間" />
  24. </b-form-group>
  25. </b-col>
  26. <!-- submit and reset -->
  27. <b-col offset-md="4">
  28. <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" type="submit" variant="primary"
  29. class="mr-1" @click="postData">
  30. 送出
  31. </b-button>
  32. <b-button v-ripple.400="'rgba(186, 191, 199, 0.15)'" type="reset" variant="outline-secondary">
  33. 取消
  34. </b-button>
  35. </b-col>
  36. </b-row>
  37. </b-form>
  38. </b-card-code>
  39. <!--TODO 匯入excel功能-->
  40. <b-form-file ref="prizeList" placeholder="匯入獎項列表" drop-placeholder="Drop file here..."
  41. accept=".xls, .xlsx, .csv" @change="importFile($event, 'prize')"></b-form-file>
  42. <b-form-file ref="guestList" placeholder="匯入來賓列表" drop-placeholder="Drop file here..."
  43. accept=".xls, .xlsx, .csv" @change="importFile($event, 'guest')"></b-form-file>
  44. <b-modal ref="confirm-modal" title="成功設定活動" centered ok-only ok-title="確認">
  45. <b-card-text>
  46. 已成功設定活動資訊!
  47. </b-card-text>
  48. </b-modal>
  49. <b-modal ref="insert-success-modal" title="成功上傳" ok-only ok-title="確認">
  50. <b-card-text>
  51. 成功上傳資料。
  52. </b-card-text>
  53. </b-modal>
  54. </div>
  55. </template>
  56. <script>
  57. import BCardCode from '@core/components/b-card-code'
  58. import {
  59. BRow, BCol, BFormGroup, BFormInput, BFormCheckbox, BForm, BButton, BFormFile, BModal, BCardText
  60. } from 'bootstrap-vue'
  61. import Ripple from 'vue-ripple-directive'
  62. import useJwt from '@/auth/jwt/useJwt'
  63. import { getUserData } from '@/auth/utils'
  64. export default {
  65. components: {
  66. BCardCode,
  67. BRow,
  68. BCol,
  69. BFormGroup,
  70. BFormInput,
  71. BFormCheckbox,
  72. BForm,
  73. BButton,
  74. BFormFile,
  75. BModal,
  76. BCardText,
  77. },
  78. directives: {
  79. Ripple,
  80. },
  81. data() {
  82. return {
  83. activities: [],
  84. userData: getUserData(),
  85. activity_name: '',
  86. date: '',
  87. place: '',
  88. deadline: '',
  89. successText: '',
  90. }
  91. },
  92. methods: {
  93. postData() {
  94. useJwt.postData('/api/activity/store',
  95. {
  96. 'activity_name': this.activity_name,
  97. 'date': this.date,
  98. 'place': this.place,
  99. 'user_id': this.userData.user_id,
  100. 'deadline': this.deadline
  101. }).then(response => {
  102. console.log(response);
  103. this.$refs['confirm-modal'].toggle();
  104. }).catch(error => {
  105. console.log("error: " + error);
  106. })
  107. },
  108. importFile(event, option) {
  109. let refOption = option + 'List';
  110. let formData = new FormData();
  111. formData.append('file', event.target.files[0]);
  112. formData.append('option', option);
  113. useJwt.postData('/api/activity/uploadFile', formData).then(response => {
  114. this.successText = response.data.success;
  115. this.$refs['insert-success-modal'].toggle();
  116. this.$refs[refOption].reset();
  117. }).catch(error => {
  118. console.log(error);
  119. });
  120. },
  121. }
  122. }
  123. </script>