displayCard.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. count.forEach((value) => {
  173. if (value.usedFor === 'mall_home_banner') {
  174. value.type = value.detno === 2 ? 3: 1
  175. value.count = this.formatNumber(value.count)
  176. arr.push(value)
  177. }
  178. })
  179. arr = arr.sort((a,b) => {return a.detno - b.detno})
  180. arr.push({count: this.inquirySheet ? this.inquirySheet : 0, type: 2},
  181. {count: this.inquirySheetLast ? this.inquirySheetLast : 0, type: 2})
  182. return arr
  183. },
  184. counts () {
  185. let arr = []
  186. let count = this.baseUtils.deepCopy(this.counter)
  187. count.forEach((value) => {
  188. if (value.usedFor === 'b2c_index') {
  189. value.logo = value.detno === 4 ? 0: 1
  190. arr.push(value)
  191. }
  192. })
  193. arr = arr.sort((a,b) => {return a.detno - b.detno})
  194. return arr
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .display-card{
  201. position: fixed;
  202. right: 116px;
  203. top: 235px;
  204. /*width: 180px;*/
  205. /*height: 540px;*/
  206. z-index: 100;
  207. .cardClose{
  208. position: absolute;
  209. right: -5px;
  210. top: 12px;
  211. opacity: 0.8;
  212. &:hover{
  213. cursor: pointer;
  214. }
  215. }
  216. .content{
  217. margin-top: 10px;
  218. /*width: 178px;*/
  219. /*height: 536px;*/
  220. background: url('/images/all/countBg.png') no-repeat;
  221. div{
  222. height: 56px;
  223. width: 158px;
  224. padding-top: 19px;
  225. margin-left: 16px;
  226. &:first-child{
  227. height: 109px;
  228. padding-top: 1px;
  229. ul{
  230. &:first-child{
  231. max-height: 30px;
  232. width: 100%;
  233. text-align: center;
  234. overflow: hidden;
  235. position: relative;
  236. top: 16px;
  237. li{
  238. height: 30px;
  239. line-height: 30px;
  240. font-weight: bold;
  241. font-size: 21px;
  242. letter-spacing: 0px;
  243. color: #ff3600;
  244. position: relative;
  245. top: 0;
  246. transition: top 1s;
  247. -moz-transition: top 1s; /* Firefox 4 */
  248. -webkit-transition: top 1s; /* Safari and Chrome */
  249. -o-transition: top 1s; /* Opera */
  250. &.top {
  251. transition: top 0s;
  252. -moz-transition: top 0s; /* Firefox 4 */
  253. -webkit-transition: top 0s; /* Safari and Chrome */
  254. -o-transition: top 0s; /* Opera */
  255. }
  256. }
  257. }
  258. &:last-child{
  259. max-height: 30px;
  260. width: 100%;
  261. overflow: hidden;
  262. position: relative;
  263. top: 21px;
  264. text-align: right;
  265. li{
  266. position: relative;
  267. top: 0;
  268. left: 0;
  269. margin: 0 auto;
  270. width: 141px;
  271. height: 30px;
  272. line-height: 28px;
  273. font-weight: bold;
  274. font-size: 21px;
  275. text-align: left;
  276. color: #bc1b1c;
  277. transition: top 1s;
  278. -moz-transition: top 1s;
  279. -webkit-transition: top 1s;
  280. -o-transition: top 1s;
  281. &.top {
  282. transition: top 0s;
  283. -moz-transition: top 0s; /* Firefox 4 */
  284. -webkit-transition: top 0s; /* Safari and Chrome */
  285. -o-transition: top 0s; /* Opera */
  286. }
  287. span.count-distance{
  288. display: inline-block;
  289. padding-left: 3.3px;
  290. margin-left: 2px;
  291. font-size: 18px;
  292. color: #bc1b1c;
  293. width: 17px;
  294. }
  295. span.count-distance.count6{
  296. position:relative;
  297. top: -2px;
  298. padding-left: 0;
  299. font-weight: bold;
  300. color: #fff;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. p{
  307. width: 100%;
  308. text-align: center;
  309. font-size: 20px;
  310. color: #f14e4e;
  311. }
  312. }
  313. .enter{
  314. width: 100%;
  315. display: inline-block;
  316. position: absolute;
  317. bottom: 35px;
  318. left: -5px;
  319. text-align: center;
  320. }
  321. }
  322. }
  323. </style>