Header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <header class="header">
  3. <div class="apply-adv" v-if="isShowApplyAdv">
  4. <a href="/applyPurchase#opportunities">
  5. <img src="/images/applyPurchase/apply-ad.png" alt="">
  6. </a>
  7. <i @click="ShowApplyAdv = false"></i>
  8. </div>
  9. <nav class="navbar">
  10. <div class="navbar-container container">
  11. <div class="navbar-header">
  12. <a href="http://www.ubtob.com" class="item navbar-link">
  13. <img src="/images/logo/uas.png" class="navbar-logo">
  14. <span class="navbar-slogan">进入优软云</span>
  15. </a>
  16. </div>
  17. <div class="navbar-right">
  18. <template v-if="user.logged">
  19. <div class="item-wrap dropdown">
  20. <div class="item dropdown-toggle">
  21. 欢迎您,{{ user.data.userName }}&nbsp;|&nbsp;
  22. <a @click="logout()">[退出]</a>
  23. <span>{{enterprise.enName}}</span>
  24. </div>
  25. <div class="dropdown-menu" v-if="user.data.enterprises && user.data.enterprises.length > 0">
  26. <div class="menu-item-first">
  27. <span>您可切换至以下账户:</span>
  28. </div>
  29. <ul>
  30. <!-- <li class="menu-item-first">
  31. <span class="member-text" :title="enterprise.enName"><i class="fa fa-map-marker"></i>&nbsp;{{ enterprise.uu?enterprise.enName: user.data.userName + '(个人账户)' }}</span>
  32. <a class="pull-right" @click="toggleEnterprises()" v-if="user.data.enterprises && user.data.enterprises.length > 0">
  33. {{ showEnterprises ? '取消' : '切换' }}
  34. </a>
  35. <span>您可切换至以下账户:</span>
  36. <input type="text" placeholder="请输入公司名称" v-model="keyword"><span class="search-enterprise" @click="searchEnterprise()">搜索</span>
  37. </li>-->
  38. <li class="menu-item"
  39. v-for="en in sortEnterprises"
  40. v-if="en.uu!=enterprise.uu">
  41. <a @click="switchEnterprise(en)" :title="en.enName">{{ en.enName }}</a>
  42. </li>
  43. <li class="menu-item" v-if="enterprise.uu">
  44. <a @click="switchEnterprise({uu: 0})"><span v-text="user.data.userName"></span>(个人账户)</a>
  45. </li>
  46. </ul>
  47. </div>
  48. </div>
  49. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  50. <!--<nuxt-link class="item" to="/user">买家中心</nuxt-link>
  51. <nuxt-link class="item" to="/vendor">卖家中心</nuxt-link>-->
  52. <!--<a class="item" :href="url + '/user'">买家中心</a>
  53. <a class="item" :href="url + '/vendor'">卖家中心</a>-->
  54. <a class="item" href="/user#/index">买家中心</a>
  55. <a class="item" @click="toVendor">卖家中心</a>
  56. </template>
  57. <template v-else>
  58. <a class="item" @click="onLoginClick()">登录</a>
  59. <a class="item" @click="onRegisterClick">注册</a>
  60. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  61. </template>
  62. <nuxt-link class="item" to="/help/home" target="_blank">帮助中心</nuxt-link>
  63. <!--<a class="item" href="/help#/home">帮助中心</a>-->
  64. </div>
  65. </div>
  66. </nav>
  67. </header>
  68. </template>
  69. <script>
  70. export default {
  71. name: 'headerView',
  72. data () {
  73. return {
  74. // showEnterprises: false
  75. // searchEnterpriseArr: [],
  76. // keyword: '',
  77. // isSearching: false
  78. ShowApplyAdv: true,
  79. showEnterpriseToggle: false
  80. }
  81. },
  82. computed: {
  83. isShowApplyAdv () {
  84. if (this.$route.path.indexOf('/applyPurchase') === -1) {
  85. this.ShowApplyAdv = true
  86. }
  87. return this.ShowApplyAdv && this.$route.path.indexOf('/applyPurchase') !== -1
  88. },
  89. user () {
  90. // console.log(this.$store.state.option.user)
  91. return this.$store.state.option.user
  92. },
  93. enterprise () {
  94. return this.user.data.enterprise || {}
  95. },
  96. url () {
  97. return this.$store.state.option.url
  98. }
  99. },
  100. methods: {
  101. logout () {
  102. this.$http.get('/logout/crossBefore').then(response => {
  103. if (response.data) {
  104. window.location.href = response.data.logoutUrl + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  105. }
  106. })
  107. },
  108. onLoginClick () {
  109. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  110. if (response.data) {
  111. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  112. }
  113. })
  114. // TODO 待Account Center改版
  115. },
  116. onRegisterClick () {
  117. this.$http.get('/register/page').then(response => {
  118. if (response.data) {
  119. window.location.href = response.data.content
  120. }
  121. })
  122. },
  123. // 切换当前企业
  124. switchEnterprise (en) {
  125. this.showEnterpriseToggle = false
  126. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  127. this.$store.dispatch('loadUserInfo')
  128. // let path = this.$route.path
  129. // if (path === '/register-saler' && en.uu !== 0 && en.isVendor === 313) {
  130. // window.location.href = '/vendor#/index'
  131. // } else {
  132. // window.location.reload()
  133. // }
  134. window.location.href = '/'
  135. })
  136. },
  137. toVendor: function () {
  138. let isSelf = true
  139. let tempEnterprise = {}
  140. let ens = this.user.data.enterprises
  141. if (ens && ens.length) {
  142. ens.forEach(function (item) {
  143. if (item.current) {
  144. isSelf = false
  145. tempEnterprise = item
  146. }
  147. })
  148. } else {
  149. isSelf = true
  150. }
  151. if (isSelf) {
  152. window.location.href = '/personalMaterial'
  153. } else {
  154. if (tempEnterprise.isVendor === 313) {
  155. // window.location.href = '/vendor'
  156. window.location.href = '/vendor#/index'
  157. } else {
  158. window.location.href = '/register-saler'
  159. }
  160. }
  161. }
  162. // searchEnterprise () {
  163. // let key = this.keyword
  164. // let enterprise = this.user.data.enterprises
  165. // this.isSearching = true
  166. // this.searchEnterpriseArr = []
  167. // if (this.keyword === '') {
  168. // this.isSearching = false
  169. // } else {
  170. // for (let i = 0; i < enterprise.length; i++) {
  171. // if (enterprise[i].enName.indexOf(key) !== -1) {
  172. // this.searchEnterpriseArr.push(enterprise[i])
  173. // }
  174. // }
  175. // }
  176. // }
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .header .navbar{
  182. min-height: inherit;
  183. border-radius: 0;
  184. }
  185. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  186. font-size: 12px;
  187. }
  188. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  189. width: 100%;
  190. display: inline-block;
  191. overflow: hidden;
  192. text-overflow: ellipsis;
  193. white-space: nowrap;
  194. height: 25px;
  195. }
  196. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  197. height: 30px;
  198. }
  199. .apply-adv{
  200. margin: 0 auto;
  201. min-width: 1190px;
  202. position: relative;
  203. img{
  204. max-width: 100%;
  205. min-width: 1190px;
  206. }
  207. i {
  208. background: url("/images/search/search-close.png")no-repeat;
  209. width: 16px;
  210. height: 16px;
  211. position: absolute;
  212. right: 8px;
  213. top: 8px;
  214. cursor: pointer;
  215. z-index: 20000;
  216. }
  217. }
  218. .dropdown-menu>li>a{
  219. padding: 0;
  220. line-height: 30px;
  221. }
  222. .dropdown-menu>li a:hover{
  223. background: none;
  224. text-decoration: underline !important;
  225. }
  226. .dropdown-menu>li>a.pull-right{
  227. padding: 0;
  228. color: #1162a4 !important;
  229. line-height: inherit;
  230. }
  231. .member-text{
  232. width: 80%;
  233. white-space: nowrap;
  234. overflow: hidden;
  235. text-overflow: ellipsis;
  236. display: inline-block;
  237. }
  238. @import '~assets/scss/mixins';
  239. @import '~assets/scss/variables';
  240. $nav-height: 38px;
  241. .header {
  242. /* height: $nav-height;*/
  243. .navbar {
  244. width: 100%;
  245. height: 100%;
  246. font-size: $font-size-small;
  247. background-color: $black-light;
  248. .navbar-container {
  249. .item-wrap {
  250. display: inline-block;
  251. }
  252. .item {
  253. color: $grey;
  254. display: inline-block;
  255. height: 35px;
  256. line-height: 35px;
  257. }
  258. a {
  259. color: $grey;
  260. }
  261. .navbar-header {
  262. float: left;
  263. .navbar-logo {
  264. margin-bottom: 2px;
  265. }
  266. .navbar-slogan {
  267. margin-left: $sm-pad;
  268. }
  269. }
  270. .navbar-right {
  271. float: right;
  272. .item {
  273. padding: 0 $pad;
  274. }
  275. .dropdown {
  276. .dropdown-toggle {
  277. line-height: $nav-height;
  278. border-left: 1px solid $black-light;
  279. border-right: 1px solid $black-light;
  280. height: 35px;
  281. a {
  282. margin-left: 15px;
  283. float: right;
  284. &:hover {
  285. color: $red !important;
  286. }
  287. }
  288. &:hover {
  289. border-left: 1px solid #999;
  290. border-right: 1px solid #999;
  291. }
  292. span {
  293. display: inline-block;
  294. max-width: 190px;
  295. overflow: hidden;
  296. text-overflow: ellipsis;
  297. white-space: nowrap;
  298. float: right;
  299. }
  300. }
  301. .menu-item-first {
  302. background: #eee;
  303. padding: 0 12px;
  304. line-height: 30px;
  305. font-size: 12px;
  306. >span:nth-child(1) {
  307. cursor: default;
  308. font-weight: bold;
  309. }
  310. input {
  311. width: 174px;
  312. height: 24px;
  313. margin-left: 35px;
  314. background: #fff;
  315. border: 1px solid #5078cb;
  316. padding-left: 4px;
  317. }
  318. .search-enterprise {
  319. display: inline-block;
  320. width: 36px;
  321. height: 24px;
  322. color: #fff;
  323. background: #5078cb;
  324. text-align: center;
  325. line-height: 24px;
  326. cursor: pointer;
  327. }
  328. }
  329. .dropdown-menu {
  330. padding: 0 6px 13px;
  331. margin:0;
  332. border-radius: 0;
  333. right: unset;
  334. background: #fff;
  335. border: 1px solid #999999;
  336. border-top: none;
  337. -webkit-box-shadow: none;
  338. -moz-box-shadow: none;
  339. box-shadow: none;
  340. ::-webkit-scrollbar {
  341. background: #f6f6f6;
  342. }
  343. ul {
  344. max-height: 300px;
  345. overflow-y: auto;
  346. background: #f6f6f6;
  347. }
  348. .menu-item {
  349. padding: 0 12px;
  350. a {
  351. color: #333;
  352. max-width: 300px;
  353. line-height: 30px;
  354. width: auto;
  355. &:hover {
  356. color: #5078cb;
  357. text-decoration: none!important;
  358. }
  359. }
  360. }
  361. }
  362. &:hover {
  363. background-color: $white;
  364. .dropdown-toggle {
  365. color: $text;
  366. }
  367. a {
  368. color: $text
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }
  375. }
  376. </style>