header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <div class="header-layout" >
  3. <div class="h-left" v-if="!isBack" @click="active = !active">
  4. <div class="l-con" :class="{active:active}" >
  5. <span class="l1"></span>
  6. <span class="l2"></span>
  7. <span class="l3"></span>
  8. </div>
  9. </div>
  10. <div @click="backHome?$router.push({name:'home'}):$router.back()" class="h-left back" v-else>
  11. <i class="iconfont icon-jiantou"></i>
  12. </div>
  13. <div class="h-center" @click="$router.push({name: 'home'})">
  14. <vcenter>
  15. <h-icon :type="language === 'zh' ? 'logo' : 'hengbiaoEN'" class="logo-icon"></h-icon>
  16. <!-- <img v-if="!isBack||$route.name==='useimg'" :src="language==='en'?`${$cdn}images/logo-en.png`:`${$cdn}images/logo.png`" @click="()=>{goto({name:'home'})} " alt> -->
  17. <!-- <div v-else>{{$route.name==='consumpdetail'?titleName[$route.name][$route.params.id]:titleName[$route.name]}}</div> -->
  18. </vcenter>
  19. </div>
  20. <div class="h-right">
  21. <div class="h-user" v-if="isAccout||isLogin">
  22. <i class="iconfont icon-cart" :style="{opacity:language==='en'?0:1}" @click="gocart"><span>{{count>99?'99+':count}}</span></i>
  23. <img ref="userList" :src="`${$cdn}images/icon/nav_icon.png`" @click="userList=!userList,active = false" alt="">
  24. <ul :style="{width:language==='en'?'160px':'110px'}" :class="{'ul-active':userList}" >
  25. <li v-for="(item,i) in langHeader.manage" :key="i" @click="handleClick(item)">{{item.name}}</li>
  26. </ul>
  27. </div>
  28. <div class="btn-buy" v-else-if="$route.name!=='purchase'&&$route.name!=='purchasetwo'&&$route.name!=='purchasezhijia'" @click="buy" >{{$t('header.online_shop')}}</div>
  29. </div>
  30. <div class="nav-active" :style="{maxHeight:active?'100vh':'0'}">
  31. <div class="nav-mask" :style="{position: active? 'fixed' : 'absolute'}"></div>
  32. <div class="nav-content">
  33. <ul v-for="(item, index) in navs" :key="index">
  34. <li>
  35. <div class="n-name" @click="clickItem(item, index)">
  36. <span>{{item.name}}</span>
  37. <h-icon type="shang" class="icon" :class="{active: activeIdx===index}"></h-icon>
  38. </div>
  39. <div class="n-child" :class="{'open':activeIdx === index}">
  40. <div v-for="(sub,i) in item.childs" :key="i" @click="goto(sub.url)">
  41. <i class="iconfont" :class="sub.icon"></i>
  42. <span :style="{minWidth:index==='cpgm'?'120px':'60px'}" v-html="sub.name"></span>
  43. <img v-if="sub.isNew" class="new-icon" :src="`${$cdn}images/new.png`" alt="">
  44. </div>
  45. </div>
  46. </li>
  47. </ul>
  48. <ul v-if="!noEnglish">
  49. <li>
  50. <div class="n-name" @click="activeIdx = 'language'">
  51. <span>{{ languageName }}</span>
  52. <h-icon type="shang" class="icon" :class="{active: activeIdx==='language'}"></h-icon>
  53. </div>
  54. <div class="n-child" :class="{'open':activeIdx === 'language'}">
  55. <div v-for="(sub,i) in languageList" :key="i" @click="changLang(sub.value)">
  56. <span :style="{minWidth:i==='cpgm'?'120px':'60px'}" v-html="sub.name"></span>
  57. </div>
  58. </div>
  59. </li>
  60. </ul>
  61. </div>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import vcenter from '@/components/vcenter/'
  67. import { mapState } from 'vuex'
  68. import Paging from '@/components/Paging'
  69. import browser from '@/util/browser'
  70. let hasBack = [
  71. 'introduce',
  72. 'introtow',
  73. 'openInvoice',
  74. 'orderInvoice',
  75. 'consumpdetail',
  76. 'useimg'
  77. ]
  78. let showUser = [
  79. 'purchase',
  80. 'purchasezhijia',
  81. 'purchasetwo',
  82. 'about',
  83. 'useimg',
  84. 'location',
  85. 'service'
  86. ]
  87. let noEngList = {
  88. 'cart': true,
  89. 'confirm': true,
  90. 'paytype': true,
  91. 'openInvoice': true,
  92. 'vieworder': true
  93. }
  94. let titleName = {
  95. 'introduce': '扩充容量',
  96. 'introtow': '点数充值',
  97. 'consumpdetail': {
  98. 0: '扩容记录',
  99. 1: '充值记录',
  100. 2: '增值记录'
  101. },
  102. 'openInvoice': '开具发票'
  103. }
  104. let titleNameEn = {
  105. 'introduce': 'Expansion',
  106. 'introtow': '点数充值',
  107. 'consumpdetail': {
  108. 0: 'Billing Records',
  109. 1: '充值记录',
  110. 2: '增值发票'
  111. },
  112. 'openInvoice': '开具发票'
  113. }
  114. let typeArr = {
  115. 2: '房地产',
  116. 1: '博物馆',
  117. 5: '家居',
  118. 4: '餐饮',
  119. 0: '其他'
  120. }
  121. let typeArrEn = {
  122. 2: 'Real estate',
  123. 1: 'Museum',
  124. 5: 'Home',
  125. 4: 'Catering',
  126. 0: 'Others'
  127. }
  128. export default {
  129. computed: {
  130. ...mapState({
  131. token: state => state.user.token,
  132. langHeader: state => state.language.home.headers,
  133. language: state => state.language.current,
  134. languageList: state => state.language.languageList,
  135. info: state => state.user.info
  136. }),
  137. languageName () {
  138. let language = this.languageList.filter(item => item.value === this.language)
  139. return language[0] ? language[0].name : '简体中文'
  140. },
  141. typeArr: function () {
  142. return this.language === 'en' ? typeArrEn : typeArr
  143. },
  144. titleName: function () {
  145. return this.language === 'en' ? titleNameEn : titleName
  146. },
  147. noEnglish () {
  148. return noEngList[this.$route.name]
  149. },
  150. isBack: function () {
  151. for (let i = 0; i < hasBack.length; i++) {
  152. let ele = hasBack[i]
  153. if (this.$route.name === ele) {
  154. return true
  155. }
  156. }
  157. return false
  158. },
  159. isAccout: function () {
  160. if (this.$route.name === 'introduce' || this.$route.name === 'introtow') {
  161. return true
  162. }
  163. if (this.$route.matched.length > 0) {
  164. return this.$route.matched[0]['name'] === 'manage'
  165. }
  166. return false
  167. },
  168. isLogin: function () {
  169. if (this.$route.name === 'scenesearch') {
  170. return true
  171. }
  172. if (this.token) {
  173. for (let i = 0; i <= showUser.length; i++) {
  174. if (this.$route.name === showUser[i]) {
  175. return true
  176. }
  177. }
  178. }
  179. return false
  180. }
  181. },
  182. data () {
  183. return {
  184. active: false,
  185. searchActive: false,
  186. searchTxt: '',
  187. activeIdx: '',
  188. count: 0,
  189. backHome: false,
  190. total: 0,
  191. pageSize: 10,
  192. currentPage: 1,
  193. scene: [],
  194. showCount: false,
  195. userList: false,
  196. browserLang: browser.language,
  197. navs: [
  198. {
  199. name: this.$t('header.core_product'),
  200. url: '/coreProduct'
  201. },
  202. {
  203. name: this.$t('header.solutions'),
  204. childs: [
  205. {
  206. name: this.$t('header.solutionsHouse'),
  207. url: '/conduct/house'
  208. },
  209. {
  210. name: this.$t('header.solutionsExi'),
  211. url: '/conduct/exhibition'
  212. },
  213. {
  214. name: this.$t('header.solutionsSubject'),
  215. url: '/conduct/subject'
  216. },
  217. {
  218. name: this.$t('header.solutionsShop'),
  219. url: '/conduct/shop'
  220. },
  221. {
  222. name: this.$t('header.solutionsSec'),
  223. url: '/conduct/secury'
  224. }
  225. ]
  226. },
  227. {
  228. name: this.$t('header.kankan_space'),
  229. url: '/cases/全部'
  230. },
  231. {
  232. name: this.$t('header.core_tech'),
  233. url: '/location'
  234. },
  235. {
  236. name: this.$t('header.service'),
  237. childs: [
  238. {
  239. name: this.$t('header.serviceApp'),
  240. url: '/service/app'
  241. },
  242. {
  243. name: this.$t('header.serviceUse'),
  244. url: '/service/use'
  245. },
  246. {
  247. name: this.$t('header.serviceBaoxiu'),
  248. url: '/service/clause'
  249. },
  250. {
  251. name: this.$t('header.serviceVideo'),
  252. url: '/video-course'
  253. }
  254. ]
  255. },
  256. {
  257. name: this.$t('header.about'),
  258. childs: [
  259. {
  260. name: this.$t('header.aboutCompany'),
  261. url: '/about'
  262. },
  263. {
  264. name: this.$t('header.aboutNews'),
  265. url: '/news'
  266. },
  267. {
  268. name: this.$t('header.aboutAgent'),
  269. url: '/agent'
  270. }
  271. ]
  272. },
  273. {
  274. name: this.$t('header.myAccount'),
  275. url: '/login',
  276. needLogin: true
  277. }
  278. ]
  279. }
  280. },
  281. watch: {
  282. '$route.query': function (newVal) {
  283. if (newVal.lang) {
  284. newVal.lang === 'en' ? this.$store.commit('change_language', 'en') : this.$store.commit('change_language', '中')
  285. }
  286. this.backHome = newVal.token
  287. // let lang = this.$route.query.lang
  288. // this.$store.commit('change_language', lang)
  289. },
  290. currentPage () {
  291. this.getData()
  292. },
  293. language (newVal) {
  294. document.title = newVal === 'en' ? '4DKanKan' : '四维看看'
  295. },
  296. searchTxt (newVal) {
  297. if (newVal) {
  298. this.currentPage === 1 ? this.getData() : this.currentPage = 1
  299. } else {
  300. this.scene = []
  301. }
  302. }
  303. },
  304. mounted () {
  305. // let lang = ~this.browserLang.indexOf('zh') ? 'zh' : 'en'
  306. // this.$store.commit('change_language', lang)
  307. document.addEventListener('click', (e) => {
  308. if (this.$refs.userList) {
  309. if (!this.$refs.userList.contains(e.target)) {
  310. this.userList = false
  311. }
  312. }
  313. })
  314. if (this.token) {
  315. let cart = JSON.parse(this.$store.state.user.cart)
  316. let count = 0
  317. cart.forEach(item => {
  318. count += item.goodsCount
  319. })
  320. this.count = count
  321. }
  322. this.$bus.$on('updateCart', data => {
  323. this.count = data
  324. })
  325. },
  326. methods: {
  327. gocart () {
  328. if (this.language !== 'en') {
  329. this.active = false
  330. this.$router.push({path: '/cart'})
  331. }
  332. },
  333. handleClick (item) {
  334. if (item.to === 'logout') {
  335. this.$toast.showConfirm('warn', this.language === 'en' ? 'Are you sure to log out?' : '确定要退出登录吗?', async () => {
  336. await this.$store.dispatch('logout')
  337. this.$router.push({name: 'home'})
  338. })
  339. } else {
  340. this.$router.push(item.to)
  341. }
  342. this.userList = false
  343. },
  344. clickItem (item, index) {
  345. if (item.url) {
  346. this.active = false
  347. if (item.url === '/login' && this.token) {
  348. this.$router.push({
  349. path: '/information'
  350. })
  351. } else {
  352. this.$router.push({
  353. path: item.url,
  354. query: {
  355. id: item.id
  356. }
  357. })
  358. }
  359. this.activeIdx = ''
  360. } else if (this.activeIdx !== index) {
  361. this.activeIdx = index
  362. } else {
  363. this.activeIdx = ''
  364. }
  365. },
  366. changLang (lang) {
  367. this.$store.commit('change_language', lang)
  368. window.location.reload()
  369. this.active = false
  370. },
  371. linkto (url) {
  372. location.href = url.replace('http://', 'https://') + (this.language === 'en' ? '&lang=en' : '')
  373. },
  374. maskTitle (name) {
  375. if (!name) { return '' }
  376. let html = ''
  377. var arr = name.split(this.searchTxt)
  378. html = arr.join('<span style="background:#feced4;">' + this.searchTxt + '</span>')
  379. return html
  380. },
  381. buy () {
  382. let name = this.$route.name
  383. if (name === 'binocular' || name === 'purchasetwo') {
  384. this.$router.push({name: 'purchasetwo'})
  385. } else if (name === 'zhijia' || name === 'purchasezhijia') {
  386. this.$router.push({name: 'purchasezhijia'})
  387. } else {
  388. this.$router.push({name: 'purchase'})
  389. }
  390. this.active = false
  391. },
  392. goto (to) {
  393. this.$router.push(to)
  394. this.active = false
  395. },
  396. format (time) {
  397. let date = new Date(time)
  398. return date.format('yyyy-MM-dd')
  399. },
  400. async getData () {
  401. document.querySelector('#search-result').scrollTo(0, 0)
  402. let params = {
  403. pageSize: this.pageSize,
  404. pageNum: this.currentPage,
  405. searchKey: this.searchTxt
  406. }
  407. let result = await this.$http({
  408. method: 'post',
  409. data: params,
  410. url: '/scene/search'
  411. })
  412. let data = result.data.data
  413. this.scene = data.list
  414. this.total = data.total
  415. this.showCount = true
  416. }
  417. },
  418. components: {
  419. vcenter,
  420. Paging
  421. }
  422. }
  423. </script>
  424. <style lang="scss" scoped>
  425. @import './style.scss';
  426. </style>