addClassForm.vue 11 KB

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