index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. import OPopup from '@/components/o-popup'
  2. import OSticky from '@/components/o-sticky'
  3. import request from '@/helpers/request'
  4. import { state } from '@/state'
  5. import dayjs from 'dayjs'
  6. import {
  7. Button,
  8. Cell,
  9. CellGroup,
  10. Dialog,
  11. Field,
  12. Icon,
  13. Picker,
  14. Popup,
  15. Radio,
  16. RadioGroup,
  17. showToast,
  18. Sticky,
  19. Tag
  20. } from 'vant'
  21. import { defineComponent, onMounted, reactive } from 'vue'
  22. import { useRoute, useRouter } from 'vue-router'
  23. import { weekdays, weekFormat } from '../../create'
  24. import Calendar from '../../modal/calendar'
  25. import ClassList from '../../modal/class-list'
  26. import Timer from '../../modal/timer'
  27. import styles from './index.module.less'
  28. import { forms } from '../../create'
  29. // orchestra
  30. export default defineComponent({
  31. name: 'standard',
  32. props: {
  33. address: {
  34. type: String,
  35. default: ''
  36. }
  37. },
  38. setup(props) {
  39. const route = useRoute()
  40. const router = useRouter()
  41. // const forms = reactive({
  42. // status: false,
  43. // weekStatus: false,
  44. // calendarStatus: false,
  45. // classStatus: false,
  46. // timerStatus: false,
  47. // skipHoliday: 1,
  48. // week: null,
  49. // times: 16,
  50. // classList: [] as any, // 没有设置伴学指导的数据
  51. // calendarList: [] as any,
  52. // calendarDate: null as any,
  53. // trainStartDate: null, // 开始日期
  54. // trainStartTime: null, // 开始时间
  55. // timerList: {} as any, // 可选和不可选时间段
  56. // numberStatus: false,
  57. // numberDialogStatus: false, // 提示暂无训练次数提示
  58. // pickerNum: 16, // 默认16次
  59. // timerPickerList: [] as any // 可排课次数
  60. // })
  61. // 获取排课空闲时间
  62. const getList = async (date?: any) => {
  63. try {
  64. const { data } = await request.post('/api-school/orchestra/trainingPlanTime', {
  65. data: {
  66. schoolId: state.user.data.school.id,
  67. skipHoliday: forms.skipHoliday ? true : false,
  68. type: 'STANDARD',
  69. calendarDate: dayjs(date).format('YYYY-MM-DD')
  70. }
  71. })
  72. forms.calendarList = data || []
  73. } catch {
  74. //
  75. }
  76. }
  77. // 查询没有设置指导老师的班级
  78. const getClasses = async (show = true) => {
  79. try {
  80. const { data } = await request.post('/api-school/classGroup/page', {
  81. data: {
  82. page: 1,
  83. rows: 200,
  84. schoolId: state.user.data.school.id,
  85. hasTeacher: false,
  86. orchestraType: 'DELIVERY'
  87. }
  88. })
  89. // 班级数据
  90. forms.classList = data.rows || []
  91. // 判断没有设置伴学指导的班级
  92. if (forms.classList.length > 0 && show) {
  93. forms.status = true
  94. }
  95. } catch {
  96. //
  97. }
  98. }
  99. // 获取已排课次数
  100. const getStandardCourseNum = async () => {
  101. try {
  102. const { data } = await request.get(
  103. '/api-school/orchestra/semesterStandardCourseNum/' + state.user.data.school.id
  104. )
  105. const tempPicker = Number(forms.pickerNum - data)
  106. forms.times = tempPicker
  107. for (let i = 0; i < tempPicker; i++) {
  108. forms.timerPickerList.push({
  109. text: i + 1 + '次',
  110. value: i + 1
  111. })
  112. }
  113. if (tempPicker <= 0) {
  114. forms.numberDialogStatus = true
  115. }
  116. } catch {
  117. //
  118. }
  119. }
  120. // 下一步
  121. const onSubmit = () => {
  122. // 判断是否有训练次数
  123. if (forms.times <= 0) {
  124. forms.numberDialogStatus = true
  125. return
  126. }
  127. // 判断是否有班级没有设置伴学指导
  128. if (forms.classList.length > 0) {
  129. forms.status = true
  130. return
  131. }
  132. if (!forms.trainStartDate) {
  133. showToast('请选择训练开始日期')
  134. return
  135. }
  136. if (!forms.trainStartTime) {
  137. showToast('请选择训练开始时间')
  138. return
  139. }
  140. if (!forms.week) {
  141. showToast('请选择周次')
  142. return
  143. }
  144. if (!props.address) {
  145. showToast('您所在的学校暂未设置地址')
  146. return
  147. }
  148. router.push('/train-content')
  149. }
  150. onMounted(() => {
  151. getList(forms.calendarDate || new Date())
  152. getClasses()
  153. getStandardCourseNum()
  154. })
  155. return () => (
  156. <div
  157. class={styles.standard}
  158. style={{
  159. minHeight: 'calc(100vh - var(--header-height) - var(--van-tabs-line-height))',
  160. overflow: 'hidden'
  161. }}
  162. >
  163. <div class={styles.tips}>
  164. <Icon name="warning" class={styles.icon} />
  165. 标准训练可对交付团进行整学期标准训练排课
  166. </div>
  167. <CellGroup inset class={styles.cellGroup}>
  168. <Cell title="跳过节假日">
  169. {{
  170. value: () => (
  171. <RadioGroup
  172. checked-color="#FF8057"
  173. v-model={forms.skipHoliday}
  174. direction="horizontal"
  175. onChange={() => {
  176. forms.trainStartDate = null
  177. forms.trainStartTime = null
  178. forms.calendarDate = null
  179. // 初始化日历时间
  180. getList()
  181. }}
  182. >
  183. <Tag
  184. size="large"
  185. type="primary"
  186. color={!(forms.skipHoliday === 1) ? '#EAEAEA' : '#FF8057'}
  187. textColor={!(forms.skipHoliday === 1) ? '#AAA' : '#FFF'}
  188. class={styles.radioSection}
  189. round
  190. >
  191. <Radio class={styles.radioItem} name={1}></Radio>是
  192. </Tag>
  193. <Tag
  194. size="large"
  195. type="primary"
  196. color={!(forms.skipHoliday === 0) ? '#EAEAEA' : '#FF8057'}
  197. textColor={!(forms.skipHoliday === 0) ? '#AAA' : '#FFF'}
  198. class={styles.radioSection}
  199. round
  200. >
  201. <Radio class={styles.radioItem} name={0}></Radio>否
  202. </Tag>
  203. </RadioGroup>
  204. )
  205. }}
  206. </Cell>
  207. <Field
  208. label="训练开始日期"
  209. placeholder="请选择训练开始日期"
  210. isLink
  211. readonly
  212. inputAlign="right"
  213. onClick={() => (forms.calendarStatus = true)}
  214. modelValue={
  215. forms.trainStartDate ? dayjs(forms.trainStartDate).format('YYYY年MM月DD日') : ''
  216. }
  217. />
  218. <Field
  219. label="训练开始时间"
  220. isLink
  221. readonly
  222. placeholder="请选择训练开始日期"
  223. inputAlign="right"
  224. modelValue={forms.trainStartTime ? dayjs(forms.trainStartTime).format('HH:mm') : ''}
  225. onClick={() => {
  226. if (!forms.trainStartDate) {
  227. showToast('请选择训练开始日期')
  228. return
  229. }
  230. forms.timerStatus = true
  231. }}
  232. />
  233. <Cell
  234. title="训练时长"
  235. value={forms.trainTimer + '分钟'}
  236. v-slots={{
  237. 'right-icon': () => <span></span>
  238. }}
  239. ></Cell>
  240. <Field
  241. label="训练周次"
  242. placeholder="请选择训练周次"
  243. modelValue={weekFormat(forms.week)}
  244. inputAlign="right"
  245. readonly
  246. />
  247. <Cell
  248. title="训练次数"
  249. isLink={forms.times <= 0 ? false : true}
  250. value={forms.times + '次'}
  251. onClick={() => {
  252. if (forms.times <= 0) return
  253. forms.numberStatus = true
  254. }}
  255. ></Cell>
  256. </CellGroup>
  257. <OSticky position="bottom" class={styles.informationBottom}>
  258. <div class={'btnGroup'} style={{ marginTop: '24px' }}>
  259. <Button type="primary" block round onClick={onSubmit}>
  260. 下一步
  261. </Button>
  262. </div>
  263. </OSticky>
  264. <Popup v-model:show={forms.weekStatus} position="bottom" round class={'popupBottomSearch'}>
  265. <Picker
  266. columns={weekdays}
  267. onCancel={() => (forms.weekStatus = false)}
  268. onConfirm={(val: any) => {
  269. forms.week = val.selectedValues[0]
  270. forms.weekStatus = false
  271. }}
  272. />
  273. </Popup>
  274. {/* 选择训练开始日期 */}
  275. <OPopup
  276. v-model:modelValue={forms.calendarStatus}
  277. position="bottom"
  278. destroy
  279. teleport={'body'}
  280. >
  281. <Calendar
  282. list={forms.calendarList}
  283. nextMonth={(date: Date) => getList(date)}
  284. prevMonth={(date: Date) => getList(date)}
  285. toDayMonth={(date: Date) => getList(date)}
  286. onSelect={(date: any) => {
  287. forms.calendarStatus = false
  288. forms.trainStartDate = date
  289. forms.trainStartTime = null
  290. const days = dayjs(date).day()
  291. const selectDays = weekdays[days === 0 ? 6 : days - 1]
  292. forms.week = selectDays.value
  293. forms.calendarList.forEach((item: any) => {
  294. if (dayjs(item.calendarDate).isSame(date)) {
  295. forms.timerList = { ...item }
  296. setTimeout(() => {
  297. forms.timerStatus = true
  298. }, 100)
  299. }
  300. })
  301. }}
  302. onDestory={() => {
  303. if (forms.trainStartDate) {
  304. getList(forms.trainStartDate)
  305. } else {
  306. getList()
  307. }
  308. }}
  309. v-model:calendarDate={forms.calendarDate}
  310. />
  311. </OPopup>
  312. {/* 选择开始时间 */}
  313. <OPopup
  314. v-model:modelValue={forms.timerStatus}
  315. position="bottom"
  316. style={{ background: '#F6F6F6' }}
  317. destroy
  318. teleport={'body'}
  319. >
  320. {forms.timerStatus && (
  321. <Timer
  322. timerList={forms.timerList}
  323. times={forms.trainTimer}
  324. onClose={() => (forms.timerStatus = false)}
  325. onConfirm={(val: any) => {
  326. forms.trainStartTime = val
  327. }}
  328. />
  329. )}
  330. </OPopup>
  331. <Popup
  332. v-model:show={forms.numberStatus}
  333. position="bottom"
  334. round
  335. class={'popupBottomSearch'}
  336. teleport={'body'}
  337. >
  338. <Picker
  339. columns={forms.timerPickerList}
  340. onCancel={() => (forms.numberStatus = false)}
  341. onConfirm={(val: any) => {
  342. const selectedValue = val.selectedValues[0]
  343. forms.times = selectedValue
  344. forms.numberStatus = false
  345. }}
  346. />
  347. </Popup>
  348. <Dialog
  349. v-model:show={forms.status}
  350. message={`您有<span style="color: #F44541;">${forms.classList.length}个</span>班级尚未指定伴学指导,请完成指定后再进行训练规划。`}
  351. messageAlign="left"
  352. allowHtml
  353. confirmButtonText="去设置"
  354. cancelButtonText="暂不设置"
  355. teleport={'body'}
  356. showCancelButton
  357. onConfirm={() => {
  358. forms.classStatus = true
  359. }}
  360. >
  361. {{
  362. title: () => (
  363. <div class={styles.dialogTitle}>
  364. <i></i>
  365. 指定伴学指导
  366. </div>
  367. )
  368. }}
  369. </Dialog>
  370. <Dialog
  371. v-model:show={forms.numberDialogStatus}
  372. message={`暂无可训练次数`}
  373. messageAlign="center"
  374. confirmButtonText="确定"
  375. teleport={'body'}
  376. >
  377. {{
  378. title: () => (
  379. <div class={styles.dialogTitle}>
  380. <i></i>
  381. 训练次数
  382. </div>
  383. )
  384. }}
  385. </Dialog>
  386. <OPopup
  387. v-model:modelValue={forms.classStatus}
  388. position="bottom"
  389. style={{ background: '#F6F6F6' }}
  390. destroy
  391. teleport={'body'}
  392. >
  393. <ClassList
  394. classList={forms.classList}
  395. onClose={() => (forms.classStatus = false)}
  396. onConfirm={() => {
  397. getClasses(false)
  398. }}
  399. />
  400. </OPopup>
  401. </div>
  402. )
  403. }
  404. })