Header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. sortEnterprises () {
  97. if (this.user.data.enterprises) {
  98. let ens = this.user.data.enterprises.slice()
  99. if (ens && ens.length) {
  100. ens.sort(function (a, b) {
  101. return b.lastLoginTime - a.lastLoginTime
  102. })
  103. }
  104. return ens
  105. } else {
  106. return ''
  107. }
  108. },
  109. url () {
  110. return this.$store.state.option.url
  111. }
  112. },
  113. methods: {
  114. logout () {
  115. this.$http.get('/logout/crossBefore').then(response => {
  116. if (response.data) {
  117. window.location.href = response.data.logoutUrl + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  118. }
  119. })
  120. },
  121. onLoginClick () {
  122. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  123. if (response.data) {
  124. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  125. }
  126. })
  127. // TODO 待Account Center改版
  128. },
  129. onRegisterClick () {
  130. this.$http.get('/register/page').then(response => {
  131. if (response.data) {
  132. window.location.href = response.data.content
  133. }
  134. })
  135. },
  136. // 切换当前企业
  137. switchEnterprise (en) {
  138. this.showEnterpriseToggle = false
  139. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  140. this.$store.dispatch('loadUserInfo')
  141. // let path = this.$route.path
  142. // if (path === '/register-saler' && en.uu !== 0 && en.isVendor === 313) {
  143. // window.location.href = '/vendor#/index'
  144. // } else {
  145. // window.location.reload()
  146. // }
  147. window.location.href = '/'
  148. })
  149. },
  150. toVendor: function () {
  151. let isSelf = true
  152. let tempEnterprise = {}
  153. let ens = this.user.data.enterprises
  154. if (ens && ens.length) {
  155. ens.forEach(function (item) {
  156. if (item.current) {
  157. isSelf = false
  158. tempEnterprise = item
  159. }
  160. })
  161. } else {
  162. isSelf = true
  163. }
  164. if (isSelf) {
  165. window.location.href = '/personalMaterial'
  166. } else {
  167. if (tempEnterprise.isVendor === 313) {
  168. // window.location.href = '/vendor'
  169. window.location.href = '/vendor#/index'
  170. } else {
  171. window.location.href = '/register-saler'
  172. }
  173. }
  174. }
  175. // searchEnterprise () {
  176. // let key = this.keyword
  177. // let enterprise = this.user.data.enterprises
  178. // this.isSearching = true
  179. // this.searchEnterpriseArr = []
  180. // if (this.keyword === '') {
  181. // this.isSearching = false
  182. // } else {
  183. // for (let i = 0; i < enterprise.length; i++) {
  184. // if (enterprise[i].enName.indexOf(key) !== -1) {
  185. // this.searchEnterpriseArr.push(enterprise[i])
  186. // }
  187. // }
  188. // }
  189. // }
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. .header .navbar{
  195. min-height: inherit;
  196. border-radius: 0;
  197. }
  198. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  199. font-size: 12px;
  200. }
  201. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  202. width: 100%;
  203. display: inline-block;
  204. overflow: hidden;
  205. text-overflow: ellipsis;
  206. white-space: nowrap;
  207. height: 25px;
  208. }
  209. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  210. height: 30px;
  211. }
  212. .apply-adv{
  213. margin: 0 auto;
  214. min-width: 1190px;
  215. position: relative;
  216. img{
  217. max-width: 100%;
  218. min-width: 1190px;
  219. }
  220. i {
  221. background: url("/images/search/search-close.png")no-repeat;
  222. width: 16px;
  223. height: 16px;
  224. position: absolute;
  225. right: 8px;
  226. top: 8px;
  227. cursor: pointer;
  228. z-index: 20000;
  229. }
  230. }
  231. .dropdown-menu>li>a{
  232. padding: 0;
  233. line-height: 30px;
  234. }
  235. .dropdown-menu>li a:hover{
  236. background: none;
  237. text-decoration: underline !important;
  238. }
  239. .dropdown-menu>li>a.pull-right{
  240. padding: 0;
  241. color: #1162a4 !important;
  242. line-height: inherit;
  243. }
  244. .member-text{
  245. width: 80%;
  246. white-space: nowrap;
  247. overflow: hidden;
  248. text-overflow: ellipsis;
  249. display: inline-block;
  250. }
  251. @import '~assets/scss/mixins';
  252. @import '~assets/scss/variables';
  253. $nav-height: 38px;
  254. .header {
  255. /* height: $nav-height;*/
  256. .navbar {
  257. width: 100%;
  258. height: 100%;
  259. font-size: $font-size-small;
  260. background-color: $black-light;
  261. .navbar-container {
  262. .item-wrap {
  263. display: inline-block;
  264. }
  265. .item {
  266. color: $grey;
  267. display: inline-block;
  268. height: 35px;
  269. line-height: 35px;
  270. }
  271. a {
  272. color: $grey;
  273. }
  274. .navbar-header {
  275. float: left;
  276. .navbar-logo {
  277. margin-bottom: 2px;
  278. }
  279. .navbar-slogan {
  280. margin-left: $sm-pad;
  281. }
  282. }
  283. .navbar-right {
  284. float: right;
  285. .item {
  286. padding: 0 $pad;
  287. }
  288. .dropdown {
  289. .dropdown-toggle {
  290. line-height: $nav-height;
  291. border-left: 1px solid $black-light;
  292. border-right: 1px solid $black-light;
  293. height: 35px;
  294. a {
  295. margin-left: 15px;
  296. float: right;
  297. &:hover {
  298. color: $red !important;
  299. }
  300. }
  301. &:hover {
  302. border-left: 1px solid #999;
  303. border-right: 1px solid #999;
  304. }
  305. span {
  306. display: inline-block;
  307. max-width: 190px;
  308. overflow: hidden;
  309. text-overflow: ellipsis;
  310. white-space: nowrap;
  311. float: right;
  312. }
  313. }
  314. .menu-item-first {
  315. background: #eee;
  316. padding: 0 12px;
  317. line-height: 30px;
  318. font-size: 12px;
  319. >span:nth-child(1) {
  320. cursor: default;
  321. font-weight: bold;
  322. }
  323. input {
  324. width: 174px;
  325. height: 24px;
  326. margin-left: 35px;
  327. background: #fff;
  328. border: 1px solid #5078cb;
  329. padding-left: 4px;
  330. }
  331. .search-enterprise {
  332. display: inline-block;
  333. width: 36px;
  334. height: 24px;
  335. color: #fff;
  336. background: #5078cb;
  337. text-align: center;
  338. line-height: 24px;
  339. cursor: pointer;
  340. }
  341. }
  342. .dropdown-menu {
  343. padding: 0 6px 13px;
  344. margin:0;
  345. border-radius: 0;
  346. right: unset;
  347. background: #fff;
  348. border: 1px solid #999999;
  349. border-top: none;
  350. -webkit-box-shadow: none;
  351. -moz-box-shadow: none;
  352. box-shadow: none;
  353. ::-webkit-scrollbar {
  354. background: #f6f6f6;
  355. }
  356. ul {
  357. max-height: 300px;
  358. overflow-y: auto;
  359. background: #f6f6f6;
  360. }
  361. .menu-item {
  362. padding: 0 12px;
  363. a {
  364. color: #333;
  365. max-width: 300px;
  366. line-height: 30px;
  367. width: auto;
  368. &:hover {
  369. color: #5078cb;
  370. text-decoration: none!important;
  371. }
  372. }
  373. }
  374. }
  375. &:hover {
  376. background-color: $white;
  377. .dropdown-toggle {
  378. color: $text;
  379. }
  380. a {
  381. color: $text
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. }
  389. </style>