common-header.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <!-- 头部 -->
  3. <div class="head">
  4. <div :class="['content',this.$store.state.locale == 'en'?'content-en':'']">
  5. <nuxt-link to="/" class="logo">
  6. <img class="logo-img" v-if="webConfigData.pcLogoImgText" :src="webConfigData.pcLogoImgText"/>
  7. <!--<div class="name">
  8. <span class="cn">蓝海创新科技</span>
  9. <span class="en">Blue Ocean Mall</span>
  10. </div>-->
  11. </nuxt-link>
  12. <div :class="['menu',this.$store.state.locale == 'en'?'menu-en':'']">
  13. <nuxt-link to="/" class="item" >{{ $t('commonHead.home') }}</nuxt-link>
  14. <nuxt-link
  15. to="/list?st=0"
  16. :class="[
  17. 'item',
  18. $route.path == '/list' && $route.query.st == 0 ? 'item-on' : ''
  19. ]"
  20. >{{ $t('commonHead.productList') }}</nuxt-link
  21. >
  22. <nuxt-link
  23. to="/list?st=1"
  24. :class="[
  25. 'item',
  26. $route.path == '/list' && $route.query.st == 1 ? 'item-on' : ''
  27. ]"
  28. >{{ $t('commonHead.newProducts') }}</nuxt-link
  29. >
  30. <nuxt-link
  31. to="/special-discount"
  32. :class="['item', $route.path == '/special-discount' || $route.path == '/discount-detail' ? 'item-on' : '']"
  33. >{{ $t('commonHead.limitedTimeOffer') }}</nuxt-link
  34. >
  35. <nuxt-link
  36. to="/group-buy"
  37. :class="['item', $route.path == '/group-buy' ? 'item-on' : '']"
  38. >{{ $t('commonHead.groupDiscount') }}</nuxt-link
  39. >
  40. <nuxt-link
  41. to="/flash-sale"
  42. :class="['item', $route.path == '/flash-sale' ? 'item-on' : '']"
  43. >{{ $t('commonHead.spikeSpecial') }}</nuxt-link
  44. >
  45. <!-- <nuxt-link
  46. to="/coupons"
  47. :class="['item', $route.path == '/coupons' ? 'item-on' : '']"
  48. >领券中心</nuxt-link> -->
  49. <a
  50. href="javascript:void(0)"
  51. :class="['item', $route.path == '/coupons' ? 'item-on' : '']"
  52. @click="toCoupons"
  53. >{{ $t('commonHead.voucherCenter') }}</a>
  54. </div>
  55. <div class="search">
  56. <div class="search-input-box">
  57. <input
  58. type="text"
  59. v-model="searchTerms"
  60. class="search-input"
  61. @keyup.enter="toSearchProdPage"
  62. :placeholder="$t('searchByStOrpN')"
  63. />
  64. <div class="select-search" @click="selectChoose" :style="$t('language')=='en'?productShop:''">
  65. {{ searchItem }}
  66. </div>
  67. <ul class="select-list" v-if="showSelectItem">
  68. <li class="select-item" @click="selectSearchItem(0)">{{$t('index.prod')}}</li>
  69. <li class="select-item" @click="selectSearchItem(1)">{{$t('index.shop')}}</li>
  70. </ul>
  71. </div>
  72. <input
  73. type="submit"
  74. class="search-btn"
  75. :value="this.$t('index.search')"
  76. @click="toSearchProdPage"
  77. :style="$t('language')=='en'?'letter-spacing: 0px;':'letter-spacing: 2px;'"
  78. />
  79. </div>
  80. </div>
  81. <!-- 登录弹窗组件 -->
  82. <LoginPopup v-if="showLogin" v-on:hideLoginPop="hideLoginPop" />
  83. <!-- /登录弹窗组件 -->
  84. </div>
  85. <!-- /头部 -->
  86. </template>
  87. <script>
  88. import Cookie from 'js-cookie'
  89. import LoginPopup from '~/components/login-popup'
  90. export default {
  91. components: {
  92. LoginPopup
  93. },
  94. data () {
  95. return {
  96. showLogin: false,
  97. searchItem: this.$t('index.prod'), //搜索框内容
  98. showSelectItem: false, //下拉框显隐
  99. searchTerms: this.$route.query.pn, //搜索词
  100. searchType: 0, //搜索类型 0商品 1店铺
  101. tabType: this.$router.history.current.query.st || 0,
  102. webConfigData: {},
  103. language: this.$store.state.locale,
  104. fontStyleDowmEn:{
  105. fontSize:'14px',
  106. padding:'0 15px'
  107. },
  108. productShop:{
  109. position: "relative",
  110. left: "-9px"
  111. }
  112. }
  113. },
  114. watch: {
  115. '$route' (to, from) { //监听路由是否变化
  116. if (to.query.st != from.query.st) {
  117. this.tabType = to.query.st
  118. }
  119. this.searchTerms = ''
  120. if (!to.query.st) {
  121. if (to.path == '/group-buy') {
  122. this.tabType = 3
  123. } else if (this.$router.history.current.path == '/special-discount') {
  124. this.tabType = 2
  125. } else if (this.$router.history.current.path == '/flash-sale') {
  126. this.tabType = 4
  127. } else if (this.$router.history.current.path == '/coupons') {
  128. this.tabType = 5
  129. } else {
  130. this.tabType = 0
  131. }
  132. }
  133. },
  134. // 监听搜索框搜索词是否为空
  135. // searchTerms (newValue,oldValue) {
  136. // if(newValue == '') {
  137. // oldValue = ''
  138. // this.$router.history.current.query.pn = newValue
  139. // }
  140. // this.$router.history.current.query.pn = newValue
  141. // }
  142. },
  143. created () {
  144. if (this.$router.history.current.path == '/group-buy') {
  145. this.tabType = 3
  146. } else if (this.$router.history.current.path == '/flash-sale') {
  147. this.tabType = 4
  148. } else if (this.$router.history.current.path == '/coupons') {
  149. this.tabType = 5
  150. } else {
  151. this.tabType = 0
  152. }
  153. },
  154. mounted () {
  155. console.log(this.$route.query);
  156. if (this.$route.query&&this.$route.query.shopName) {
  157. this.selectSearchItem(1)
  158. this.searchTerms=this.$route.query.shopName
  159. }
  160. // 获取网站配置信息
  161. this.webConfigData = JSON.parse(localStorage.getItem('webConfig') || '{}')
  162. },
  163. methods: {
  164. /**
  165. * 统一跳转方法
  166. */
  167. routeTo (e) {
  168. let path = e.target.dataset.route
  169. switch (path) {
  170. case 'logoIndex':
  171. this.$router.push({ path: '/' })
  172. break;
  173. case 'index':
  174. this.$router.push({ path: '/' })
  175. break;
  176. case 'newArrivals':
  177. this.$router.push({ path: '' })
  178. break;
  179. case 'preferential':
  180. this.$router.push({ path: '' })
  181. break;
  182. case 'teamBuying':
  183. this.$router.push({ path: '' })
  184. break;
  185. case 'seckill':
  186. this.$router.push({ path: '' })
  187. break;
  188. case 'couponCenter':
  189. this.$router.push({ path: 'user-center/uc-coupons' })
  190. break;
  191. default:
  192. break;
  193. }
  194. },
  195. /**
  196. * 领券中心
  197. */
  198. toCoupons () {
  199. // if (Cookie.get('token')) {
  200. // console.log('token1:',Cookie.get('token'))
  201. // this.$router.push({ path: '/coupons' })
  202. // } else {
  203. // console.log('token2:',Cookie.get('token'))
  204. // this.showLogin = true
  205. // }
  206. console.log('coupons')
  207. this.$router.push({ path: '/coupons' })
  208. },
  209. /**
  210. * 隐藏登录弹窗
  211. */
  212. hideLoginPop () {
  213. this.showLogin = false
  214. },
  215. /** 搜索框选择 */
  216. selectChoose () {
  217. this.showSelectItem = !this.showSelectItem
  218. },
  219. /** 点击选择 店铺 || 商品 */
  220. selectSearchItem (sts) {
  221. if (sts === 0) {
  222. this.searchItem = this.$t('index.prod')
  223. this.showSelectItem = false
  224. this.searchType = 0 //商品
  225. } else if (sts === 1) {
  226. this.searchItem = this.$t('index.shop')
  227. this.showSelectItem = false
  228. this.searchType = 1 //店铺
  229. }
  230. },
  231. /**
  232. * 失去焦点
  233. */
  234. // changeSearchTerms (searchTerms) {
  235. // this.searchTerms = searchTerms
  236. // this.toSearchProdPage
  237. // },
  238. /**
  239. * 搜索
  240. */
  241. toSearchProdPage () {
  242. var searchType = this.searchType
  243. if(this.searchTerms!==undefined){
  244. var searchTerms = this.searchTerms.trim() //去除字符串的头尾空格
  245. }
  246. if (searchType == 0) {
  247. if (!searchTerms) {
  248. this.$message({
  249. message: this.$t('commonHead.productNameCannotBeEmpty'),
  250. type: 'error',
  251. duration: 1000
  252. })
  253. return
  254. }
  255. // 跳转到商品列表页
  256. this.$router.push({ path: '/list?pn=' + searchTerms })
  257. } else if (searchType == 1) {
  258. if (!searchTerms) {
  259. this.$message({
  260. message: this.$t('commonHead.storeNameCannotBeEmpty'),
  261. type: 'error',
  262. duration: 1000
  263. })
  264. return
  265. }
  266. // 跳转到店铺列表页
  267. this.$router.push({ path: '/shopList?shopName=' + searchTerms })
  268. }
  269. },
  270. },
  271. }
  272. </script>
  273. <style scoped src='~/assets/css/home.css'></style>