index.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { CellGroup, Cell, Image, Button, Popup, List } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import styles from './index.module.less'
  4. import award from './images/award.png'
  5. import cert from './images/cert.png'
  6. import request from '@/helpers/request'
  7. import ColResult from '@/components/col-result'
  8. import { state } from '@/state'
  9. import dayjs from 'dayjs'
  10. import ColPopup from '@/components/col-popup'
  11. import UserAuth from '../order-detail/userAuth'
  12. import ColHeader from '@/components/col-header'
  13. export default defineComponent({
  14. name: 'award-activity',
  15. data() {
  16. return {
  17. status: false,
  18. type: 'auth',
  19. list: [],
  20. dataShow: true, // 判断是否有数据
  21. loading: false,
  22. finished: false,
  23. params: {
  24. // receive: 2,
  25. page: 1,
  26. rows: 20
  27. },
  28. exists: false,
  29. popupShow: false,
  30. receiveRewardId: null as any
  31. }
  32. },
  33. // /student-server/activity/receiveRewardList 学生端查看未领奖列表接口
  34. // /student-server/activity/receiveReward/{receiveRewardId} 学生端领奖接口
  35. // /teacher-server/activity/receiveRewardList 老师端查看未领奖列表接口
  36. // /teacher-server/activity/receiveReward/{receiveRewardId} 学生端领奖接口
  37. async mounted() {
  38. this.getUserRegisterProtocol()
  39. this.getList()
  40. },
  41. methods: {
  42. async getUserRegisterProtocol() {
  43. // 获取是否签署过《用户注册协议》
  44. try {
  45. const res = await request.get(
  46. state.platformApi + '/sysUserContractRecord/checkContractSign',
  47. {
  48. params: {
  49. contractType: 'REGISTER'
  50. }
  51. }
  52. )
  53. this.exists = res.data
  54. } catch {
  55. //
  56. }
  57. },
  58. async onGetAward() {
  59. try {
  60. const users = state.user.data
  61. // 判断是否需要实名认证, 姓名,卡号,是否签协议
  62. if (!users?.realName || !users?.idCardNo || !this.exists) {
  63. this.status = true
  64. this.type = 'auth'
  65. return
  66. }
  67. await request.post(
  68. `${state.platformApi}/activity/receiveReward/${this.receiveRewardId}`
  69. )
  70. this.status = true
  71. this.type = 'success'
  72. this.receiveRewardId = null
  73. } catch {
  74. //
  75. }
  76. },
  77. async onAuthSuccess() {
  78. this.popupShow = false
  79. this.status = false
  80. await this.getUserRegisterProtocol()
  81. this.onGetAward()
  82. },
  83. async getList() {
  84. try {
  85. const params = this.params
  86. const res = await request.post(
  87. `${state.platformApi}/activity/receiveRewardList`,
  88. {
  89. data: {
  90. ...params
  91. }
  92. }
  93. )
  94. this.loading = false
  95. const result = res.data || {}
  96. // 处理重复请求数据
  97. if (this.list.length > 0 && result.pageNo === 1) {
  98. return
  99. }
  100. this.list = this.list.concat(result.rows || [])
  101. this.finished = result.pageNo >= result.totalPage
  102. this.params.page = result.pageNo + 1
  103. this.dataShow = this.list.length > 0
  104. } catch {
  105. this.dataShow = false
  106. this.finished = true
  107. }
  108. }
  109. },
  110. render() {
  111. return (
  112. <div class={styles.award}>
  113. <ColHeader />
  114. {this.dataShow ? (
  115. <List
  116. class={styles.videoList}
  117. v-model:loading={this.loading}
  118. finished={this.finished}
  119. finishedText=" "
  120. immediateCheck={false}
  121. onLoad={this.getList}
  122. >
  123. {this.list.map((item: any) => (
  124. <CellGroup inset class={styles.cellGroup}>
  125. <Cell
  126. v-slots={{
  127. icon: () => (
  128. <Image src={item.imgUrl} class={styles.image} />
  129. ),
  130. title: () => (
  131. <div class={styles.title}>{item.rewardName}</div>
  132. ),
  133. label: () => (
  134. <div class={styles.label}>{item.rewardDescribe}</div>
  135. )
  136. }}
  137. />
  138. <Cell
  139. center
  140. title={`获奖时间:${dayjs(item.winningTime).format(
  141. 'YYYY-MM-DD'
  142. )}`}
  143. titleClass={styles.cellTitle}
  144. v-slots={{
  145. value: () => (
  146. <Button
  147. color="linear-gradient(180deg, #FF8636 0%, #FF4E19 100%)"
  148. size="small"
  149. class={styles.button}
  150. onClick={() => {
  151. this.receiveRewardId = item.receiveRewardId
  152. this.onGetAward()
  153. }}
  154. >
  155. 立即领取
  156. </Button>
  157. )
  158. }}
  159. />
  160. </CellGroup>
  161. ))}
  162. </List>
  163. ) : (
  164. <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无数据" />
  165. )}
  166. <Popup v-model:show={this.status} class={styles.popup}>
  167. <div class={styles.popupContainer}>
  168. {this.type === 'auth' && (
  169. <>
  170. <Image src={cert} class={styles.cert} />
  171. <h3>您还没有实名认证</h3>
  172. <p>完成实名认证后即可领取奖品</p>
  173. <div class={[styles.btnGroup, styles.btnMore]}>
  174. <Button
  175. type="primary"
  176. block
  177. class={styles.lastBtn}
  178. onClick={() => {
  179. this.status = false
  180. }}
  181. >
  182. 以后再说
  183. </Button>
  184. <Button
  185. type="primary"
  186. block
  187. color="linear-gradient(180deg, #59E5D5 0%, #2DC7AA 100%)"
  188. onClick={() => {
  189. this.popupShow = true
  190. }}
  191. >
  192. 立即认证
  193. </Button>
  194. </div>
  195. </>
  196. )}
  197. {this.type === 'success' && (
  198. <>
  199. <Image src={award} class={styles.award} />
  200. <h3>奖品领取成功!</h3>
  201. <p>请耐心等待,活动奖品将会到达~</p>
  202. <div class={[styles.btnGroup]}>
  203. <Button
  204. type="primary"
  205. block
  206. color="linear-gradient(180deg, #59E5D5 0%, #2DC7AA 100%)"
  207. onClick={() => {
  208. this.status = false
  209. this.list = []
  210. this.params.page = 1
  211. this.getList()
  212. }}
  213. >
  214. 我知道了
  215. </Button>
  216. </div>
  217. </>
  218. )}
  219. </div>
  220. </Popup>
  221. <ColPopup v-model={this.popupShow}>
  222. <UserAuth exists={this.exists} onSuccess={this.onAuthSuccess} />
  223. </ColPopup>
  224. </div>
  225. )
  226. }
  227. })