batch-adjust.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import OHeader from '@/components/o-header'
  2. import OPopup from '@/components/o-popup'
  3. import OSticky from '@/components/o-sticky'
  4. import { postMessage } from '@/helpers/native-message'
  5. import request from '@/helpers/request'
  6. import { verifiyNumberInteger } from '@/helpers/toolsValidate'
  7. import { browser } from '@/helpers/utils'
  8. import router from '@/router'
  9. import { state } from '@/state'
  10. import dayjs from 'dayjs'
  11. import {
  12. Button,
  13. Cell,
  14. CellGroup,
  15. DatePicker,
  16. Field,
  17. Picker,
  18. Popup,
  19. Radio,
  20. RadioGroup,
  21. Tag
  22. } from 'vant'
  23. import { defineComponent, onMounted, reactive } from 'vue'
  24. import { useRouter } from 'vue-router'
  25. import PracticeClass from '../train-planning/modal/practice-class'
  26. import { forms } from './batch'
  27. import styles from './batch-adjust.module.less'
  28. export default defineComponent({
  29. name: 'batch-adjust',
  30. setup() {
  31. const router = useRouter()
  32. const form = reactive({
  33. submitLoading: false
  34. })
  35. // 获取乐团列表
  36. const getOrchestra = async () => {
  37. try {
  38. const { data } = await request.post('/api-school/orchestra/page', {
  39. data: {
  40. page: 1,
  41. rows: 100,
  42. schoolId: state.user.data.school.id,
  43. status: 'DONE'
  44. }
  45. })
  46. forms.orchestraList = data.rows || []
  47. // 初始化显示选中第一个乐团
  48. if (forms.orchestraList.length > 0) {
  49. const temp = forms.orchestraList[0]
  50. forms.orchestraId = temp.id
  51. forms.orchestraName = temp.name
  52. }
  53. } catch {
  54. //
  55. }
  56. }
  57. const onSubmit = async () => {
  58. try {
  59. form.submitLoading = true
  60. const { data } = await request.post('/api-school/courseSchedule/batchAdjust', {
  61. hideLoading: true,
  62. data: {
  63. adjustDay: forms.changeType ? '-' + forms.adjustDay : forms.adjustDay,
  64. classGroupIdList: forms.classGroupIdList,
  65. startTime: forms.startTime.join('-'),
  66. endTime: forms.endTime.join('-')
  67. }
  68. })
  69. form.submitLoading = false
  70. router.push({
  71. path: '/course-preview',
  72. query: {
  73. cacheId: data
  74. }
  75. })
  76. } catch {
  77. //
  78. form.submitLoading = false
  79. }
  80. }
  81. const onFormatterInt = (val: any) => {
  82. if (val && val >= 1) {
  83. return verifiyNumberInteger(val)
  84. } else {
  85. return ''
  86. }
  87. }
  88. onMounted(() => {
  89. getOrchestra()
  90. })
  91. return () => (
  92. <div class={styles.batchAdjust}>
  93. <OHeader />
  94. <CellGroup inset>
  95. <Cell isLink onClick={() => (forms.orchestraStatus = true)} valueClass={['van-ellipsis']}>
  96. {{ title: () => '乐团名称', value: () => forms.orchestraName }}
  97. </Cell>
  98. <Cell
  99. isLink
  100. onClick={() => {
  101. forms.classStatus = true
  102. }}
  103. >
  104. {{
  105. title: () => '班级',
  106. value: () => (
  107. <div class={styles.value}>
  108. {forms.classGroupIdList.length <= 0 ? (
  109. <div class={styles.tips}>请选择班级</div>
  110. ) : (
  111. <div>
  112. 已选<span style={{ padding: '0 4px' }}>{forms.classGroupIdList.length}</span>
  113. 个班级
  114. </div>
  115. )}
  116. </div>
  117. )
  118. }}
  119. </Cell>
  120. <Field
  121. isLink
  122. label="课程开始日期"
  123. placeholder="请选择课程开始日期"
  124. readonly
  125. inputAlign="right"
  126. modelValue={forms.startTime.join('-')}
  127. onClick={() => {
  128. forms.startTimeStatus = true
  129. }}
  130. />
  131. <Field
  132. isLink
  133. label="课程结束日期"
  134. placeholder="请选择课程结束日期"
  135. readonly
  136. inputAlign="right"
  137. modelValue={forms.endTime.join('-')}
  138. onClick={() => {
  139. forms.endTimeStatus = true
  140. }}
  141. />
  142. <Cell title="调整方式">
  143. {{
  144. value: () => (
  145. <RadioGroup
  146. checked-color="#FF8057"
  147. v-model={forms.changeType}
  148. direction="horizontal"
  149. >
  150. <Tag
  151. size="large"
  152. type="primary"
  153. color={!(forms.changeType === 1) ? '#EAEAEA' : '#FF8057'}
  154. textColor={!(forms.changeType === 1) ? '#AAA' : '#FFF'}
  155. class={styles.radioSection}
  156. round
  157. >
  158. <Radio class={styles.radioItem} name={1}></Radio>提前
  159. </Tag>
  160. <Tag
  161. size="large"
  162. type="primary"
  163. color={!(forms.changeType === 0) ? '#EAEAEA' : '#FF8057'}
  164. textColor={!(forms.changeType === 0) ? '#AAA' : '#FFF'}
  165. class={styles.radioSection}
  166. round
  167. >
  168. <Radio class={styles.radioItem} name={0}></Radio>延后
  169. </Tag>
  170. </RadioGroup>
  171. )
  172. }}
  173. </Cell>
  174. <Field
  175. class={styles.adjustDay}
  176. label="调整天数"
  177. inputAlign="right"
  178. type="number"
  179. v-model={forms.adjustDay}
  180. placeholder="请输入调整天数"
  181. formatter={onFormatterInt}
  182. v-slots={{ extra: () => <span style={{ paddingLeft: '6px' }}>天</span> }}
  183. />
  184. </CellGroup>
  185. <OSticky position="bottom">
  186. <div class={['btnGroup btnMore']} style={{ marginTop: '20px' }}>
  187. <Button
  188. color="#ccc"
  189. round
  190. onClick={() => {
  191. if (browser().isApp) {
  192. postMessage({ api: 'back' })
  193. } else {
  194. router.back()
  195. }
  196. }}
  197. >
  198. 取消
  199. </Button>
  200. <Button
  201. color="#FF8057"
  202. round
  203. onClick={onSubmit}
  204. disabled={form.submitLoading}
  205. loading={form.submitLoading}
  206. >
  207. 下一步
  208. </Button>
  209. </div>
  210. </OSticky>
  211. {/* 乐团列表 */}
  212. <Popup v-model:show={forms.orchestraStatus} position="bottom" round>
  213. <Picker
  214. columns={forms.orchestraList}
  215. columnsFieldNames={{ text: 'name', value: 'id' }}
  216. onCancel={() => (forms.orchestraStatus = false)}
  217. onConfirm={(val: any) => {
  218. const selectedOption = val.selectedOptions[0]
  219. if (forms.orchestraId !== selectedOption.id) {
  220. forms.orchestraId = selectedOption.id
  221. forms.orchestraName = selectedOption.name
  222. forms.classGroupIdList = []
  223. }
  224. forms.orchestraStatus = false
  225. }}
  226. />
  227. </Popup>
  228. {/* 班级 */}
  229. <OPopup
  230. v-model:modelValue={forms.classStatus}
  231. position="bottom"
  232. style={{ background: '#f6f6f6' }}
  233. destroy
  234. >
  235. <PracticeClass
  236. onClose={() => (forms.classStatus = false)}
  237. orchestraId={forms.orchestraId}
  238. selectItem={forms.classGroupIdList}
  239. onConfirm={(val: any) => {
  240. forms.classGroupIdList = val
  241. }}
  242. />
  243. </OPopup>
  244. {/* 开始日期 */}
  245. <Popup v-model:show={forms.startTimeStatus} position="bottom" round>
  246. <DatePicker
  247. // v-model={forms.startTime}
  248. minDate={new Date()}
  249. onCancel={() => (forms.startTimeStatus = false)}
  250. onConfirm={(val: any) => {
  251. forms.startTime = val.selectedValues
  252. forms.startTimeStatus = false
  253. forms.endTime = []
  254. forms.endTimeMinDate = dayjs(forms.startTime.join('-') || new Date()).toDate()
  255. }}
  256. />
  257. </Popup>
  258. {/* 结束日期 */}
  259. <Popup v-model:show={forms.endTimeStatus} position="bottom" round>
  260. <DatePicker
  261. // v-model={forms.endTime}
  262. minDate={forms.endTimeMinDate}
  263. onCancel={() => (forms.endTimeStatus = false)}
  264. onConfirm={(val: any) => {
  265. forms.endTime = val.selectedValues
  266. forms.endTimeStatus = false
  267. }}
  268. />
  269. </Popup>
  270. </div>
  271. )
  272. }
  273. })