index.tsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import OHeader from '@/components/o-header'
  2. import OPopup from '@/components/o-popup'
  3. import OSticky from '@/components/o-sticky'
  4. import { trainCourseEmnu } from '@/constant'
  5. import request from '@/helpers/request'
  6. import { verifiyNumberInteger } from '@/helpers/toolsValidate'
  7. import { state } from '@/state'
  8. import dayjs from 'dayjs'
  9. import { Button, Cell, CellGroup, Field, Popup, showToast, TimePicker } from 'vant'
  10. import { defineComponent, onMounted, reactive } from 'vue'
  11. import { useRouter } from 'vue-router'
  12. import { forms } from '../../create'
  13. import PracticeClass from '../../modal/practice-class'
  14. import styles from './index.module.less'
  15. export default defineComponent({
  16. name: 'practice-detail',
  17. setup() {
  18. const router = useRouter()
  19. const f = reactive({
  20. selectItem: {} as any,
  21. currentTime: [] as any,
  22. minHour: 0,
  23. minMinute: 0,
  24. maxHour: 24,
  25. maxMinute: 60,
  26. firstTime: null as any,
  27. lastTime: null as any
  28. })
  29. const configParams = async () => {
  30. // 获取基础数据
  31. const { data } = await request.get('/api-school/sysParamConfig/queryByParamNameList', {
  32. params: {
  33. paramNames: 'course_start_time,course_end_time'
  34. }
  35. })
  36. const tempData = data || []
  37. tempData.forEach((item: any) => {
  38. console.log(item.paramValue, 'paramValue')
  39. const day = dayjs(forms.trainStartDate).format('YYYY-MM-DD')
  40. if (item.paramName === 'course_start_time') {
  41. const firstTime = dayjs(day + ' ' + item.paramValue)
  42. f.minHour = Number(firstTime.format('HH'))
  43. f.minMinute = Number(firstTime.format('mm'))
  44. f.firstTime = firstTime
  45. } else if (item.paramName === 'course_end_time') {
  46. const lastTime = dayjs(day + ' ' + item.paramValue)
  47. f.maxHour = Number(lastTime.format('HH'))
  48. f.lastTime = lastTime
  49. }
  50. })
  51. }
  52. const onChange = (val: any) => {
  53. // 判断是否选择小时
  54. if (val.columnIndex === 1) return
  55. // 选择时间
  56. const selectHour = Number(val.selectedValues[0])
  57. if (selectHour === f.minHour) {
  58. f.minMinute = Number(f.firstTime.format('mm'))
  59. f.maxMinute = 60
  60. } else if (selectHour === f.maxHour) {
  61. console.log(selectHour, 'hour')
  62. f.minMinute = 0
  63. f.maxMinute = Number(f.lastTime.format('mm'))
  64. } else {
  65. f.minMinute = 0
  66. f.maxMinute = 60
  67. }
  68. }
  69. // 选择日期
  70. const onConfirmTimer = (item: any) => {
  71. const times = dayjs(
  72. dayjs(f.lastTime).format('YYYY-MM-DD') + ' ' + item.selectedValues.join(':') + ':00'
  73. ).add(f.selectItem.trainTimer, 'minute')
  74. if (times.isAfter(f.lastTime)) {
  75. showToast('开始时间超过可选时间范围')
  76. return
  77. }
  78. f.selectItem.startTime = dayjs(
  79. dayjs(f.lastTime).format('YYYY-MM-DD') + ' ' + item.selectedValues.join(':') + ':00'
  80. ).format('YYYY-MM-DD HH:mm:ss')
  81. f.selectItem.endTime = times.format('YYYY-MM-DD HH:mm:ss')
  82. forms.timerStatus = false
  83. }
  84. const checkForms = () => {
  85. const list = forms.classPracticeList
  86. let status = false
  87. let message = ''
  88. list.forEach((item: any) => {
  89. console.log(item)
  90. if (!status && !item.trainTimer) {
  91. status = true
  92. message = '请输入训练时长'
  93. }
  94. if (!status && !item.startTime) {
  95. status = true
  96. message = '请选择开始时间'
  97. }
  98. if (!status && !item.times) {
  99. status = true
  100. message = '请输入课时数'
  101. }
  102. if (!status && item.classIdList.length <= 0) {
  103. status = true
  104. message = '请选择训练班级'
  105. }
  106. })
  107. if (status) {
  108. showToast(message)
  109. }
  110. return status
  111. }
  112. const onSubmit = async () => {
  113. if (checkForms()) return
  114. try {
  115. const list = forms.classPracticeList
  116. const trainingPlanClassList: any = []
  117. list.forEach((item: any) => {
  118. trainingPlanClassList.push({
  119. classGroupIdList: item.classIdList,
  120. courseNum: item.times,
  121. startTime: dayjs(item.startTime).format('HH:mm:ss'),
  122. endTime: dayjs(item.endTime).format('HH:mm:ss'),
  123. singleCourseTime: item.trainTimer
  124. })
  125. })
  126. const params = {
  127. week: forms.week,
  128. schoolId: state.user.data.school.id,
  129. skipHoliday: forms.skipHoliday ? true : false,
  130. type: 'PRACTISE',
  131. startDate: dayjs(forms.trainStartDate).format('YYYY-MM-DD'),
  132. trainingPlanClassList
  133. }
  134. console.log(params)
  135. const { data } = await request.post('/api-school/orchestra/trainingPlanList', {
  136. data: {
  137. ...params
  138. }
  139. })
  140. // 初始化 课程预览时选中的乐团编号 课程预览时选中的课程组编号
  141. forms.selectOrchestraId = null
  142. forms.selectClassGroupId = null
  143. forms.planList = {
  144. orchestra: [] as any, // 所有的乐团
  145. classes: {} as any, // 所有的班级
  146. course: {} as any // 所有的课程
  147. }
  148. console.log(data, 'date')
  149. router.push({
  150. path: '/course-preview',
  151. query: {
  152. cacheId: data
  153. }
  154. })
  155. } catch {
  156. //
  157. }
  158. }
  159. const onFormatterInt = (val: any) => {
  160. if (val && val >= 1) {
  161. return verifiyNumberInteger(val)
  162. } else {
  163. return ''
  164. }
  165. }
  166. onMounted(() => {
  167. configParams()
  168. })
  169. return () => (
  170. <div class={styles.practiceDetail}>
  171. <OHeader />
  172. {forms.classPracticeList.map((item: any) => (
  173. <>
  174. <div class={styles.title}>
  175. <i></i>
  176. {trainCourseEmnu[item.classType]}
  177. </div>
  178. <CellGroup inset class={styles.cellGroup}>
  179. <Field
  180. label="训练时长"
  181. placeholder="请输入训练时长"
  182. inputAlign="right"
  183. v-model={item.trainTimer}
  184. formatter={onFormatterInt}
  185. maxlength={3}
  186. type="tel"
  187. onUpdate:modelValue={(val: any) => {
  188. console.log(val)
  189. item.startTime = null
  190. }}
  191. >
  192. {{ extra: () => <span style={{ paddingLeft: '6px' }}>分钟</span> }}
  193. </Field>
  194. <Field
  195. label="开始时间"
  196. placeholder="请选择开始时间"
  197. inputAlign="right"
  198. readonly
  199. isLink
  200. modelValue={item.startTime ? dayjs(item.startTime).format('HH:mm') : ''}
  201. onClick={() => {
  202. if (!item.trainTimer) {
  203. showToast('请输入训练时长')
  204. return
  205. }
  206. f.selectItem = item
  207. forms.timerStatus = true
  208. }}
  209. />
  210. <Field
  211. label="课时数"
  212. placeholder="请输入课时数"
  213. inputAlign="right"
  214. v-model={item.times}
  215. formatter={onFormatterInt}
  216. maxlength={2}
  217. type="tel"
  218. >
  219. {{ extra: () => <span style={{ paddingLeft: '6px' }}>课时</span> }}
  220. </Field>
  221. <Cell
  222. title="训练班级"
  223. isLink
  224. onClick={() => {
  225. f.selectItem = item
  226. forms.classStatus = true
  227. }}
  228. >
  229. {{
  230. value: () => (
  231. <div class={styles.value}>
  232. {item.classIdList.length <= 0 ? (
  233. <div class={styles.tips}>请选择训练班级</div>
  234. ) : (
  235. <div>
  236. 已选<span style={{ padding: '0 4px' }}>{item.classIdList.length}</span>
  237. 个班级
  238. </div>
  239. )}
  240. </div>
  241. )
  242. }}
  243. </Cell>
  244. </CellGroup>
  245. </>
  246. ))}
  247. <OSticky position="bottom">
  248. <div class={'btnGroup'}>
  249. <Button type="primary" block round onClick={onSubmit}>
  250. 下一步
  251. </Button>
  252. </div>
  253. </OSticky>
  254. <OPopup
  255. v-model:modelValue={forms.classStatus}
  256. position="bottom"
  257. style={{ background: '#f6f6f6' }}
  258. destroy
  259. >
  260. <PracticeClass
  261. onClose={() => (forms.classStatus = false)}
  262. classType={f.selectItem.classType}
  263. selectItem={f.selectItem.classIdList}
  264. onConfirm={(val: any) => {
  265. f.selectItem.classIdList = val
  266. }}
  267. />
  268. </OPopup>
  269. <Popup v-model:show={forms.timerStatus} position="bottom" round>
  270. <TimePicker
  271. v-model={f.currentTime}
  272. minHour={f.minHour}
  273. minMinute={f.minMinute}
  274. maxHour={f.maxHour}
  275. maxMinute={f.maxMinute}
  276. onChange={onChange}
  277. onCancel={() => (forms.timerStatus = false)}
  278. onConfirm={(val: any) => onConfirmTimer(val)}
  279. />
  280. </Popup>
  281. </div>
  282. )
  283. }
  284. })