AddLessonScreen.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <nb-container>
  3. <Header
  4. title="Добавить"
  5. :navigation="this.props.navigation"
  6. :left-button="{
  7. show: true,
  8. icon: 'md-arrow-back',
  9. action: () => this.props.navigation.goBack()
  10. }"
  11. :right-button="{
  12. show: false
  13. }"
  14. :right-second-button="{
  15. show: false
  16. }"
  17. />
  18. <nb-content>
  19. <nb-form>
  20. <nb-separator bordered>
  21. <nb-text>Информация о предмете</nb-text>
  22. </nb-separator>
  23. <nb-content padder>
  24. <nb-item stackedLabel :disabled="setNull">
  25. <nb-label>Название предмета</nb-label>
  26. <nb-input :disabled="setNull" v-model="lesson.name" />
  27. </nb-item>
  28. </nb-content>
  29. <nb-content padder>
  30. <nb-item stackedLabel :disabled="setNull">
  31. <nb-label>Номер аудитории</nb-label>
  32. <nb-input :disabled="setNull" v-model="lesson.audience" />
  33. </nb-item>
  34. </nb-content>
  35. <nb-list-item
  36. class="checkbox-wrapper"
  37. last
  38. :onPress="toggleNullableLesson"
  39. >
  40. <nb-left>
  41. <nb-text>Нет занятия</nb-text>
  42. </nb-left>
  43. <nb-right>
  44. <nb-checkbox
  45. class="checkbox"
  46. :checked="setNull"
  47. :onPress="toggleNullableLesson"
  48. />
  49. </nb-right>
  50. </nb-list-item>
  51. <nb-separator bordered>
  52. <nb-text>День недели</nb-text>
  53. </nb-separator>
  54. <nb-item class="picker" picker last>
  55. <nb-picker
  56. mode="dropdown"
  57. :style="{ width: 350 }"
  58. placeholder="День недели"
  59. placeholderStyle="{ color: '#bfc6ea' }"
  60. placeholderIconColor="#007aff"
  61. :iosIcon="getIosIcon()"
  62. :selectedValue="lesson.day"
  63. :onValueChange="selectDay"
  64. >
  65. <item label="Понедельник" value="monday" />
  66. <item label="Вторник" value="tuesday" />
  67. <item label="Среда" value="wednesday" />
  68. <item label="Четверг" value="thursday" />
  69. <item label="Пятница" value="friday" />
  70. <item label="Суббота" value="saturday" />
  71. </nb-picker>
  72. </nb-item>
  73. <nb-separator bordered>
  74. <nb-text>Выбор недели</nb-text>
  75. </nb-separator>
  76. <nb-list-item
  77. :selected="lesson.week_type === 1"
  78. :onPress="() => lesson.week_type = 1"
  79. last
  80. >
  81. <nb-left>
  82. <nb-text>Нечетная неделя</nb-text>
  83. </nb-left>
  84. <nb-right>
  85. <nb-radio :selected="lesson.week_type === 1" />
  86. </nb-right>
  87. </nb-list-item>
  88. <nb-list-item
  89. :selected="lesson.week_type === 2"
  90. :onPress="() => lesson.week_type = 2"
  91. last
  92. >
  93. <nb-left>
  94. <nb-text>Четная неделя</nb-text>
  95. </nb-left>
  96. <nb-right>
  97. <nb-radio :selected="lesson.week_type === 2"/>
  98. </nb-right>
  99. </nb-list-item>
  100. </nb-form>
  101. <nb-content padder>
  102. <nb-button
  103. class="button"
  104. block
  105. primary
  106. :onPress="addLesson"
  107. >
  108. <nb-spinner v-if="loading" color="#fff"></nb-spinner>
  109. <nb-text v-if="!loading">Добавить</nb-text>
  110. </nb-button>
  111. </nb-content>
  112. </nb-content>
  113. </nb-container>
  114. </template>
  115. <script>
  116. import React from "react";
  117. import { Picker, Icon, Toast } from "native-base";
  118. import Header from "../../components/Header";
  119. import store from "../../store";
  120. export default {
  121. name: 'AddLesson',
  122. components: {
  123. Header,
  124. Item: Picker.Item
  125. },
  126. data() {
  127. return {
  128. lesson: {
  129. name: "",
  130. audience: "",
  131. day: "monday",
  132. week_type: 1,
  133. },
  134. validationError: {
  135. name: false,
  136. audience: false
  137. },
  138. setNull: false,
  139. loading: false
  140. }
  141. },
  142. methods: {
  143. selectDay(value) {
  144. this.lesson.day = value;
  145. },
  146. toggleNullableLesson() {
  147. this.setNull = !this.setNull;
  148. this.lesson.name = (this.setNull) ? 'Нет занятия' : '';
  149. this.lesson.audience = '';
  150. },
  151. getIosIcon() {
  152. return <Icon name="ios-arrow-down-outline" />;
  153. },
  154. async addLesson() {
  155. this.loading = true;
  156. let response = await this.$plugins.f(
  157. 'lesson',
  158. 'POST',
  159. store.state.userObj.api_token,
  160. JSON.stringify(this.lesson),
  161. true
  162. );
  163. if (response.body.status) {
  164. Toast.show({
  165. text: "Предмет успешно добавлен",
  166. buttonText: "ОК",
  167. type: "success",
  168. duration: 3000
  169. });
  170. } else {
  171. Toast.show({
  172. text: "Произошла ошибка, проверьте правильность заполнения полей!",
  173. buttonText: "Закрыть",
  174. type: "danger",
  175. duration: 3000
  176. });
  177. }
  178. this.loading = false;
  179. },
  180. }
  181. }
  182. </script>
  183. <style scoped>
  184. .picker {
  185. border-bottom-width: 0;
  186. }
  187. .checkbox {
  188. margin-right: 2px;
  189. }
  190. .button {
  191. margin-top: 20px;
  192. }
  193. </style>