index.vue 9.8 KB

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