Header.vue 12 KB

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