message-card.vue 9.0 KB

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