index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 class={styles.standard}>
  157. <div class={styles.tips}>
  158. <Icon name="warning" class={styles.icon} />
  159. 标准训练可对交付团进行整学期标准训练排课
  160. </div>
  161. <CellGroup inset class={styles.cellGroup}>
  162. <Field
  163. label="训练开始日期"
  164. placeholder="请选择训练开始日期"
  165. isLink
  166. readonly
  167. inputAlign="right"
  168. onClick={() => (forms.calendarStatus = true)}
  169. modelValue={
  170. forms.trainStartDate ? dayjs(forms.trainStartDate).format('YYYY年MM月DD日') : ''
  171. }
  172. />
  173. <Field
  174. label="训练开始时间"
  175. isLink
  176. readonly
  177. placeholder="请选择训练开始日期"
  178. inputAlign="right"
  179. modelValue={forms.trainStartTime ? dayjs(forms.trainStartTime).format('HH:mm') : ''}
  180. onClick={() => {
  181. if (!forms.trainStartDate) {
  182. showToast('请选择训练开始日期')
  183. return
  184. }
  185. forms.timerStatus = true
  186. }}
  187. />
  188. <Cell title="训练时长" value={forms.trainTimer + '分钟'}></Cell>
  189. <Field
  190. label="训练周次"
  191. placeholder="请选择训练周次"
  192. modelValue={weekFormat(forms.week)}
  193. inputAlign="right"
  194. readonly
  195. />
  196. <Cell
  197. title="训练次数"
  198. isLink={forms.times <= 0 ? false : true}
  199. value={forms.times + '次'}
  200. onClick={() => {
  201. if (forms.times <= 0) return
  202. forms.numberStatus = true
  203. }}
  204. ></Cell>
  205. <Cell title="跳过节假日">
  206. {{
  207. value: () => (
  208. <RadioGroup
  209. checked-color="#FF8057"
  210. v-model={forms.skipHoliday}
  211. direction="horizontal"
  212. onChange={() => {
  213. forms.trainStartDate = null
  214. forms.trainStartTime = null
  215. forms.calendarDate = null
  216. // 初始化日历时间
  217. getList()
  218. }}
  219. >
  220. <Tag
  221. size="large"
  222. type="primary"
  223. color={!(forms.skipHoliday === 1) ? '#EAEAEA' : '#FF8057'}
  224. textColor={!(forms.skipHoliday === 1) ? '#AAA' : '#FFF'}
  225. class={styles.radioSection}
  226. round
  227. >
  228. <Radio class={styles.radioItem} name={1}></Radio>是
  229. </Tag>
  230. <Tag
  231. size="large"
  232. type="primary"
  233. color={!(forms.skipHoliday === 0) ? '#EAEAEA' : '#FF8057'}
  234. textColor={!(forms.skipHoliday === 0) ? '#AAA' : '#FFF'}
  235. class={styles.radioSection}
  236. round
  237. >
  238. <Radio class={styles.radioItem} name={0}></Radio>否
  239. </Tag>
  240. </RadioGroup>
  241. )
  242. }}
  243. </Cell>
  244. </CellGroup>
  245. <OSticky position="bottom">
  246. <div class={'btnGroup'} style={{ marginTop: '24px' }}>
  247. <Button type="primary" block round onClick={onSubmit}>
  248. 下一步
  249. </Button>
  250. </div>
  251. </OSticky>
  252. <Popup v-model:show={forms.weekStatus} position="bottom" round>
  253. <Picker
  254. columns={weekdays}
  255. onCancel={() => (forms.weekStatus = false)}
  256. onConfirm={(val: any) => {
  257. forms.week = val.selectedValues[0]
  258. forms.weekStatus = false
  259. }}
  260. />
  261. </Popup>
  262. {/* 选择训练开始日期 */}
  263. <OPopup v-model:modelValue={forms.calendarStatus} position="bottom" destroy>
  264. <Calendar
  265. list={forms.calendarList}
  266. nextMonth={(date: Date) => getList(date)}
  267. prevMonth={(date: Date) => getList(date)}
  268. onSelect={(date: any) => {
  269. forms.calendarStatus = false
  270. forms.trainStartDate = date
  271. forms.trainStartTime = null
  272. const days = dayjs(date).day()
  273. const selectDays = weekdays[days === 0 ? 6 : days - 1]
  274. forms.week = selectDays.value
  275. forms.calendarList.forEach((item: any) => {
  276. if (dayjs(item.calendarDate).isSame(date)) {
  277. forms.timerList = { ...item }
  278. setTimeout(() => {
  279. forms.timerStatus = true
  280. }, 100)
  281. }
  282. })
  283. }}
  284. onDestory={() => {
  285. if (forms.trainStartDate) {
  286. getList(forms.trainStartDate)
  287. } else {
  288. getList()
  289. }
  290. }}
  291. v-model:calendarDate={forms.calendarDate}
  292. />
  293. </OPopup>
  294. {/* 选择开始时间 */}
  295. <OPopup
  296. v-model:modelValue={forms.timerStatus}
  297. position="bottom"
  298. style={{ background: '#F6F6F6' }}
  299. destroy
  300. >
  301. {forms.timerStatus && (
  302. <Timer
  303. timerList={forms.timerList}
  304. times={forms.trainTimer}
  305. onClose={() => (forms.timerStatus = false)}
  306. onConfirm={(val: any) => {
  307. forms.trainStartTime = val
  308. }}
  309. />
  310. )}
  311. </OPopup>
  312. <Popup v-model:show={forms.numberStatus} position="bottom" round>
  313. <Picker
  314. columns={forms.timerPickerList}
  315. onConfirm={(val: any) => {
  316. const selectedValue = val.selectedValues[0]
  317. forms.times = selectedValue
  318. forms.numberStatus = false
  319. }}
  320. />
  321. </Popup>
  322. <Dialog
  323. v-model:show={forms.status}
  324. message={`您有${forms.classList.length}个班级尚未指定伴学指导,请完成指定后再进行训练规划。`}
  325. messageAlign="left"
  326. confirmButtonText="去设置"
  327. cancelButtonText="暂不设置"
  328. showCancelButton
  329. onConfirm={() => {
  330. forms.classStatus = true
  331. }}
  332. >
  333. {{
  334. title: () => (
  335. <div class={styles.dialogTitle}>
  336. <i></i>
  337. 指定伴学指导
  338. </div>
  339. )
  340. }}
  341. </Dialog>
  342. <Dialog
  343. v-model:show={forms.numberDialogStatus}
  344. message={`暂无可训练次数`}
  345. messageAlign="center"
  346. confirmButtonText="确定"
  347. >
  348. {{
  349. title: () => (
  350. <div class={styles.dialogTitle}>
  351. <i></i>
  352. 训练次数
  353. </div>
  354. )
  355. }}
  356. </Dialog>
  357. <OPopup
  358. v-model:modelValue={forms.classStatus}
  359. position="bottom"
  360. style={{ background: '#F6F6F6' }}
  361. destroy
  362. >
  363. <ClassList
  364. classList={forms.classList}
  365. onClose={() => (forms.classStatus = false)}
  366. onConfirm={() => {
  367. getClasses(false)
  368. }}
  369. />
  370. </OPopup>
  371. </div>
  372. )
  373. }
  374. })