index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. import ColEmpty from '@/components/col-empty'
  2. import request from '@/helpers/request'
  3. import { verifyNumberIntegerAndFloat } from '@/helpers/toolsValidate'
  4. import { state } from '@/state'
  5. import {
  6. ElButton,
  7. ElDialog,
  8. ElForm,
  9. ElFormItem,
  10. ElInput,
  11. ElMessage,
  12. ElOption,
  13. ElOptionGroup,
  14. ElRadio,
  15. ElRadioButton,
  16. ElRadioGroup,
  17. ElSelect
  18. } from 'element-plus'
  19. import { defineComponent } from 'vue'
  20. import PracticeTimer from '../model/practice-timer'
  21. import styles from './index.module.less'
  22. export default defineComponent({
  23. name: 'practice-setting',
  24. data() {
  25. return {
  26. subjectList: [],
  27. chargeTypeArr: {
  28. 0: '否',
  29. 1: '是'
  30. },
  31. classTimeStatus: false,
  32. subjectStatus: false,
  33. timerStatus: false,
  34. timeSetting: {
  35. courseMinutes: 25,
  36. freeMinutes: 5,
  37. startSetting: '08:00',
  38. endSetting: '18:00'
  39. },
  40. timerObject: {} as any,
  41. form: {
  42. enableFlag: 1,
  43. courseMinutes: null as any,
  44. freeMinutes: 0,
  45. subjectIdTemp: '',
  46. subjectId: [] as any[],
  47. subjectPrice: [] as any[],
  48. skipHolidayFlag: 1,
  49. setting: '未设置'
  50. },
  51. minutes: [] as any,
  52. rate: 0
  53. }
  54. },
  55. async mounted() {
  56. try {
  57. // 获取手续费和分钟数
  58. let config = await request.get(
  59. '/api-website/sysConfig/queryByParamNameList',
  60. {
  61. params: {
  62. paramNames:
  63. 'practice_times_setting,practice_service_fee,course_start_setting,course_end_setting'
  64. }
  65. }
  66. )
  67. let configData = config.data || []
  68. configData.forEach((item: any) => {
  69. if (item.paramName === 'practice_times_setting') {
  70. let mins = item.paramValue ? JSON.parse(item.paramValue) : []
  71. let tempArr = [] as any
  72. mins.forEach((item: any) => {
  73. tempArr.push({
  74. ...item,
  75. name: item.courseMinutes
  76. })
  77. })
  78. this.minutes = [...tempArr]
  79. }
  80. if (item.paramName === 'practice_service_fee') {
  81. this.rate = item.paramValue
  82. }
  83. if (item.paramName === 'course_start_setting') {
  84. this.timeSetting.startSetting = item.paramValue
  85. }
  86. if (item.paramName === 'course_end_setting') {
  87. this.timeSetting.endSetting = item.paramValue
  88. }
  89. })
  90. let teacher = await request.post('/api-website/teacher/querySubject')
  91. this.subjectList = teacher.data || []
  92. // 获取课程设置
  93. const setting = await request.post(
  94. '/api-website/teacherFreeTime/getDetail',
  95. {
  96. data: {
  97. defaultFlag: 1
  98. }
  99. }
  100. )
  101. const sr = setting.data
  102. if (sr) {
  103. this.timeSetting.courseMinutes = sr.courseMinutes
  104. this.timeSetting.freeMinutes = sr.freeMinutes
  105. this.timerObject = {
  106. monday: sr.monday ? JSON.parse(sr.monday) : [],
  107. tuesday: sr.tuesday ? JSON.parse(sr.tuesday) : [],
  108. wednesday: sr.wednesday ? JSON.parse(sr.wednesday) : [],
  109. thursday: sr.thursday ? JSON.parse(sr.thursday) : [],
  110. friday: sr.friday ? JSON.parse(sr.friday) : [],
  111. saturday: sr.saturday ? JSON.parse(sr.saturday) : [],
  112. sunday: sr.sunday ? JSON.parse(sr.sunday) : []
  113. }
  114. let tempIds: any = []
  115. let tempPrices: any = []
  116. const subjectPrice = sr.subjectPrice || []
  117. subjectPrice.forEach((item: any) => {
  118. tempIds.push(item.subjectId)
  119. tempPrices.push({
  120. subjectId: item.subjectId,
  121. subjectPrice: item.subjectPrice,
  122. subjectName: item.subjectName
  123. })
  124. })
  125. const to = this.timerObject
  126. this.form = {
  127. enableFlag: sr.enableFlag ? 1 : 0,
  128. courseMinutes: sr.courseMinutes,
  129. freeMinutes: sr.freeMinutes,
  130. subjectIdTemp: tempIds.join(','),
  131. subjectId: tempIds,
  132. subjectPrice: tempPrices,
  133. skipHolidayFlag: sr.skipHolidayFlag ? 1 : 0,
  134. setting:
  135. to.monday.length > 0 ||
  136. to.tuesday.length > 0 ||
  137. to.wednesday.length > 0 ||
  138. to.thursday.length > 0 ||
  139. to.friday.length > 0 ||
  140. to.saturday.length > 0 ||
  141. to.sunday.length > 0
  142. ? '已设置'
  143. : '未设置'
  144. }
  145. }
  146. } catch {}
  147. },
  148. methods: {
  149. onSelect(item: any) {
  150. // 如果分钟数不同,则清空
  151. if (this.form.courseMinutes !== item.courseMinutes) {
  152. this.timerObject = {}
  153. this.form.setting = '未设置'
  154. }
  155. this.form.courseMinutes = item.courseMinutes
  156. this.form.freeMinutes = item.freeMinutes
  157. },
  158. async onTimer() {
  159. try {
  160. const form = this.form
  161. if (!form.courseMinutes) {
  162. // Toast('请选择单课时时长')
  163. ElMessage.error('请选择单课时时长')
  164. return
  165. }
  166. this.timeSetting.courseMinutes = Number(form.courseMinutes)
  167. this.timeSetting.freeMinutes = Number(form.freeMinutes)
  168. this.timerStatus = true
  169. } catch {}
  170. },
  171. onChoiceTimer(item: any, status: boolean) {
  172. // console.log(item, 'item')
  173. this.form.setting = status ? '已设置' : ''
  174. this.timerObject = item
  175. this.timerStatus = false
  176. },
  177. onChoice(item: any) {
  178. const tempItem = item || []
  179. this.form.subjectId = tempItem
  180. this.form.subjectIdTemp = tempItem.join(',') || ''
  181. let subjectPriceList = [...this.form.subjectPrice]
  182. tempItem.forEach((item: any) => {
  183. const index = subjectPriceList.findIndex(
  184. (subject: any) => subject.subjectId === item
  185. )
  186. if (index === -1) {
  187. subjectPriceList.push({
  188. subjectId: item,
  189. subjectPrice: null as any,
  190. subjectName: ''
  191. })
  192. }
  193. })
  194. const temp: any = []
  195. subjectPriceList.forEach((item: any) => {
  196. const isExist = tempItem.some(
  197. (subjectId: any) => subjectId === item.subjectId
  198. )
  199. isExist && temp.push(item)
  200. })
  201. this.form.subjectPrice = temp
  202. this.subjectStatus = false
  203. },
  204. getSubjectName(id: any) {
  205. const subject: any = this.subjectList.find((item: any) => item.id === id)
  206. return subject ? subject.name : ''
  207. },
  208. onFormatter(e: any) {
  209. // console.log(verifyNumberIntegerAndFloat(e.target.value))
  210. e.target.value = verifyNumberIntegerAndFloat(e.target.value)
  211. },
  212. async onSubmit() {
  213. ;(this as any).$refs.form.validate(async (_: boolean) => {
  214. if (_) {
  215. try {
  216. const form = this.form
  217. form.subjectPrice.forEach((item: any) => {
  218. item.subjectName = this.getSubjectName(item.subjectId)
  219. })
  220. form.setting = form.setting === '未设置' ? '' : form.setting
  221. await request.post('/api-website/teacherFreeTime/upSet', {
  222. data: {
  223. ...form,
  224. ...this.timerObject
  225. }
  226. })
  227. ElMessage.success('设置成功')
  228. setTimeout(() => {
  229. postMessage({ api: 'back', content: {} })
  230. }, 500)
  231. } catch {}
  232. } else {
  233. this.$nextTick(() => {
  234. let isError = document.getElementsByClassName('is-error')
  235. isError[0].scrollIntoView({
  236. block: 'center',
  237. behavior: 'smooth'
  238. })
  239. })
  240. return false
  241. }
  242. })
  243. }
  244. },
  245. render() {
  246. return (
  247. <div class={styles.setting}>
  248. <div class="text-2xl font-medium text-black leading-none px-6 py-5 ">
  249. 陪练课设置
  250. </div>
  251. {state.user.data?.entryFlag ? (
  252. <>
  253. <ElForm
  254. labelPosition="left"
  255. labelWidth={'188px'}
  256. size="large"
  257. model={this.form}
  258. ref="form"
  259. class="px-6 py-5"
  260. >
  261. <ElFormItem
  262. label="是否开启陪练"
  263. prop="enableFlag"
  264. rules={[
  265. {
  266. required: true,
  267. message: '请选择是否开启陪练'
  268. }
  269. ]}
  270. >
  271. <ElSelect class="w-full" v-model={this.form.enableFlag}>
  272. <ElSelect.Option value={1} label={'是'}>
  273. </ElSelect.Option>
  274. <ElSelect.Option value={0} label={'否'}>
  275. </ElSelect.Option>
  276. </ElSelect>
  277. </ElFormItem>
  278. <ElFormItem
  279. label="可教授声部"
  280. prop={'subjectId'}
  281. rules={[
  282. {
  283. required: true,
  284. message: '请选择可教授声部',
  285. trigger: 'change'
  286. }
  287. ]}
  288. >
  289. <ElSelect
  290. multiple
  291. filterable
  292. placeholder="请选择可教授声部"
  293. class="w-full"
  294. multipleLimit={5}
  295. v-model={this.form.subjectId}
  296. onChange={this.onChoice}
  297. >
  298. {this.subjectList.map((item: any) => (
  299. <ElOption key={item.id} value={item.id} label={item.name} />
  300. ))}
  301. </ElSelect>
  302. </ElFormItem>
  303. <ElFormItem
  304. label="单课时长"
  305. prop="courseMinutes"
  306. rules={[
  307. {
  308. required: true,
  309. message: '请选择单课时长',
  310. trigger: 'change'
  311. }
  312. ]}
  313. >
  314. <ElSelect
  315. class="w-full"
  316. placeholder="请选择单课时时长"
  317. v-model={this.form.courseMinutes}
  318. >
  319. {this.minutes.map((item: any) => (
  320. <ElOption
  321. key={item.courseMinutes}
  322. value={item.courseMinutes}
  323. >
  324. {item.name}
  325. </ElOption>
  326. ))}
  327. </ElSelect>
  328. </ElFormItem>
  329. {this.form.subjectPrice.map((item: any, index: number) => (
  330. <ElFormItem
  331. label={`${this.getSubjectName(item.subjectId)}陪练价格`}
  332. prop={`subjectPrice.${index}.subjectPrice`}
  333. rules={[
  334. {
  335. required: true,
  336. message: `请选择声部陪练价格`
  337. }
  338. ]}
  339. >
  340. <ElInput
  341. // @ts-ignore
  342. onKeyup={this.onFormatter}
  343. type="text"
  344. placeholder="请输入陪练价格"
  345. v-model={item.subjectPrice}
  346. v-slots={{
  347. append: () => (
  348. <span class="text-base text-[#333]">元</span>
  349. )
  350. }}
  351. />
  352. </ElFormItem>
  353. ))}
  354. <ElFormItem label="是否跳过节假日">
  355. <ElRadioGroup v-model={this.form.skipHolidayFlag}>
  356. <ElRadioButton label={1} class="mr-3 w-24">
  357. </ElRadioButton>
  358. <ElRadioButton label={0} class="w-24">
  359. </ElRadioButton>
  360. </ElRadioGroup>
  361. </ElFormItem>
  362. <ElFormItem label="陪练时间段">
  363. <div onClick={this.onTimer} class="w-full">
  364. <ElInput
  365. readonly
  366. class="cursor-pointer"
  367. v-model={this.form.setting}
  368. placeholder="请选择陪练时间段"
  369. suffixIcon={'ArrowDown'}
  370. />
  371. </div>
  372. </ElFormItem>
  373. </ElForm>
  374. <div class="text-center pt-6 pb-7">
  375. <ElButton
  376. class="!w-44 !h-[48px] !text-base"
  377. round
  378. onClick={() => {
  379. // 重置数据
  380. this.form = {
  381. enableFlag: 1,
  382. courseMinutes: null as any,
  383. freeMinutes: 0,
  384. subjectIdTemp: '',
  385. subjectId: [] as any[],
  386. subjectPrice: [] as any[],
  387. skipHolidayFlag: 1,
  388. setting: '未设置'
  389. }
  390. ;(this as any).$refs.form.resetFields()
  391. }}
  392. >
  393. 重置
  394. </ElButton>
  395. <ElButton
  396. type="primary"
  397. class="!w-44 !h-[48px] !text-base"
  398. round
  399. onClick={this.onSubmit}
  400. >
  401. 保存设置
  402. </ElButton>
  403. </div>
  404. </>
  405. ) : (
  406. <ColEmpty
  407. type="teacherCert"
  408. message="您还未完成达人认证,认证后才可设置陪练课哦~"
  409. buttonVisibility
  410. buttonText="去认证"
  411. onDetail={() => {
  412. this.$router.push('/teacherAuth')
  413. }}
  414. />
  415. )}
  416. <ElDialog
  417. modelValue={this.timerStatus}
  418. onUpdate:modelValue={val => (this.timerStatus = val)}
  419. showClose
  420. width={'488px'}
  421. >
  422. <PracticeTimer
  423. onChoice={this.onChoiceTimer}
  424. onClose={() => {
  425. this.timerStatus = false
  426. }}
  427. timerObject={this.timerObject}
  428. courseMinutes={Number(this.timeSetting.courseMinutes)}
  429. freeMinutes={Number(this.timeSetting.freeMinutes)}
  430. startSetting={this.timeSetting.startSetting}
  431. endSetting={this.timeSetting.endSetting}
  432. />
  433. </ElDialog>
  434. </div>
  435. )
  436. }
  437. })