course.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import ColField from '@/components/col-field'
  2. import ColFieldGroup from '@/components/col-field-group'
  3. import ColPopup from '@/components/col-popup'
  4. import SubjectModel from '@/business-components/subject-list'
  5. import { ActionSheet, Button, Field, Form, Sticky } from 'vant'
  6. import { defineComponent } from 'vue'
  7. import styles from './course.module.less'
  8. import { createState } from './createState'
  9. import {
  10. verifiyNumberInteger,
  11. verifyNumberIntegerAndFloat
  12. } from '@/helpers/toolsValidate'
  13. import request from '@/helpers/request'
  14. import { state } from '@/state'
  15. import ColHeader from '@/components/col-header'
  16. import TheSticky from '@/components/the-sticky'
  17. // 校验函数返回 true 表示校验通过,false 表示不通过
  18. export const validator = val => {
  19. console.log(val)
  20. if (Number(val) <= 0) {
  21. return '课程组售价必须大于0'
  22. } else {
  23. return true
  24. }
  25. }
  26. export default defineComponent({
  27. name: 'course',
  28. data() {
  29. return {
  30. subjectStatus: false,
  31. classTimeStatus: false,
  32. checked: false
  33. }
  34. },
  35. computed: {
  36. choiceSubjectIds() {
  37. // 选择的科目编号
  38. const ids = createState.live.subjectId
  39. ? Number(createState.live.subjectId)
  40. : null
  41. return ids ? [ids] : []
  42. },
  43. subjectList() {
  44. // 学科列表
  45. return createState.subjectList || []
  46. },
  47. lessonSubjectName() {
  48. // 选择的科目
  49. let tempStr = ''
  50. this.subjectList.forEach((item: any) => {
  51. if (this.choiceSubjectIds.includes(item.id)) {
  52. tempStr = item.name
  53. }
  54. })
  55. return tempStr
  56. },
  57. calcSingleRatePrice() {
  58. const rate = createState.rate || 0
  59. const nums = createState.live.courseNum
  60. const price = createState.live.coursePrice || 0
  61. return nums ? ((price / nums) * (1 - rate / 100)).toFixed(2) : 0
  62. },
  63. calcRatePrice() {
  64. // 计算手续费
  65. const rate = createState.rate || 0
  66. const price = createState.live.coursePrice || 0
  67. return (price - (rate / 100) * price).toFixed(2)
  68. },
  69. disabled() {
  70. return createState.live.courseGroupId ? true : false
  71. }
  72. },
  73. async mounted() {
  74. try {
  75. const resVersion = await request.post('/api-teacher/open/appVersion', {
  76. data: {
  77. platform:
  78. state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher',
  79. version: state.version
  80. }
  81. })
  82. this.checked = resVersion.data.check ? true : false
  83. // 审核版本金额默认为0
  84. if (this.checked) {
  85. createState.live.coursePrice = 0
  86. }
  87. } catch {
  88. //
  89. }
  90. },
  91. methods: {
  92. onChoice(id: number) {
  93. createState.live.subjectId = id
  94. let tempStr = ''
  95. this.subjectList.forEach((item: any) => {
  96. if (id == item.id) {
  97. tempStr = item.name
  98. }
  99. })
  100. createState.live.subjectName = tempStr
  101. this.subjectStatus = false
  102. },
  103. onFormatter(val: any) {
  104. return verifyNumberIntegerAndFloat(val)
  105. },
  106. onFormatterInt(val: any) {
  107. if (val && val >= 1) {
  108. return verifiyNumberInteger(val)
  109. } else {
  110. return ''
  111. }
  112. },
  113. onSelect(action: any) {
  114. createState.live.singleCourseMinutes =
  115. Number(action.name || 0) + Number(action.freeMinutes || 0)
  116. createState.live.singleMins = Number(action.name || 0)
  117. createState.live.freeMinutes = Number(action.freeMinutes || 0)
  118. }
  119. },
  120. render() {
  121. return (
  122. <Form
  123. class={styles.classInfo}
  124. onSubmit={() => (createState.active = 2)}
  125. scrollToError
  126. >
  127. <ColFieldGroup>
  128. <ColField title="课程名称" required>
  129. <Field
  130. v-model={createState.live.name}
  131. name="name"
  132. maxlength={20}
  133. placeholder="请输入您的课程名称"
  134. rules={[{ required: true, message: '请输入您的课程名称' }]}
  135. disabled={this.disabled}
  136. />
  137. </ColField>
  138. <ColField title="课程声部" required>
  139. <Field
  140. modelValue={this.lessonSubjectName}
  141. name="subjectId"
  142. readonly
  143. isLink
  144. disabled={this.disabled}
  145. onClick={() => {
  146. if (createState.live.courseGroupId) {
  147. return
  148. }
  149. this.subjectStatus = true
  150. }}
  151. rules={[{ required: true, message: '请选择课程声部' }]}
  152. placeholder="请选择课程声部"
  153. />
  154. </ColField>
  155. <ColField title="课程介绍" required border={false}>
  156. <Field
  157. v-model={createState.live.courseIntroduce}
  158. name="courseIntroduce"
  159. placeholder="请输入课程介绍"
  160. rows="3"
  161. maxlength={200}
  162. showWordLimit
  163. autosize
  164. rules={[{ required: true, message: '请输入课程介绍' }]}
  165. type="textarea"
  166. />
  167. </ColField>
  168. </ColFieldGroup>
  169. <ColFieldGroup>
  170. <ColField title="课时数" required>
  171. <Field
  172. v-model={createState.live.courseNum}
  173. name="courseNum"
  174. placeholder="请输入您的课时数"
  175. formatter={this.onFormatterInt}
  176. type="number"
  177. maxlength={2}
  178. disabled={this.disabled}
  179. rules={[{ required: true, message: '请输入您的课时数' }]}
  180. v-slots={{
  181. button: () => <span>课时</span>
  182. }}
  183. />
  184. </ColField>
  185. <ColField title="单课时时长" required>
  186. <Field
  187. modelValue={createState.live.singleMins}
  188. name="singleMins"
  189. readonly
  190. disabled={this.disabled}
  191. isLink
  192. onClick={() => {
  193. if (!createState.live.courseGroupId) {
  194. this.classTimeStatus = true
  195. }
  196. }}
  197. rules={[{ required: true, message: '请选择单课时时长' }]}
  198. placeholder="请选择单课时时长"
  199. />
  200. </ColField>
  201. {/* 是审核版本才会显示金额 */}
  202. {!this.checked && (
  203. <ColField title="课程组售价" required>
  204. <Field
  205. v-model={createState.live.coursePrice}
  206. name="coursePrice"
  207. placeholder="请输入您的课程组售价"
  208. formatter={this.onFormatter}
  209. type="number"
  210. maxlength={8}
  211. disabled={this.disabled}
  212. rules={[
  213. { required: true, validator, message: '请输入您的课程组售价' }
  214. ]}
  215. v-slots={{
  216. button: () => <span>元</span>
  217. }}
  218. />
  219. </ColField>
  220. )}
  221. </ColFieldGroup>
  222. {/* 是审核版本才会显示金额 */}
  223. {!this.checked && (
  224. <div class={styles['class-info-tip']}>
  225. <p>扣除手续费后您的课程预计收入为:</p>
  226. <p>
  227. 单课时<span>{this.calcSingleRatePrice}</span>元/人
  228. </p>
  229. <p>
  230. 课程组总收入<span>{this.calcRatePrice}</span>元/人
  231. </p>
  232. <p>您的课程收入将在课程结束后结算到您的账户中</p>
  233. </div>
  234. )}
  235. <TheSticky position="bottom">
  236. <div class={'btnGroup'}>
  237. <Button block round type="primary" native-type="submit">
  238. 下一步
  239. </Button>
  240. </div>
  241. </TheSticky>
  242. <ColPopup v-model={this.subjectStatus}>
  243. <ColHeader title="选择声部" />
  244. <SubjectModel
  245. selectType="Radio"
  246. single
  247. subjectList={createState.subjectList}
  248. choiceSubjectIds={this.choiceSubjectIds}
  249. onChoice={this.onChoice}
  250. />
  251. </ColPopup>
  252. <ActionSheet
  253. v-model:show={this.classTimeStatus}
  254. actions={createState.minutes}
  255. cancelText="取消"
  256. closeOnClickAction
  257. onSelect={this.onSelect}
  258. />
  259. </Form>
  260. )
  261. }
  262. })