addClassForm.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <u-form-item label="班级名称" prop="name" required>
  5. <u-input v-model="form.name" placeholder="请输入班级名称" />
  6. </u-form-item>
  7. <u-form-item label="课程周期开始时间" prop="startDate" right-icon="arrow-right" required @click.native="startDateShow = true">
  8. <u-input v-model="form.startDate" placeholder="请选择课程周期开始时间" disabled @click="startDateShow = true" />
  9. </u-form-item>
  10. <u-form-item label="课程周期结束时间" prop="endDate" right-icon="arrow-right" required @click.native="endDateShow = true">
  11. <u-input v-model="form.endDate" placeholder="请选择课程周期结束时间" disabled @click="endDateShow = true" />
  12. </u-form-item>
  13. <u-form-item label="上课时间" prop="timeReqList" required label-position="top"></u-form-item>
  14. <u-swipe-action :index="index" v-for="(item, index) in form.timeReqList" :key="item.id" @click="deleteDate" :options="options">
  15. <u-form-item label=" " right-icon="arrow-right" @click.native="toSetDate(index)" label-width="0px">
  16. <text :style="{color: item.week ? '' :'#999999'}">{{item.week ? item.week + '&nbsp;&nbsp;' +item.startTime + '&nbsp;&nbsp;' +item.endTime : '请选择上课时间'}}</text>
  17. </u-form-item>
  18. </u-swipe-action>
  19. <u-form-item label=" " label-width="0px">
  20. <view style="display: flex; justify-content: space-around;">
  21. <u-button type="success" :ripple="true" size="medium" :custom-style="{backgroundColor: '#ff6e3e'}" @click="addDate">新增</u-button>
  22. </view>
  23. </u-form-item>
  24. <u-form-item label="归属场馆" prop="venueName" right-icon="arrow-right" required @click.native="venueShow = true">
  25. <u-input v-model="form.venueName" placeholder="请选择归属场馆" disabled @click="venueShow = true" />
  26. </u-form-item>
  27. <u-form-item label="地址">
  28. <u-input v-model="form.address" disabled placeholder="请输入地址" />
  29. </u-form-item>
  30. <u-form-item label="学生数量" prop="maxStudentCount" required>
  31. <u-input v-model="form.maxStudentCount" type="number" placeholder="请输入学生数量" />
  32. </u-form-item>
  33. </u-form>
  34. <u-popup v-model="classDate" mode="bottom" border-radius="30">
  35. <view class="dateForm">
  36. <u-form :model="selectForm" ref="selectForm" label-width="140">
  37. <u-form-item label="上课时间" prop="week" required>
  38. <u-radio-group v-model="selectForm.week">
  39. <u-radio v-for="(item, index) in weekList" :key="index" :name="item.name">
  40. {{ item.name }}
  41. </u-radio>
  42. </u-radio-group>
  43. </u-form-item>
  44. <u-form-item label="上课时间" prop="startTime" right-icon="arrow-right" required @click.native="()=>{startTimeShow = true;timeType = 1}">
  45. <u-input v-model="selectForm.startTime" placeholder="请选择上课时间" disabled @click="()=>{startTimeShow = true;timeType = 1}" />
  46. </u-form-item>
  47. <u-form-item label="下课时间" prop="endTime" right-icon="arrow-right" required @click.native="()=>{startTimeShow = true;timeType = 2}">
  48. <u-input v-model="selectForm.endTime" placeholder="请选择下课时间" disabled @click="()=>{startTimeShow = true;timeType = 2}" />
  49. </u-form-item>
  50. </u-form>
  51. <u-button type="warning" :ripple="true" :custom-style="{...customStyle, marginTop: '15px'}" @click="setDate()">确定</u-button>
  52. </view>
  53. </u-popup>
  54. <u-picker mode="time" v-model="startDateShow" :params="cycleParams" @confirm="setStartDate"></u-picker>
  55. <u-picker mode="time" v-model="endDateShow" :params="cycleParams" @confirm="setEndDate"></u-picker>
  56. <u-picker mode="time" v-model="startTimeShow" :params="startTimeParams" @confirm="setStartTime"></u-picker>
  57. <u-picker mode="selector" v-model="venueShow" :range="venueList" range-key="name" @confirm="setVenue"></u-picker>
  58. <view class="handle-fix-box">
  59. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">保存</u-button>
  60. </view>
  61. <u-top-tips ref="uTips"></u-top-tips>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. mapGetters
  67. } from 'vuex'
  68. const NET = require('@/utils/request')
  69. const API = require('@/config/api')
  70. export default {
  71. computed: {
  72. ...mapGetters([
  73. 'mainColor',
  74. 'customStyle',
  75. ])
  76. },
  77. data() {
  78. return {
  79. form: {
  80. name: '',
  81. startDate: '',
  82. endDate: '',
  83. address: '',
  84. venueId: '',
  85. venueName: '',
  86. address: '',
  87. maxStudentCount: '',
  88. timeReqList: [{
  89. week: '',
  90. startTime: '',
  91. endTime: '',
  92. }],
  93. },
  94. rules: {
  95. name: [{
  96. required: true,
  97. message: '请输入班级名称',
  98. trigger: 'change'
  99. }],
  100. startDate: [{
  101. required: true,
  102. message: '请选择课程周期开始时间',
  103. trigger: 'change'
  104. }],
  105. endDate: [{
  106. required: true,
  107. message: '请选择课程周期结束时间',
  108. trigger: 'change'
  109. }],
  110. timeReqList: [{
  111. type: 'array',
  112. required: true,
  113. message: '请选择上课时间',
  114. trigger: 'change'
  115. }],
  116. venueName: [{
  117. required: true,
  118. message: '请选择归属场馆',
  119. trigger: 'change'
  120. }],
  121. maxStudentCount: [{
  122. required: true,
  123. message: '请输入学生数量',
  124. trigger: 'change'
  125. }],
  126. },
  127. selectIndex: 0,
  128. selectForm: {
  129. week: '',
  130. startTime: '',
  131. endTime: '',
  132. },
  133. classDate: false,
  134. weekList: [{
  135. name: '周一'
  136. },
  137. {
  138. name: '周二'
  139. },
  140. {
  141. name: '周三'
  142. },
  143. {
  144. name: '周四'
  145. },
  146. {
  147. name: '周五'
  148. },
  149. {
  150. name: '周六'
  151. },
  152. {
  153. name: '周日'
  154. },
  155. ],
  156. startDateShow: false,
  157. endDateShow: false,
  158. cycleParams: {
  159. year: true,
  160. month: true,
  161. day: true,
  162. hour: false,
  163. minute: false,
  164. second: false
  165. },
  166. startTimeShow: false,
  167. startTimeParams: {
  168. year: false,
  169. month: false,
  170. day: false,
  171. hour: true,
  172. minute: true,
  173. second: true
  174. },
  175. venueShow: false,
  176. venueList: [],
  177. options: [{
  178. text: '删除',
  179. style: {
  180. color: '#fa3534'
  181. }
  182. }]
  183. }
  184. },
  185. onLoad() {
  186. NET.request(API.getVenueList, {
  187. page: 1,
  188. size: 10000,
  189. }, 'POST').then(res => {
  190. this.venueList = res.data.row
  191. }).catch(error => {
  192. this.$refs.uTips.show({
  193. title: error.message,
  194. type: 'warning',
  195. })
  196. })
  197. },
  198. onReady() {
  199. this.$refs.form.setRules(this.rules);
  200. },
  201. onShow() {},
  202. methods: {
  203. // 弹出设置时间
  204. toSetDate(index) {
  205. this.selectIndex = index
  206. this.selectForm = {
  207. week: this.form.timeReqList[index].week,
  208. startTime: this.form.timeReqList[index].startTime,
  209. endTime: this.form.timeReqList[index].endTime,
  210. }
  211. this.classDate = true
  212. },
  213. // 删除时间
  214. deleteDate(index, index1) {
  215. if (index1 == 0) {
  216. this.form.timeReqList.splice(index, 1);
  217. }
  218. },
  219. // 新增时间
  220. addDate() {
  221. this.form.timeReqList.push({
  222. week: '',
  223. startTime: '',
  224. endTime: '',
  225. })
  226. },
  227. // 设置课程周期开始时间
  228. setStartDate(date) {
  229. this.form.startDate = date.year + '-' + date.month + '-' + date.day
  230. },
  231. // 设置课程周期结束时间
  232. setEndDate(date) {
  233. this.form.endDate = date.year + '-' + date.month + '-' + date.day
  234. },
  235. // 设置上课时间
  236. setStartTime(date) {
  237. if (this.timeType == 1) {
  238. this.selectForm.startTime = date.hour + ':' + date.minute + ':' + date.second
  239. } else {
  240. this.selectForm.endTime = date.hour + ':' + date.minute + ':' + date.second
  241. }
  242. },
  243. // 设置上课时间
  244. setDate() {
  245. this.form.timeReqList[this.selectIndex] = {
  246. week: this.selectForm.week,
  247. startTime: this.selectForm.startTime,
  248. endTime: this.selectForm.endTime,
  249. }
  250. this.classDate = false
  251. },
  252. // 设置场馆
  253. setVenue(data) {
  254. this.form.venueId = this.venueList[data[0]].id
  255. this.form.venueName = this.venueList[data[0]].name
  256. this.form.address = this.venueList[data[0]].address
  257. },
  258. // 提交表单
  259. submitForm() {
  260. this.$refs.form.validate(valid => {
  261. if (valid) {
  262. NET.request(API.submitClassForm, {
  263. ...this.form,
  264. }, 'POST').then(res => {
  265. uni.removeStorageSync({
  266. key: 'extraLessonsUserList'
  267. })
  268. this.$refs.uTips.show({
  269. title: '提交成功',
  270. type: 'success',
  271. })
  272. setTimeout(() => {
  273. uni.navigateBack()
  274. }, 1000)
  275. }).catch(error => {
  276. this.$refs.uTips.show({
  277. title: error.message,
  278. type: 'warning',
  279. })
  280. })
  281. }
  282. });
  283. },
  284. },
  285. }
  286. </script>
  287. <style>
  288. page {
  289. width: 100%;
  290. height: 100%;
  291. position: relative;
  292. }
  293. </style>
  294. <style lang="scss" scoped>
  295. @import "@/static/css/themes.scss";
  296. .content {
  297. width: 100%;
  298. float: left;
  299. padding: 0 15px 60px 15px;
  300. box-sizing: border-box;
  301. .dateForm {
  302. padding: 20px;
  303. }
  304. }
  305. </style>