index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view>
  3. <Calendar
  4. class="uni-calendar--hook"
  5. :selected="selected"
  6. :lunar="true"
  7. :range="false"
  8. :showMonth="true"
  9. @change="handleChange"
  10. />
  11. <uni-popup ref="popupRef" type="dialog">
  12. <view class="popupContent">
  13. <!-- <image class="img" src="https://menduner.citupro.com:3443/dev/f7b4ce5cdd4a96286640a88c868c47694fd98b536a79218d1e755498db547725.png"></image>
  14. <view class="title">{{ calendarInfo.yangli }}</view>
  15. <view class="d-flex align-center justify-center" style="margin-top: 55px;">
  16. 幸运色:
  17. <view class="luckyColor" :style="{ 'background-color': currentColor }"></view>
  18. </view>
  19. <view class="font-size-12 ss-m-t-30" style="text-align: left; color: #888;">
  20. <view>阴历:{{ calendarInfo.yinli }}</view>
  21. <view class="ss-m-y-10">宜:{{ calendarInfo.yi }}</view>
  22. <view>忌:{{ calendarInfo.ji }}</view>
  23. </view> -->
  24. <view class="content-box">
  25. <view class="text-center ss-p-y-30">
  26. <view class="yangli">{{ calendarInfo.yangli }}</view>
  27. <view class="yinli">{{ calendarInfo.yinli }}</view>
  28. <view class="d-flex align-center justify-center">
  29. <span style="color: #7f7f7f;">幸运色</span>
  30. <view class="luckyColor ss-m-l-20" :style="{ 'background-color': `${currentColor || '#2979ff'}` }"></view>
  31. </view>
  32. </view>
  33. <view class="center-box ss-p-y-30 ss-p-x-30">
  34. <view class="d-flex">
  35. <view class="yi d-flex align-center justify-center">宜</view>
  36. <view class="font-size-15" style="flex: 1; color: #c6b393;">{{ calendarInfo.yi }}</view>
  37. </view>
  38. <view class="d-flex ss-m-t-30">
  39. <view class="ji d-flex align-center justify-center">忌</view>
  40. <view class="font-size-15" style="flex: 1; color: #7f7f7f;">{{ calendarInfo.ji }}</view>
  41. </view>
  42. </view>
  43. <view class="bottom-box">
  44. <view class="bottom-box-item d-flex flex-column align-center justify-center">
  45. <view class="padding">
  46. <view class="label">五行</view>
  47. <view class="value">{{ calendarInfo.wuxing }}</view>
  48. </view>
  49. <view style="border-top: 1px solid #c2a08c; height: 1px; width: 100%;"></view>
  50. <view class="padding">
  51. <view class="label">吉神</view>
  52. <view class="value">{{ calendarInfo.jishen }}</view>
  53. </view>
  54. </view>
  55. <view class="bottom-box-item d-flex align-center justify-center">
  56. <view class="padding">
  57. <view class="label">彭祖</view>
  58. <view class="value">{{ calendarInfo.baiji }}</view>
  59. </view>
  60. </view>
  61. <view class="bottom-box-item d-flex flex-column align-center justify-center">
  62. <view class="padding">
  63. <view class="label">冲煞</view>
  64. <view class="value">{{ calendarInfo.chongsha }}</view>
  65. </view>
  66. <view style="border-top: 1px solid #c2a08c; height: 1px; width: 100%;"></view>
  67. <view class="padding">
  68. <view class="label">凶神</view>
  69. <view class="value">{{ calendarInfo.xiongshen }}</view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="text-center ss-m-t-50">
  76. <uni-icons type="close" size="40" color="#fff" @click="handleClose"></uni-icons>
  77. </view>
  78. </uni-popup>
  79. </view>
  80. </template>
  81. <script setup>
  82. import { onLoad } from '@dcloudio/uni-app'
  83. import { ref } from 'vue'
  84. import Calendar from '@/components/uni-calendar/components/uni-calendar/uni-calendar.vue'
  85. import { getDrawLots } from '@/api/drawLots.js'
  86. /**
  87. * 获取任意时间
  88. */
  89. function getDate(date, AddDayCount = 0) {
  90. if (!date) {
  91. date = new Date()
  92. }
  93. if (typeof date !== 'object') {
  94. date = date.replace(/-/g, '/')
  95. }
  96. const dd = new Date(date)
  97. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  98. const y = dd.getFullYear()
  99. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  100. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  101. return {
  102. fullDate: y + '-' + m + '-' + d,
  103. year: y,
  104. month: m,
  105. date: d,
  106. day: dd.getDay()
  107. }
  108. }
  109. const selected = ref([])
  110. const setSelectedDates = () => {
  111. selected.value = [
  112. {
  113. date: getDate(new Date(),-20).fullDate,
  114. color: '#d3e3fd',
  115. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  116. },
  117. {
  118. date: getDate(new Date(),-16).fullDate,
  119. color: '#f8bbd0',
  120. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  121. },
  122. {
  123. date: getDate(new Date(),-12).fullDate,
  124. color: '#3bb19b',
  125. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  126. },
  127. {
  128. date: getDate(new Date(),-7).fullDate,
  129. color: '#facd89',
  130. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  131. },
  132. {
  133. date: getDate(new Date(),-3).fullDate,
  134. color: '#d7ccc8',
  135. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  136. },
  137. {
  138. date: getDate(new Date(),-2).fullDate,
  139. color: '#c5cae9',
  140. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  141. }
  142. ]
  143. }
  144. onLoad(() => {
  145. // const birthday = uni.getStorageSync('birthday')
  146. // if (!birthday) {
  147. // uni.reLaunch({
  148. // url: '/pages/drawLots/form'
  149. // })
  150. // return
  151. // }
  152. // 设置选中项
  153. setTimeout(() => {
  154. setSelectedDates()
  155. }, 2000)
  156. })
  157. const popupRef = ref()
  158. const currentColor = ref(null)
  159. const calendarInfo = ref({})
  160. const handleChange = async (e) => {
  161. if (e.isBackToday) return // 点击左上角“今日”按钮不弹窗
  162. try {
  163. const { result } = await getDrawLots({ date: e.fulldate })
  164. // console.log(result, '成功信息')
  165. calendarInfo.value = result || {}
  166. popupRef.value.open()
  167. currentColor.value = result?.color || e.extraInfo?.color
  168. } catch (error) {
  169. console.log(error, '错误信息')
  170. }
  171. }
  172. const handleClose = () => {
  173. popupRef.value.close()
  174. currentColor.value = null
  175. calendarInfo.value = {}
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. $commonColor: #c2a08c;
  180. $size: 25px;
  181. .popupContent {
  182. position: relative;
  183. background-color: #fff;
  184. // border-radius: 12px;
  185. width: 70vw;
  186. // height: 400rpx;
  187. // text-align: center;
  188. padding: 30rpx;
  189. .content-box {
  190. height: 100%;
  191. border: 1px solid $commonColor;
  192. border-radius: 6px;
  193. // padding: 20rpx;
  194. }
  195. .yangli {
  196. font-weight: bold;
  197. color: $commonColor;
  198. font-size: 30px;
  199. }
  200. .yinli {
  201. color: #7f7f7f;
  202. margin: 10px 0;
  203. }
  204. .center-box {
  205. border-top: 1px solid $commonColor;
  206. border-bottom: 1px solid $commonColor;
  207. .yi {
  208. width: $size;
  209. height: $size;
  210. background-color: #c39c87;
  211. border-radius: 50%;
  212. color: #fff;
  213. margin-right: 10px;
  214. font-size: 14px;
  215. }
  216. .ji {
  217. width: $size;
  218. height: $size;
  219. background-color: #bfbfbf;
  220. border-radius: 50%;
  221. color: #fff;
  222. margin-right: 10px;
  223. font-size: 14px;
  224. }
  225. }
  226. .bottom-box {
  227. display: flex;
  228. &-item {
  229. width: 33.3%;
  230. text-align: center;
  231. border-right: 1px solid $commonColor;
  232. &:nth-child(3n) {
  233. border-right: none;
  234. }
  235. .label {
  236. font-size: 17px;
  237. }
  238. .value {
  239. color: #7f7f7f;
  240. font-size: 14px;
  241. margin-top: 10px;
  242. }
  243. .padding {
  244. padding: 10px;
  245. }
  246. }
  247. }
  248. .luckyColor {
  249. width: 50rpx;
  250. height: 50rpx;
  251. border-radius: 50%;
  252. }
  253. .img {
  254. position: absolute;
  255. top: -56px;
  256. left: 50%;
  257. transform: translateX(-50%);
  258. width: 150px;
  259. height: 150px;
  260. }
  261. .title {
  262. position: absolute;
  263. top: 7px;
  264. left: 50%;
  265. color: #F49610;
  266. font-weight: bold;
  267. transform: translateX(-50%);
  268. }
  269. }
  270. </style>