practice-setting.tsx 14 KB

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