displayCard.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <div class="display-card" v-if="cardShow">
  3. <span @click="cardClose" v-if="cardShow" class="cardClose"><img src="/images/all/close.png"></span>
  4. <div class="content" v-if="cardShow">
  5. <div>
  6. <ul class="list-unstyled">
  7. <li ref="pingdanListWrapper" v-for="item in counts" :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
  8. <span>{{item.item}}</span>
  9. </li>
  10. </ul>
  11. <ul class="list-unstyled">
  12. <li ref="pingdanListWrapper" v-for="c in counts" :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
  13. <span v-for="(item, index) in formatScrollNumber(c.count, c.logo)" class="count-distance" :class="'count' + index">{{item}}</span>
  14. </li>
  15. </ul>
  16. </div>
  17. <div v-for="item in itemCounts">
  18. <p>
  19. <span v-html="item.count"></span>
  20. <span style="color: #333" v-if="item.type === 3">家</span>
  21. <span style="color: #333" v-if="item.type === 2">条</span>
  22. </p>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'display-card',
  30. data () {
  31. return {
  32. cardShow: true,
  33. timerIndex: 0,
  34. isTop: false, // 判断是否滚动至顶,
  35. timer: {} // 定时器实体
  36. }
  37. },
  38. mounted () {
  39. this.$nextTick(() => {
  40. this.changeInterval(true)
  41. })
  42. },
  43. methods: {
  44. changeInterval: function (flag) {
  45. if (flag) {
  46. this.timer = setInterval(() => {
  47. this.isTop = false
  48. let isChange = true
  49. this.timerIndex++
  50. if (this.$refs.pingdanListWrapper[0]) {
  51. let _transitionEvent = this.baseUtils.whichTransitionEvent()
  52. _transitionEvent && this.$refs.pingdanListWrapper[0].addEventListener(
  53. _transitionEvent, () => {
  54. if (isChange) {
  55. let count = this.counts.shift()
  56. this.counts.push(count)
  57. this.timerIndex = 0
  58. isChange = false
  59. this.isTop = true
  60. }
  61. })
  62. }
  63. }, 3000)
  64. } else {
  65. clearInterval(this.timer)
  66. }
  67. },
  68. cardClose () {
  69. this.cardShow = false
  70. },
  71. formatScrollNumber (num, logo) {
  72. if (num) {
  73. if (num > 99999999) {
  74. let str2 = num.toString()
  75. num = Math.floor(num / 100000000)
  76. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  77. num = num + 1
  78. }
  79. let length = String(num).length
  80. this.len = length > 3 ? length + 1 : length
  81. num = (Array(7 - length).join(0) + num)
  82. num = num.toString() + '亿'
  83. } else if (num > 9999) {
  84. let str = num.toString()
  85. num = Math.floor(num / 10000)
  86. if (parseInt(str.charAt(str.length - 4)) > 4) {
  87. num = num + 1
  88. }
  89. let length = String(num).length
  90. this.len = length > 3 ? length + 1 : length
  91. num = (Array(7 - length).join(0) + num)
  92. num = num.toString() + '万'
  93. } else {
  94. let length = String(num).length
  95. this.len = length > 3 ? length + 1 : length
  96. num = (Array(7 - length).join(0) + num)
  97. if (logo === 0) {
  98. num = num.toString() + '家'
  99. } else {
  100. num = num.toString() + '个'
  101. }
  102. }
  103. }
  104. let _arr = []
  105. for (let i = 0; i < num.length; i++) {
  106. _arr.push(num[i])
  107. }
  108. return _arr
  109. },
  110. formatNumber (num, type) {
  111. if (num) {
  112. if (num.toString().indexOf('E') !== -1) {
  113. let arr = num.toString().split('E')
  114. num = arr[0] * Math.pow(10, arr[1])
  115. }
  116. if (num > 99999999) {
  117. let str2 = num.toString()
  118. num = Math.floor(num / 100000000)
  119. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  120. num = num + 1
  121. }
  122. num += '<span style="color: #333">亿</span>'
  123. } else if (num > 9999) {
  124. let str = num.toString()
  125. num = Math.floor(num / 10000)
  126. if (parseInt(str.charAt(str.length - 4)) > 4) {
  127. num = num + 1
  128. }
  129. num += '<span style="color: #333">万</span>'
  130. } else {
  131. if (type === 1) {
  132. num += '<span style="color: #333">元</span>'
  133. } else {
  134. num += ''
  135. }
  136. }
  137. }
  138. return num
  139. },
  140. formatDouble (num) {
  141. if (num) {
  142. if (num.toString().indexOf('E') !== -1) {
  143. let arr = num.toString().split('E')
  144. num = arr[0] * Math.pow(10, arr[1])
  145. }
  146. if (num > 99999999) {
  147. num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '<span style="color: #333">亿</span>'
  148. } else if (num > 9999) {
  149. num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '<span style="color: #333">万</span>'
  150. } else {
  151. num += ''
  152. }
  153. }
  154. return num
  155. },
  156. },
  157. computed: {
  158. counter () {
  159. return this.$store.state.option.counter.data
  160. },
  161. inquirySheet () {
  162. let sheetNum = this.$store.state.count.inquirySheet.data
  163. return sheetNum ? this.formatDouble(sheetNum.count) : 0
  164. },
  165. inquirySheetLast () {
  166. let lastSheetNum = this.$store.state.count.inquirySheetLast.data
  167. return lastSheetNum ? this.formatDouble(lastSheetNum.count) : 0
  168. },
  169. itemCounts () {
  170. let arr = []
  171. let count = this.baseUtils.deepCopy(this.counter)
  172. if(count.length){
  173. count.forEach((value) => {
  174. if (value.usedFor === 'mall_home_banner') {
  175. value.type = value.detno === 2 ? 3: 1
  176. value.count = this.formatNumber(value.count)
  177. arr.push(value)
  178. }
  179. })
  180. arr = arr.sort((a,b) => {return a.detno - b.detno})
  181. arr.push({count: this.inquirySheet ? this.inquirySheet : 0, type: 2},
  182. {count: this.inquirySheetLast ? this.inquirySheetLast : 0, type: 2})
  183. }
  184. return arr
  185. },
  186. counts () {
  187. let arr = []
  188. let count = this.baseUtils.deepCopy(this.counter)
  189. if(count.length) {
  190. count.forEach((value) => {
  191. if (value.usedFor === 'b2c_index') {
  192. value.logo = value.detno === 4 ? 0: 1
  193. arr.push(value)
  194. }
  195. })
  196. arr = arr.sort((a,b) => {return a.detno - b.detno})
  197. }
  198. return arr
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .display-card{
  205. position: fixed;
  206. right: 56px;
  207. top: 182px;
  208. z-index: 100;
  209. .cardClose{
  210. position: absolute;
  211. right: -5px;
  212. top: 12px;
  213. opacity: 0.8;
  214. &:hover{
  215. cursor: pointer;
  216. }
  217. }
  218. .content{
  219. margin-top: 10px;
  220. /*width: 178px;*/
  221. /*height: 536px;*/
  222. background: url('/images/all/countBg.png') no-repeat;
  223. div{
  224. height: 56px;
  225. width: 158px;
  226. padding-top: 19px;
  227. margin-left: 16px;
  228. &:first-child{
  229. height: 109px;
  230. padding-top: 1px;
  231. ul{
  232. &:first-child{
  233. max-height: 30px;
  234. width: 100%;
  235. text-align: center;
  236. overflow: hidden;
  237. position: relative;
  238. top: 16px;
  239. li{
  240. height: 30px;
  241. line-height: 30px;
  242. font-weight: bold;
  243. font-size: 21px;
  244. letter-spacing: 0px;
  245. color: #ff3600;
  246. position: relative;
  247. top: 0;
  248. transition: top 1s;
  249. -moz-transition: top 1s; /* Firefox 4 */
  250. -webkit-transition: top 1s; /* Safari and Chrome */
  251. -o-transition: top 1s; /* Opera */
  252. &.top {
  253. transition: top 0s;
  254. -moz-transition: top 0s; /* Firefox 4 */
  255. -webkit-transition: top 0s; /* Safari and Chrome */
  256. -o-transition: top 0s; /* Opera */
  257. }
  258. }
  259. }
  260. &:last-child{
  261. max-height: 30px;
  262. width: 100%;
  263. overflow: hidden;
  264. position: relative;
  265. top: 21px;
  266. text-align: right;
  267. li{
  268. position: relative;
  269. top: 0;
  270. left: 0;
  271. margin: 0 auto;
  272. width: 141px;
  273. height: 30px;
  274. line-height: 28px;
  275. font-weight: bold;
  276. font-size: 21px;
  277. text-align: left;
  278. color: #bc1b1c;
  279. transition: top 1s;
  280. -moz-transition: top 1s;
  281. -webkit-transition: top 1s;
  282. -o-transition: top 1s;
  283. &.top {
  284. transition: top 0s;
  285. -moz-transition: top 0s; /* Firefox 4 */
  286. -webkit-transition: top 0s; /* Safari and Chrome */
  287. -o-transition: top 0s; /* Opera */
  288. }
  289. span.count-distance{
  290. display: inline-block;
  291. padding-left: 3.3px;
  292. margin-left: 2px;
  293. font-size: 18px;
  294. color: #bc1b1c;
  295. width: 17px;
  296. }
  297. span.count-distance.count6{
  298. position:relative;
  299. top: -2px;
  300. padding-left: 0;
  301. font-weight: bold;
  302. color: #fff;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. p{
  309. width: 100%;
  310. text-align: center;
  311. font-size: 20px;
  312. color: #f14e4e;
  313. }
  314. }
  315. .enter{
  316. width: 100%;
  317. display: inline-block;
  318. position: absolute;
  319. bottom: 35px;
  320. left: -5px;
  321. text-align: center;
  322. }
  323. }
  324. }
  325. </style>