index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import { defineComponent, PropType, ref } from 'vue'
  2. import styles from './index.module.less'
  3. import { CellGroup, List, Sticky } from 'vant'
  4. import iconMoney from '../../images/icon-money.png'
  5. import ColResult from '@/components/col-result'
  6. import Echats from '../echats'
  7. import TeacherItem from '../teacher-item'
  8. import BuyItem from '../buy-item'
  9. import request from '@/helpers/request'
  10. import { getTimeRange, TIME_TYPE } from '../../home-statistics'
  11. import { moneyFormat } from '@/helpers/utils'
  12. export default defineComponent({
  13. name: 'list',
  14. props: {
  15. type: {
  16. type: String as PropType<
  17. 'VIP_COURSE' | 'PRACTICE' | 'GROUP' | 'LIVE' | 'VIDEO' | 'MUSIC'
  18. >,
  19. default: 'VIP_COURSE'
  20. }
  21. },
  22. setup(props) {
  23. const timeRange = ref(getTimeRange('MONTH'))
  24. const obj = ref({
  25. xAxisData: [] as any,
  26. yAxisData: [] as any,
  27. browseCount: 0,
  28. buyCount: 0
  29. })
  30. const dataShow = ref(true) // 判断是否有数据
  31. const state = {
  32. statInfo: 0, // 预计课程总收入
  33. accountPeriod: 0, // 几天后
  34. loading: false,
  35. finished: false,
  36. params: {
  37. page: 1,
  38. rows: 20
  39. }
  40. }
  41. const tableList = ref<any[]>([])
  42. const getSysConfig = async () => {
  43. try {
  44. const { data } = await request.get('/api-teacher/sysConfig/list', {
  45. params: {
  46. group: 'ACCOUNT_PERIOD'
  47. }
  48. })
  49. const result = data || []
  50. result.forEach((item: any) => {
  51. if (
  52. props.type === 'VIP_COURSE' &&
  53. item.paramName === 'vip_course_account_period'
  54. ) {
  55. state.accountPeriod = item.paramValue
  56. } else if (
  57. props.type === 'PRACTICE' &&
  58. item.paramName === 'practice_account_period'
  59. ) {
  60. state.accountPeriod = item.paramValue
  61. } else if (
  62. props.type === 'GROUP' &&
  63. item.paramName === 'group_course_account_period'
  64. ) {
  65. state.accountPeriod = item.paramValue
  66. } else if (
  67. props.type === 'LIVE' &&
  68. item.paramName === 'live_account_period'
  69. ) {
  70. state.accountPeriod = item.paramValue
  71. } else if (
  72. props.type === 'VIDEO' &&
  73. item.paramName === 'video_account_period'
  74. ) {
  75. state.accountPeriod = item.paramValue
  76. } else if (
  77. props.type === 'MUSIC' &&
  78. item.paramName === 'music_account_period'
  79. ) {
  80. state.accountPeriod = item.paramValue
  81. }
  82. })
  83. } catch {
  84. //
  85. }
  86. }
  87. const getDetail = async () => {
  88. try {
  89. const { data } = await request.post(
  90. '/api-teacher/home/courseExposure',
  91. {
  92. data: { ...timeRange.value, type: props.type }
  93. }
  94. )
  95. const buy = data.buy || []
  96. const exposure = data.exposure || []
  97. const xAxisData: string[] = []
  98. const exposureList: number[] = []
  99. exposure.forEach((item: any, index: number) => {
  100. xAxisData.push(item.date)
  101. exposureList.push(item.exposureNum)
  102. if (exposure.length - 1 === index) {
  103. obj.value.browseCount = item.exposureNum
  104. }
  105. })
  106. const buyList: number[] = []
  107. buy.forEach((item: any, index: number) => {
  108. buyList.push(item.exposureNum)
  109. if (buy.length - 1 === index) {
  110. obj.value.buyCount = item.exposureNum
  111. }
  112. })
  113. const yAxisData = [exposureList, buyList]
  114. obj.value.xAxisData = xAxisData
  115. obj.value.yAxisData = yAxisData
  116. } catch {
  117. //
  118. }
  119. }
  120. const getList = async () => {
  121. try {
  122. const { data } = await request.post(
  123. '/api-teacher/home/teacherIncomeList',
  124. {
  125. data: {
  126. ...timeRange.value,
  127. type: props.type,
  128. ...state.params
  129. }
  130. }
  131. )
  132. state.loading = false
  133. state.statInfo = data.statInfo || 0
  134. tableList.value = tableList.value.concat(data.rows || [])
  135. state.finished = data.pageNo >= data.totalPage
  136. state.params.page = data.pageNo + 1
  137. dataShow.value = tableList.value.length > 0
  138. } catch {
  139. dataShow.value = false
  140. state.finished = true
  141. }
  142. }
  143. getSysConfig()
  144. getDetail()
  145. getList()
  146. return () => (
  147. <div class={styles.list}>
  148. <Echats
  149. obj={obj.value}
  150. currentType={'MONTH'}
  151. onConfirm={(val: any) => {
  152. // currentType.value = val
  153. timeRange.value = val
  154. getDetail()
  155. getList()
  156. }}
  157. />
  158. <div class={styles.expectedIncome}>
  159. {/* <Sticky> */}
  160. <div class={styles.incomeTitle}>
  161. <div class={styles.title}>
  162. <img src={iconMoney} />
  163. <span>预计总收入</span>
  164. </div>
  165. <div class={styles.price}>
  166. <span>¥ </span>
  167. {moneyFormat(state.statInfo || 0)}
  168. </div>
  169. </div>
  170. {/* </Sticky> */}
  171. <div class={styles.incomeTip}>
  172. 实际收入将在课程结束{state.accountPeriod || 0}天后结算
  173. </div>
  174. <div class={styles.element}></div>
  175. {dataShow.value ? (
  176. <List
  177. v-model:loading={state.loading}
  178. finished={state.finished}
  179. finishedText=" "
  180. onLoad={getList}
  181. >
  182. <CellGroup border={false}>
  183. {['VIP_COURSE', 'PRACTICE'].includes(props.type) && (
  184. <TeacherItem list={tableList.value} />
  185. )}
  186. {['GROUP', 'LIVE', 'VIDEO', 'MUSIC'].includes(props.type) && (
  187. <BuyItem
  188. list={tableList.value}
  189. isSquare={props.type === 'MUSIC'}
  190. />
  191. )}
  192. </CellGroup>
  193. </List>
  194. ) : (
  195. <ColResult
  196. type="empty"
  197. btnStatus={false}
  198. classImgSize="SMALL"
  199. tips="暂无数据~"
  200. />
  201. )}
  202. </div>
  203. </div>
  204. )
  205. }
  206. })