course-start.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import ColField from '@/components/col-field'
  2. import ColFieldGroup from '@/components/col-field-group'
  3. import {
  4. Button,
  5. Col,
  6. Field,
  7. Form,
  8. Radio,
  9. RadioGroup,
  10. Row,
  11. Sticky,
  12. Tab,
  13. Tabs,
  14. Image,
  15. Icon,
  16. Popup,
  17. DatetimePicker
  18. } from 'vant'
  19. import { defineComponent } from 'vue'
  20. import { createState } from './createState'
  21. import styles from './course-start.module.less'
  22. import ColUpload from '@/components/col-upload'
  23. import { verifiyNumberInteger } from '@/helpers/toolsValidate'
  24. import { formatterDate } from '@/helpers/utils'
  25. import activeButtonIcon from '@common/images/icon_checkbox.png'
  26. import inactiveButtonIcon from '@common/images/icon_checkbox_default.png'
  27. import dayjs from 'dayjs'
  28. export default defineComponent({
  29. name: 'course-start',
  30. data() {
  31. return {
  32. dateStatus: false,
  33. currentDate: new Date(),
  34. minDate: dayjs().toDate(),
  35. maxDate: new Date()
  36. }
  37. },
  38. mounted() {
  39. this.maxDate = dayjs(createState.selectCourseList[0].startTime)
  40. .subtract(1, 'day')
  41. .toDate()
  42. createState.live.salesStartDate = dayjs(this.minDate).format('YYYY-MM-DD')
  43. createState.live.salesEndDate = dayjs(this.maxDate).format('YYYY-MM-DD')
  44. },
  45. methods: {
  46. tabChange(name: number) {
  47. createState.tabIndex = name
  48. },
  49. selectImg(val: string) {
  50. createState.live.backgroundPic = ''
  51. createState.live.backgroundPicTemplate = val
  52. },
  53. onFormatterInt(val: any) {
  54. if (val && val >= 1) {
  55. return verifiyNumberInteger(val)
  56. } else {
  57. return ''
  58. }
  59. },
  60. onConfirm(val: any) {
  61. this.dateStatus = false
  62. }
  63. },
  64. render() {
  65. return (
  66. <Form
  67. class={styles.courseStart}
  68. onSubmit={() => (createState.active = 5)}
  69. scrollToError
  70. >
  71. <ColFieldGroup>
  72. <ColField title="开售日期" required>
  73. <Field
  74. v-model={createState.live.salesStartDate}
  75. name="salesStartDate"
  76. readonly
  77. isLink
  78. placeholder="请选择停售日期"
  79. onClick={() => {
  80. this.currentDate = dayjs(
  81. createState.live.salesStartDate
  82. ).toDate()
  83. this.dateStatus = true
  84. }}
  85. rules={[{ required: true, message: '请选择停售日期' }]}
  86. />
  87. </ColField>
  88. <ColField title="停售日期" required>
  89. <Field
  90. v-model={createState.live.salesEndDate}
  91. name="salesEndDate"
  92. readonly
  93. isLink
  94. onClick={() => {
  95. this.currentDate = dayjs(createState.live.salesEndDate).toDate()
  96. this.dateStatus = true
  97. }}
  98. rules={[{ required: true, message: '请选择停售日期' }]}
  99. placeholder="请选择停售日期"
  100. />
  101. </ColField>
  102. </ColFieldGroup>
  103. <ColFieldGroup>
  104. <ColField
  105. title="最低开课人数"
  106. required
  107. style={{
  108. marginBottom: '10px'
  109. }}
  110. >
  111. <Field
  112. v-model={createState.live.mixStudentNum}
  113. name="mixStudentNum"
  114. placeholder="请输入最低开课人数"
  115. type="number"
  116. maxlength={8}
  117. formatter={this.onFormatterInt}
  118. rules={[{ required: true, message: '请输入最低开课人数' }]}
  119. v-slots={{
  120. button: () => <span>人</span>
  121. }}
  122. />
  123. </ColField>
  124. <div class={styles.stepTips}>
  125. 课程停售时付费学员达到该人数可开课,若未达到该人数课程将会失效,已付费学员将自动退款
  126. </div>
  127. </ColFieldGroup>
  128. <ColFieldGroup>
  129. <ColField
  130. required
  131. border={false}
  132. v-slots={{
  133. title: () => (
  134. <Tabs
  135. v-model:active={createState.tabIndex}
  136. class={styles.infoField}
  137. onChange={this.tabChange}
  138. shrink
  139. color="var(--van-primary)"
  140. lineWidth={20}
  141. >
  142. <Tab title="图片模板" name={1}></Tab>
  143. <Tab title="自定义模板" name={2}></Tab>
  144. </Tabs>
  145. )
  146. }}
  147. >
  148. <p class={styles.photoTip}>模板图片将作为改课程封面为学员展示</p>
  149. {createState.tabIndex === 1 ? (
  150. <Field
  151. name="backgroundPicTemplate"
  152. rules={[{ required: true, message: '请选择课程声部' }]}
  153. v-slots={{
  154. input: () => (
  155. <RadioGroup
  156. v-model={createState.live.backgroundPicTemplate}
  157. >
  158. <Row justify="space-between" style={{ width: '100%' }}>
  159. {createState.templateList.map((item: any) => (
  160. <Col
  161. span={12}
  162. class={styles.imgContainer}
  163. onClick={() => this.selectImg(item)}
  164. >
  165. <Image class={styles.imgContainer} src={item} />
  166. <Radio
  167. name={item}
  168. v-slots={{
  169. icon: (props: any) => (
  170. <Icon
  171. class={styles.boxStyle}
  172. name={
  173. props.checked
  174. ? activeButtonIcon
  175. : inactiveButtonIcon
  176. }
  177. size="18"
  178. />
  179. )
  180. }}
  181. />
  182. </Col>
  183. ))}
  184. </Row>
  185. </RadioGroup>
  186. )
  187. }}
  188. />
  189. ) : null}
  190. {createState.tabIndex == 2 ? (
  191. <Field
  192. name="backgroundPic"
  193. rules={[{ required: true, message: '请选择课程声部' }]}
  194. v-slots={{
  195. input: () => (
  196. <Row justify="space-between" style={{ width: '100%' }}>
  197. <Col span={12} class={styles.imgContainer}>
  198. <ColUpload
  199. cropper
  200. options={{
  201. fixedNumber: [3, 2],
  202. autoCropWidth: 750,
  203. autoCropHeight: 500
  204. }}
  205. onUploadChange={(val: any) => {
  206. if (val) {
  207. createState.live.backgroundPicTemplate = ''
  208. }
  209. }}
  210. v-model={createState.live.backgroundPic}
  211. class={styles.imgContainer}
  212. />
  213. </Col>
  214. </Row>
  215. )
  216. }}
  217. />
  218. ) : null}
  219. </ColField>
  220. </ColFieldGroup>
  221. <Sticky offsetBottom={0} position="bottom">
  222. <div class={['btnGroup', 'btnMore']}>
  223. <Button
  224. block
  225. round
  226. type="primary"
  227. plain
  228. onClick={() => {
  229. createState.active = 3
  230. }}
  231. >
  232. 上一步
  233. </Button>
  234. <Button block round type="primary" native-type="submit">
  235. 下一步
  236. </Button>
  237. </div>
  238. </Sticky>
  239. <Popup show={this.dateStatus} position="bottom" round>
  240. <DatetimePicker
  241. type="date"
  242. v-model={this.currentDate}
  243. minDate={this.minDate}
  244. maxDate={this.maxDate}
  245. formatter={formatterDate}
  246. onCancel={() => {
  247. this.dateStatus = false
  248. }}
  249. onConfirm={this.onConfirm}
  250. />
  251. </Popup>
  252. </Form>
  253. )
  254. }
  255. })