updateClassForm.vue 10 KB

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