updateClassForm.vue 7.9 KB

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