index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <page-meta :page-style="descVisible ? 'overflow:hidden;' : 'overflow:visible;'" />
  3. <view class="rules-box">
  4. <image class="rules-top-img" :src="topImgBg" mode="aspectFill" />
  5. <view class="enterprise-switch" @click="showEnterprisePicker">
  6. <view class="enterprise-switch__icon">
  7. <wd-icon name="loop" size="34rpx" />
  8. </view>
  9. <text>切换企业</text>
  10. </view>
  11. <wd-picker
  12. v-model:visible="pickerShow"
  13. title="切换企业"
  14. :columns="enterpriseList"
  15. label-key="label"
  16. value-key="value"
  17. root-portal
  18. @confirm="handleEnterpriseConfirm"
  19. />
  20. <view class="table-box">
  21. <view class="table-header">
  22. <view class="table-tab table-tab--left">获取途径</view>
  23. <view class="table-tab">获得积分</view>
  24. </view>
  25. <view class="table-con">
  26. <view class="table-bg">
  27. <view v-if="loading" class="loading">
  28. <view class="loading__item" />
  29. <view class="loading__item" />
  30. <view class="loading__item" />
  31. </view>
  32. <template v-else-if="sections.length">
  33. <view v-for="section in sections" :key="section.title" class="section">
  34. <view class="section-title">{{ section.title }}</view>
  35. <view v-for="item in section.items" :key="item.id" class="table-item">
  36. <view class="item-left">
  37. <text class="task-name">{{ item.taskTypeName }}</text>
  38. <image
  39. class="tips"
  40. :src="tipsIcon"
  41. mode="aspectFit"
  42. @click.stop="openDesc(item)"
  43. />
  44. </view>
  45. <text class="score-text">+{{ formatThousands(item.score) || '0' }}积分</text>
  46. </view>
  47. </view>
  48. </template>
  49. <view v-else class="empty">暂无数据</view>
  50. </view>
  51. </view>
  52. </view>
  53. <wd-popup
  54. v-model="descVisible"
  55. position="bottom"
  56. root-portal
  57. lock-scroll
  58. :safe-area-inset-bottom="true"
  59. custom-style="border-radius: 40rpx 40rpx 0 0;"
  60. >
  61. <view class="info">
  62. <view class="title">
  63. <text>{{ activeTask?.taskTypeName || '任务说明' }}</text>
  64. <wd-icon name="close" size="34rpx" @click="descVisible = false" />
  65. </view>
  66. <view class="list">
  67. <view class="tit">定义:</view>
  68. <view class="cont">{{ activeDesc }}</view>
  69. </view>
  70. <view v-if="activeTask?.taskRemark" class="list">
  71. <view class="tit">任务要求:</view>
  72. <view class="cont">{{ activeTask.taskRemark }}</view>
  73. </view>
  74. <view class="btn" @click="descVisible = false">知道了</view>
  75. </view>
  76. </wd-popup>
  77. </view>
  78. </template>
  79. <script setup lang="ts">
  80. import { computed, onMounted, ref } from 'vue'
  81. import config from '@/config'
  82. import { getDictTypeApi } from '@/services/modules/common'
  83. import type { DictItem } from '@/services/modules/common/type'
  84. import {
  85. getTaskTypeDeptListApi,
  86. getTaskTypeListByRuleIdApi,
  87. } from '@/services/modules/mine/pointsRule'
  88. import type {
  89. TaskTypeDeptListResponse,
  90. TaskTypeListByRuleIdResponse,
  91. } from '@/services/modules/mine/pointsRule/type'
  92. type TaskRuleItem = TaskTypeListByRuleIdResponse[string][number]
  93. const topImgBg = `${config.imgHost}home-top-bg2.png`
  94. const tipsIcon = 'https://yy-cloud-oss.oss-cn-beijing.aliyuncs.com/img/tips.png'
  95. const selectedRuleId = ref('')
  96. const pickerShow = ref(false)
  97. const loading = ref(false)
  98. const descVisible = ref(false)
  99. const enterpriseList = ref<TaskTypeDeptListResponse>([])
  100. const dictList = ref<DictItem[]>([])
  101. const sections = ref<Array<{ title: string; items: TaskRuleItem[] }>>([])
  102. const activeTask = ref<TaskRuleItem>()
  103. const activeDesc = computed(() => {
  104. const taskName = activeTask.value?.taskTypeName?.trim()
  105. if (!taskName) return '暂无定义'
  106. const dict = dictList.value.find((item) => {
  107. return [item.label, item.value, item.externalValue].includes(taskName)
  108. })
  109. return dict?.description || dict?.remarks || '暂无定义'
  110. })
  111. onMounted(() => {
  112. initPage()
  113. })
  114. const initPage = async () => {
  115. await Promise.all([loadEnterpriseList(), loadDictList()])
  116. const firstRuleId = enterpriseList.value[0]?.value
  117. if (!firstRuleId) return
  118. selectedRuleId.value = firstRuleId
  119. await loadRules(firstRuleId)
  120. }
  121. const loadEnterpriseList = async () => {
  122. try {
  123. const res = await getTaskTypeDeptListApi()
  124. enterpriseList.value = res.data
  125. } catch (error) {
  126. console.log(error)
  127. enterpriseList.value = []
  128. }
  129. }
  130. const loadDictList = async () => {
  131. try {
  132. const res = await getDictTypeApi('task_type_desc')
  133. dictList.value = res.data
  134. } catch (error) {
  135. console.log(error)
  136. dictList.value = []
  137. }
  138. }
  139. const loadRules = async (ruleId: string) => {
  140. if (!ruleId) {
  141. sections.value = []
  142. return
  143. }
  144. loading.value = true
  145. try {
  146. const res = await getTaskTypeListByRuleIdApi(ruleId)
  147. sections.value = Object.entries(res.data)
  148. .map(([title, items]) => ({ title, items }))
  149. .filter((section) => section.items.length > 0)
  150. } catch (error) {
  151. console.log(error)
  152. sections.value = []
  153. } finally {
  154. loading.value = false
  155. }
  156. }
  157. const showEnterprisePicker = () => {
  158. if (!enterpriseList.value.length) {
  159. uni.showToast({
  160. title: '暂无可切换企业',
  161. icon: 'none',
  162. })
  163. return
  164. }
  165. pickerShow.value = true
  166. }
  167. const handleEnterpriseConfirm = async (event: { value: string | string[] }) => {
  168. const ruleId = Array.isArray(event.value) ? event.value[0] : event.value
  169. if (!ruleId) return
  170. selectedRuleId.value = ruleId
  171. activeTask.value = undefined
  172. descVisible.value = false
  173. await loadRules(ruleId)
  174. }
  175. const openDesc = (task: TaskRuleItem) => {
  176. activeTask.value = task
  177. descVisible.value = true
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .rules-box {
  182. position: relative;
  183. min-height: 100vh;
  184. overflow-x: hidden;
  185. background: #019cd0;
  186. }
  187. .rules-top-img {
  188. display: block;
  189. width: 750rpx;
  190. height: 526rpx;
  191. }
  192. .enterprise-switch {
  193. position: fixed;
  194. z-index: 99;
  195. right: 0;
  196. top: 360rpx;
  197. display: flex;
  198. align-items: center;
  199. height: 76rpx;
  200. padding: 0 22rpx 0 18rpx;
  201. box-sizing: border-box;
  202. border-radius: 999rpx 0 0 999rpx;
  203. color: #ffffff;
  204. background: linear-gradient(135deg, #2f8cff 0%, #13c2c2 100%);
  205. box-shadow:
  206. 0 12rpx 28rpx rgba(19, 129, 210, 0.32),
  207. inset 0 1rpx 0 rgba(255, 255, 255, 0.32);
  208. text {
  209. font-size: 28rpx;
  210. font-weight: 700;
  211. line-height: 76rpx;
  212. white-space: nowrap;
  213. }
  214. }
  215. .enterprise-switch__icon {
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. width: 46rpx;
  220. height: 46rpx;
  221. margin-right: 10rpx;
  222. border-radius: 50%;
  223. color: #2f8cff;
  224. background: rgba(255, 255, 255, 0.96);
  225. }
  226. .table-box {
  227. min-height: calc(100vh - 526rpx);
  228. background: #019cd0;
  229. }
  230. .table-header {
  231. display: flex;
  232. align-items: center;
  233. height: 120rpx;
  234. }
  235. .table-tab {
  236. width: 50%;
  237. color: #ffffff;
  238. font-size: 38rpx;
  239. font-weight: 800;
  240. line-height: 120rpx;
  241. text-align: center;
  242. letter-spacing: 1rpx;
  243. text-shadow: 0 4rpx 12rpx rgba(0, 72, 120, 0.2);
  244. }
  245. .table-tab--left {
  246. border-right: 1rpx solid rgba(255, 255, 255, 0.78);
  247. }
  248. .table-con {
  249. padding: 0 26rpx 50rpx;
  250. }
  251. .table-bg {
  252. min-height: 420rpx;
  253. padding: 46rpx;
  254. border-radius: 18rpx;
  255. background: linear-gradient(180deg, rgba(241, 253, 255, 0.96) 0%, #ffffff 38%), #ffffff;
  256. box-shadow:
  257. inset 0 8rpx 54rpx rgba(110, 219, 255, 0.42),
  258. 0 18rpx 36rpx rgba(0, 96, 140, 0.12);
  259. }
  260. .section + .section {
  261. margin-top: 56rpx;
  262. padding-top: 42rpx;
  263. border-top: 1rpx solid rgba(104, 193, 228, 0.28);
  264. }
  265. .section-title {
  266. position: relative;
  267. display: inline-flex;
  268. align-items: center;
  269. color: #4f3a9f;
  270. font-size: 34rpx;
  271. font-weight: 800;
  272. line-height: 46rpx;
  273. }
  274. .section-title::before {
  275. content: '';
  276. width: 10rpx;
  277. height: 30rpx;
  278. margin-right: 14rpx;
  279. border-radius: 999rpx;
  280. background: linear-gradient(180deg, #24c6dc 0%, #514a9d 100%);
  281. }
  282. .table-item {
  283. display: flex;
  284. align-items: center;
  285. justify-content: space-between;
  286. margin-top: 32rpx;
  287. margin-left: 32rpx;
  288. color: #5f4b8b;
  289. font-size: 32rpx;
  290. line-height: 44rpx;
  291. }
  292. .item-left {
  293. min-width: 0;
  294. flex: 1;
  295. display: flex;
  296. align-items: center;
  297. }
  298. .task-name {
  299. min-width: 0;
  300. overflow: hidden;
  301. color: #5b4b8a;
  302. font-weight: 500;
  303. text-overflow: ellipsis;
  304. white-space: nowrap;
  305. }
  306. .tips {
  307. flex: none;
  308. width: 36rpx;
  309. height: 36rpx;
  310. margin-left: 10rpx;
  311. }
  312. .score-text {
  313. flex: none;
  314. min-width: 172rpx;
  315. margin-left: 24rpx;
  316. color: #0b8fc8;
  317. font-size: 32rpx;
  318. font-weight: 800;
  319. line-height: 44rpx;
  320. text-align: right;
  321. text-shadow: 0 4rpx 12rpx rgba(11, 143, 200, 0.12);
  322. }
  323. .loading {
  324. padding: 20rpx 0;
  325. }
  326. .loading__item {
  327. height: 72rpx;
  328. margin-top: 24rpx;
  329. border-radius: 12rpx;
  330. background: linear-gradient(90deg, #eff9fd 0%, #e0f5fb 50%, #f7fdff 100%);
  331. }
  332. .empty {
  333. padding: 80rpx 0;
  334. color: #999999;
  335. font-size: 28rpx;
  336. text-align: center;
  337. }
  338. .info {
  339. position: relative;
  340. padding: 30rpx;
  341. background: #ffffff;
  342. }
  343. .title {
  344. display: flex;
  345. align-items: center;
  346. justify-content: space-between;
  347. margin-bottom: 60rpx;
  348. text {
  349. color: #000000;
  350. font-size: 36rpx;
  351. font-weight: 600;
  352. }
  353. }
  354. .list {
  355. margin: 10rpx 0;
  356. }
  357. .tit {
  358. margin-bottom: 10rpx;
  359. color: #333333;
  360. font-size: 32rpx;
  361. }
  362. .cont {
  363. min-height: 5vh;
  364. margin-bottom: 60rpx;
  365. color: #666666;
  366. font-size: 24rpx;
  367. line-height: 42rpx;
  368. }
  369. .btn {
  370. height: 80rpx;
  371. margin-top: 40rpx;
  372. color: #333333;
  373. font-size: 30rpx;
  374. line-height: 80rpx;
  375. text-align: center;
  376. background: #f1f1f1;
  377. }
  378. </style>