message-card.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <script setup lang="ts">
  2. import { Coupon, Message } from '../../../core/libs/models'
  3. import Card from '@/components/card.vue'
  4. import { integral, interact, message, system } from '../../../core/libs/svgs'
  5. import { beforeNow } from '../../../utils/date-util'
  6. import dayjs from 'dayjs'
  7. import { MessageType, PointStatus } from '../../../core/libs/enums'
  8. import { getPointsCoupons } from '../../../core/libs/requests'
  9. import { getMessageType } from '../../../core/libs/message-types'
  10. import { useRouter } from '../../../core/utils/router'
  11. import ButtonEvo from '@/components/button-evo.vue'
  12. import { messages } from '../../../core/libs/messages'
  13. import { stringify } from 'qs'
  14. const props = withDefaults(
  15. defineProps<{ options?: Message & { selectedCoupons?: Coupon[] } }>(),
  16. {},
  17. )
  18. const emits = defineEmits<{
  19. submit: [message: Message, coupons: Coupon[]]
  20. cancel: [message: Message]
  21. selectCoupon: [message: Message, coupons: any[]]
  22. }>()
  23. const router = useRouter()
  24. const { data: coupons, run: setCoupons } = useRequest(
  25. () =>
  26. getPointsCoupons({
  27. userId: props.options.designerId,
  28. businessId: props.options.businessId,
  29. available: true,
  30. }),
  31. { initialData: [] },
  32. )
  33. const couponSelectText = computed(() => {
  34. const selectedCoupons = props.options.selectedCoupons || []
  35. const availableCoupons = coupons.value || []
  36. if (selectedCoupons.length > 0) {
  37. return `${selectedCoupons[0].brandPoints ?? 0}积分`
  38. }
  39. if (availableCoupons.length > 0) {
  40. return `${availableCoupons.length}张可用`
  41. }
  42. return '无可用'
  43. })
  44. const hasLine = computed(() => getMessageType(props.options.messageSubType)?.path)
  45. const init = async () => {
  46. if (
  47. props.options.messageType === MessageType.Integral &&
  48. props.options.messageSubType === 31 &&
  49. props.options.isRead !== '1'
  50. ) {
  51. await setCoupons()
  52. }
  53. }
  54. const handleJump = () => {
  55. if ((props.options.linkUrl ?? '') !== '') {
  56. return router.push(props.options.linkUrl)
  57. }
  58. const query: Record<string, string> = {}
  59. switch (props.options.messageSubType) {
  60. case 5:
  61. query.title = props.options.title
  62. query.contentDetail = props.options.detailBody
  63. query.createTime = String(props.options.createTime)
  64. query.viewsCount = props.options.viewCount
  65. break
  66. default:
  67. break
  68. }
  69. console.log(stringify(query))
  70. router.push(getMessageType(props.options.messageSubType)?.path + '?' + stringify(query))
  71. }
  72. watch(
  73. () => props.options,
  74. async (value, oldValue, onCleanup) => {
  75. // console.log('====>', value)
  76. await init()
  77. },
  78. )
  79. onMounted(async () => {
  80. await init()
  81. })
  82. </script>
  83. <template>
  84. <Card>
  85. <div class="grid items-center grid-cols-[38px_auto_100px]">
  86. <div class="row-start-1 col-start-1">
  87. <div
  88. class="w-[30px] h-[30px] bg-neutral-100 rounded-full mr-2 flex items-center justify-center"
  89. >
  90. <wd-img
  91. width="18"
  92. height="18"
  93. :src="
  94. {
  95. [MessageType.Integral]: integral,
  96. [MessageType.System]: system,
  97. [MessageType.Interact]: interact,
  98. }[options.messageType]
  99. "
  100. ></wd-img>
  101. </div>
  102. </div>
  103. <div class="row-start-1 col-start-2 text-start">
  104. <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-[30px]">
  105. {{
  106. String(options.messageSubType) === '5'
  107. ? getMessageType(options.messageSubType)?.desc
  108. : options.title
  109. }}
  110. </div>
  111. </div>
  112. <div class="row-start-1 col-start-3 text-end">
  113. <div class="text-black/30 text-sm font-normal font-['PingFang_SC'] leading-[10.18px]">
  114. {{ beforeNow(dayjs(options.createTime).toDate()) }}
  115. </div>
  116. </div>
  117. <div class="row-start-2 col-start-2 col-end-4">
  118. <div class="my-3 text-black/40 text-sm font-normal font-['PingFang_SC'] leading-[25px]">
  119. <!-- {{ options.detailBody }} -->
  120. <div
  121. v-if="
  122. [MessageType.Integral, MessageType.System].includes(options.messageType) &&
  123. String(options.messageSubType) !== '5'
  124. "
  125. v-html="options.detailBody"
  126. ></div>
  127. <div class="grid grid-cols-[auto_1fr] gap-x-1 gap-y-4.5">
  128. <template
  129. v-if="
  130. options.messageSubType === 31 &&
  131. options.pointsDetail?.pointsStauts === PointStatus.PendingConfirmation
  132. "
  133. >
  134. <div
  135. class="text-black/40 text-sm font-normal font-['PingFang_SC'] h-5.5 flex items-center"
  136. >
  137. 销售积分券:
  138. </div>
  139. <div
  140. class="flex items-center h-full overflow-hidden"
  141. @click="emits('selectCoupon', options, coupons)"
  142. >
  143. <div
  144. class="text-sm font-normal font-['PingFang_SC']"
  145. :class="`${coupons.length > 0 ? 'text-[#ef4343]' : 'text-black/60'}`"
  146. >
  147. <!-- {{ `${coupons.length > 0 ? `${coupons.length}张可用` : '无可用'}` }}-->
  148. {{ couponSelectText }}
  149. </div>
  150. <div class="h-5.5 flex items-center overflow-hidden">
  151. <wd-icon
  152. name="chevron-right"
  153. :custom-class="`${coupons.length > 0 ? 'text-[#ef4343]' : 'text-black/60'}`"
  154. size="16"
  155. ></wd-icon>
  156. </div>
  157. </div>
  158. </template>
  159. </div>
  160. </div>
  161. </div>
  162. <div
  163. v-if="options.coverUrl"
  164. class="row-start-3 col-start-2 col-end-4 aspect-[1.7/1] rounded-md overflow-hidden"
  165. >
  166. <wd-img width="100%" height="100%" mode="aspectFill" :src="options.coverUrl" />
  167. </div>
  168. <div v-if="hasLine" class="row-start-4 col-start-1 col-end-4 my-2">
  169. <div class="bg-[#dadada] w-full h-[1px]"></div>
  170. </div>
  171. <div class="row-start-5 col-start-2 col-end-4">
  172. <div class="text-black/40 text-xs font-normal font-['PingFang_SC']">
  173. <template
  174. v-if="
  175. [MessageType.Integral].includes(Number(options.messageType)) &&
  176. options.messageSubType === 31 &&
  177. options.pointsDetail?.pointsStauts === PointStatus.PendingConfirmation
  178. "
  179. >
  180. <span class="text-black/40">
  181. {{ messages.messages.pointNotice }}
  182. </span>
  183. </template>
  184. <template
  185. v-else-if="
  186. [MessageType.Integral].includes(Number(options.messageType)) &&
  187. options.messageSubType === 31
  188. "
  189. >
  190. <template v-if="options.pointsDetail?.pointsStauts === PointStatus.Rejected">
  191. <span class="text-[#EF4343]">
  192. <!-- 确认积分后,即刻到账,如有问题请驳回,联系材料商修改积分后再次确认 -->
  193. 已驳回,驳回原因:{{ options.pointsDetail?.cancelReason }}
  194. </span>
  195. </template>
  196. </template>
  197. <template
  198. v-else-if="
  199. [MessageType.Integral].includes(Number(options.messageType)) &&
  200. [21, 22].includes(options.messageSubType)
  201. "
  202. >
  203. 如有问题请您联系官方客服!
  204. </template>
  205. <template v-if="getMessageType(options.messageSubType)?.path">
  206. <div
  207. @click="handleJump"
  208. class="flex items-center text-[rgba(0,0,0,0.85)] text-xs font-normal font-['PingFang_SC'] leading-[25px]"
  209. >
  210. 查看详情
  211. <wd-icon name="arrow-right" size="12" color="rgba(0,0,0,0.85)"></wd-icon>
  212. </div>
  213. </template>
  214. </div>
  215. </div>
  216. <div
  217. class="row-start-6 col-start-1 col-end-4 my-1"
  218. v-if="
  219. [MessageType.Integral].includes(Number(options.messageType)) &&
  220. options.messageSubType === 31 &&
  221. options.pointsDetail?.pointsStauts === PointStatus.PendingConfirmation
  222. "
  223. >
  224. <div class="flex gap-4 mt-4">
  225. <div class="flex-1">
  226. <!-- <wd-button block :round="false" plain @click="emits('cancel', options)">驳回</wd-button> -->
  227. <ButtonEvo block color="white" location="right" @click="emits('cancel', options)">
  228. <span class="text-black/80">驳回</span>
  229. </ButtonEvo>
  230. </div>
  231. <!-- <div class="flex-1">
  232. <wd-button block :round="false" @click="handleQ(it)">积分券</wd-button>
  233. </div> -->
  234. <div class="flex-1">
  235. <!-- <wd-button block :round="false" @click="emits('submit', options)">确认</wd-button> -->
  236. <ButtonEvo block @click="emits('submit', options, coupons)">确认</ButtonEvo>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. </Card>
  242. </template>