practice-setting.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import ColField from '@/components/col-field'
  2. import ColFieldGroup from '@/components/col-field-group'
  3. import SubjectModel from '@/business-components/subject-list'
  4. import ColPopup from '@/components/col-popup'
  5. import request from '@/helpers/request'
  6. import { postMessage } from '@/helpers/native-message'
  7. import {
  8. Form,
  9. Radio,
  10. RadioGroup,
  11. Tag,
  12. Sticky,
  13. Button,
  14. Field,
  15. ActionSheet,
  16. CheckboxGroup,
  17. Checkbox,
  18. Dialog,
  19. Toast
  20. } from 'vant'
  21. import { defineComponent } from 'vue'
  22. import styles from './practice-setting.module.less'
  23. import { verifyNumberIntegerAndFloat } from '@/helpers/toolsValidate'
  24. import Timer from './model/timer'
  25. import ColHeader from '@/components/col-header'
  26. export default defineComponent({
  27. name: 'PracticeSetting',
  28. data() {
  29. return {
  30. subjectList: [],
  31. chargeTypeArr: {
  32. 0: '否',
  33. 1: '是'
  34. },
  35. classTimeStatus: false,
  36. subjectStatus: false,
  37. timerStatus: false,
  38. timeSetting: {
  39. courseMinutes: 25,
  40. freeMinutes: 5,
  41. startSetting: '08:00',
  42. endSetting: '18:00'
  43. },
  44. timerObject: {} as any,
  45. form: {
  46. enableFlag: 1,
  47. courseMinutes: null as any,
  48. freeMinutes: 0,
  49. subjectIdTemp: '',
  50. subjectId: [] as any[],
  51. subjectPrice: [] as any[],
  52. skipHolidayFlag: 1,
  53. setting: ''
  54. },
  55. minutes: [] as any,
  56. rate: 0
  57. }
  58. },
  59. computed: {
  60. choiceSubjectId() {
  61. const form = this.form as any
  62. const ids = form.subjectIdTemp ? form.subjectIdTemp.split(',') : []
  63. return ids.map((item: any) => Number(item)) || []
  64. }
  65. },
  66. async mounted() {
  67. try {
  68. // 获取手续费和分钟数
  69. const config = await request.get(
  70. '/api-teacher/sysConfig/queryByParamNameList',
  71. {
  72. params: {
  73. paramNames:
  74. 'practice_times_setting,practice_service_fee,course_start_setting,course_end_setting'
  75. }
  76. }
  77. )
  78. const configData = config.data || []
  79. configData.forEach((item: any) => {
  80. if (item.paramName === 'practice_times_setting') {
  81. const mins = item.paramValue ? JSON.parse(item.paramValue) : []
  82. const tempArr = [] as any
  83. mins.forEach((item: any) => {
  84. tempArr.push({
  85. ...item,
  86. name: item.courseMinutes
  87. })
  88. })
  89. this.minutes = [...tempArr]
  90. }
  91. if (item.paramName === 'practice_service_fee') {
  92. this.rate = item.paramValue
  93. }
  94. if (item.paramName === 'course_start_setting') {
  95. this.timeSetting.startSetting = item.paramValue
  96. }
  97. if (item.paramName === 'course_end_setting') {
  98. this.timeSetting.endSetting = item.paramValue
  99. }
  100. })
  101. //
  102. const teacher = await request.post('/api-teacher/teacher/querySubject')
  103. this.subjectList = teacher.data || []
  104. // 获取课程设置
  105. const setting = await request.post(
  106. '/api-teacher/teacherFreeTime/getDetail',
  107. {
  108. data: {
  109. defaultFlag: 1
  110. }
  111. }
  112. )
  113. const sr = setting.data
  114. if (sr) {
  115. this.timeSetting.courseMinutes = sr.courseMinutes
  116. this.timeSetting.freeMinutes = sr.freeMinutes
  117. this.timerObject = {
  118. monday: sr.monday ? JSON.parse(sr.monday) : [],
  119. tuesday: sr.tuesday ? JSON.parse(sr.tuesday) : [],
  120. wednesday: sr.wednesday ? JSON.parse(sr.wednesday) : [],
  121. thursday: sr.thursday ? JSON.parse(sr.thursday) : [],
  122. friday: sr.friday ? JSON.parse(sr.friday) : [],
  123. saturday: sr.saturday ? JSON.parse(sr.saturday) : [],
  124. sunday: sr.sunday ? JSON.parse(sr.sunday) : []
  125. }
  126. const tempIds: any = []
  127. const tempPrices: any = []
  128. const subjectPrice = sr.subjectPrice || []
  129. subjectPrice.forEach((item: any) => {
  130. tempIds.push(item.subjectId)
  131. tempPrices.push({
  132. subjectId: item.subjectId,
  133. subjectPrice: item.subjectPrice,
  134. subjectName: item.subjectName
  135. })
  136. })
  137. const to = this.timerObject
  138. this.form = {
  139. enableFlag: sr.enableFlag,
  140. courseMinutes: sr.courseMinutes,
  141. freeMinutes: sr.freeMinutes,
  142. subjectIdTemp: tempIds.join(','),
  143. subjectId: tempIds,
  144. subjectPrice: tempPrices,
  145. skipHolidayFlag: sr.skipHolidayFlag,
  146. setting:
  147. to.monday.length > 0 ||
  148. to.tuesday.length > 0 ||
  149. to.wednesday.length > 0 ||
  150. to.thursday.length > 0 ||
  151. to.friday.length > 0 ||
  152. to.saturday.length > 0 ||
  153. to.sunday.length > 0
  154. ? '已设置'
  155. : ''
  156. }
  157. }
  158. } catch {}
  159. },
  160. methods: {
  161. onSelect(item: any) {
  162. // 如果分钟数不同,则清空
  163. if (this.form.courseMinutes !== item.courseMinutes) {
  164. this.timerObject = {}
  165. this.form.setting = ''
  166. }
  167. this.form.courseMinutes = item.courseMinutes
  168. this.form.freeMinutes = item.freeMinutes
  169. },
  170. async onTimer() {
  171. try {
  172. const form = this.form
  173. if (!form.courseMinutes) {
  174. Toast('请选择单课时时长')
  175. return
  176. }
  177. this.timeSetting.courseMinutes = Number(form.courseMinutes)
  178. this.timeSetting.freeMinutes = Number(form.freeMinutes)
  179. this.timerStatus = true
  180. } catch {}
  181. },
  182. onChoiceTimer(item: any, status: boolean) {
  183. this.form.setting = status ? '已设置' : ''
  184. this.timerObject = item
  185. this.timerStatus = false
  186. },
  187. onChoice(item: any) {
  188. console.log(item)
  189. const tempItem = item || []
  190. this.form.subjectId = tempItem
  191. this.form.subjectIdTemp = tempItem.join(',') || ''
  192. const subjectPriceList = [...this.form.subjectPrice]
  193. tempItem.forEach((item: any) => {
  194. const index = subjectPriceList.findIndex(
  195. (subject: any) => subject.subjectId === item
  196. )
  197. if (index === -1) {
  198. subjectPriceList.push({
  199. subjectId: item,
  200. subjectPrice: null as any,
  201. subjectName: ''
  202. })
  203. }
  204. })
  205. const temp: any = []
  206. subjectPriceList.forEach((item: any) => {
  207. const isExist = tempItem.some(
  208. (subjectId: any) => subjectId === item.subjectId
  209. )
  210. isExist && temp.push(item)
  211. })
  212. this.form.subjectPrice = temp
  213. this.subjectStatus = false
  214. },
  215. getSubjectName(id: any) {
  216. const subject: any = this.subjectList.find((item: any) => item.id === id)
  217. return subject ? subject.name : ''
  218. },
  219. onFormatter(val: any) {
  220. return verifyNumberIntegerAndFloat(val)
  221. },
  222. async onSubmit() {
  223. try {
  224. const form = this.form
  225. form.subjectPrice.forEach((item: any) => {
  226. item.subjectName = this.getSubjectName(item.subjectId)
  227. })
  228. await request.post('/api-teacher/teacherFreeTime/upSet', {
  229. data: {
  230. ...form,
  231. ...this.timerObject
  232. }
  233. })
  234. Toast('设置成功')
  235. setTimeout(() => {
  236. postMessage({ api: 'back', content: {} })
  237. }, 500)
  238. } catch {}
  239. }
  240. },
  241. render() {
  242. return (
  243. <Form style={{ paddingTop: '15px' }} onSubmit={this.onSubmit}>
  244. <ColHeader />
  245. <ColFieldGroup>
  246. <ColField title="是否开启陪练课" required border={false}>
  247. <RadioGroup
  248. class={styles['radio-group']}
  249. modelValue={this.form.enableFlag}
  250. onUpdate:modelValue={val => (this.form.enableFlag = val)}
  251. >
  252. {['1', '0'].map((item: string) => {
  253. const isActive = Number(item) === Number(this.form.enableFlag)
  254. const type = isActive ? 'primary' : 'default'
  255. return (
  256. <Radio class={styles.radio} name={item}>
  257. <Tag size="large" plain={isActive} type={type}>
  258. {this.chargeTypeArr[item]}
  259. </Tag>
  260. </Radio>
  261. )
  262. })}
  263. </RadioGroup>
  264. </ColField>
  265. <ColField title="可教授乐器" required>
  266. {this.form.subjectPrice && this.form.subjectPrice.length > 0 && (
  267. <CheckboxGroup
  268. modelValue={this.form.subjectId}
  269. class={styles['checkbox-group']}
  270. disabled
  271. onClick={() => {
  272. this.subjectStatus = true
  273. }}
  274. >
  275. {this.form.subjectPrice.map((item: any) => (
  276. <Checkbox class={styles.checkbox}>
  277. <Tag
  278. plain={true}
  279. type={'primary'}
  280. round
  281. closeable
  282. size="large"
  283. style={{ backgroundColor: '#E9FFF8' }}
  284. onClick={e => {
  285. e.stopPropagation()
  286. e.preventDefault()
  287. }}
  288. onClose={e => {
  289. e.stopPropagation()
  290. e.preventDefault()
  291. Dialog.confirm({
  292. title: '提示',
  293. message: '您是否要删除选择的乐器?',
  294. confirmButtonColor: 'var(--van-primary)'
  295. }).then(() => {
  296. const index = this.form.subjectId.indexOf(
  297. item.subjectId
  298. )
  299. if (index !== -1) {
  300. this.form.subjectId.splice(index, 1)
  301. }
  302. const index2 = this.form.subjectPrice.findIndex(
  303. (subject: any) =>
  304. subject.subjectId === item.subjectId
  305. )
  306. if (index2 !== -1) {
  307. this.form.subjectPrice.splice(index2, 1)
  308. }
  309. this.form.subjectIdTemp =
  310. this.form.subjectId.join(',')
  311. })
  312. }}
  313. >
  314. {this.getSubjectName(item.subjectId)}
  315. {/* {item.subjectName} */}
  316. </Tag>
  317. </Checkbox>
  318. ))}
  319. </CheckboxGroup>
  320. )}
  321. {!this.form.subjectPrice.length && (
  322. <Field
  323. v-model={this.form.subjectIdTemp}
  324. name="courseMinutes"
  325. readonly
  326. onClick={() => {
  327. this.subjectStatus = true
  328. }}
  329. rules={[{ required: true, message: '请选择可教授乐器' }]}
  330. placeholder="请选择可教授乐器"
  331. />
  332. )}
  333. </ColField>
  334. <ColField title="单课时时长" required>
  335. <Field
  336. v-model={this.form.courseMinutes}
  337. name="courseMinutes"
  338. readonly
  339. isLink
  340. onClick={() => {
  341. this.classTimeStatus = true
  342. }}
  343. rules={[{ required: true, message: '请选择单课时时长' }]}
  344. placeholder="请选择单课时时长"
  345. v-slots={{
  346. button: () => <span>分钟</span>
  347. }}
  348. />
  349. </ColField>
  350. </ColFieldGroup>
  351. {this.form.subjectPrice && this.form.subjectPrice.length > 0 && (
  352. <ColFieldGroup>
  353. {this.form.subjectPrice.map((item: any) => (
  354. <ColField
  355. title={`${this.getSubjectName(item.subjectId)}声部陪练价格`}
  356. required
  357. >
  358. <Field
  359. v-model={item.subjectPrice}
  360. name="singleMins"
  361. type="number"
  362. labelWidth={'auto'}
  363. label={`${this.form.courseMinutes || 0}分钟 / `}
  364. rules={[
  365. {
  366. required: true,
  367. message: `请选择声部陪练价格`
  368. }
  369. ]}
  370. formatter={this.onFormatter}
  371. maxlength={8}
  372. placeholder={`请选择声部陪练价格`}
  373. v-slots={{
  374. button: () => <span>元</span>
  375. }}
  376. />
  377. </ColField>
  378. ))}
  379. </ColFieldGroup>
  380. )}
  381. <ColFieldGroup>
  382. <ColField title="可陪练时间段">
  383. <Field
  384. modelValue={this.form.setting}
  385. name="singleMins"
  386. readonly
  387. isLink
  388. onClick={this.onTimer}
  389. placeholder="未设置"
  390. />
  391. </ColField>
  392. </ColFieldGroup>
  393. <ColFieldGroup>
  394. <ColField required title="是否跳过节假日" border={false}>
  395. <RadioGroup
  396. class={styles['radio-group']}
  397. modelValue={this.form.skipHolidayFlag}
  398. onUpdate:modelValue={val => (this.form.skipHolidayFlag = val)}
  399. >
  400. {['1', '0'].map((item: string) => {
  401. const isActive =
  402. Number(item) === Number(this.form.skipHolidayFlag)
  403. const type = isActive ? 'primary' : 'default'
  404. return (
  405. <Radio class={styles.radio} name={item}>
  406. <Tag size="large" plain={isActive} type={type}>
  407. {this.chargeTypeArr[item]}
  408. </Tag>
  409. </Radio>
  410. )
  411. })}
  412. </RadioGroup>
  413. </ColField>
  414. </ColFieldGroup>
  415. <Sticky offsetBottom={0} position="bottom">
  416. <div class={'btnGroup'}>
  417. <Button block round type="primary" native-type="submit">
  418. 提交
  419. </Button>
  420. </div>
  421. </Sticky>
  422. <ColPopup v-model={this.subjectStatus} destroy>
  423. <ColHeader />
  424. <SubjectModel
  425. max={5}
  426. single
  427. subjectList={this.subjectList}
  428. choiceSubjectIds={this.choiceSubjectId}
  429. onChoice={this.onChoice}
  430. />
  431. </ColPopup>
  432. <ColPopup v-model={this.timerStatus} destroy>
  433. <ColHeader title="设置陪练时间段" />
  434. <Timer
  435. onChoice={this.onChoiceTimer}
  436. timerObject={this.timerObject}
  437. courseMinutes={Number(this.timeSetting.courseMinutes)}
  438. freeMinutes={Number(this.timeSetting.freeMinutes)}
  439. startSetting={this.timeSetting.startSetting}
  440. endSetting={this.timeSetting.endSetting}
  441. />
  442. </ColPopup>
  443. <ActionSheet
  444. v-model:show={this.classTimeStatus}
  445. actions={this.minutes}
  446. cancelText="取消"
  447. closeOnClickAction
  448. onSelect={this.onSelect}
  449. />
  450. </Form>
  451. )
  452. }
  453. })