index.tsx 11 KB

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