addClassForm.vue 12 KB

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