Header.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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.usoftchina.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. <a class="item" href="/sso#/index">帐户中心</a>
  57. <a class="item" href="/user#/messagePersonal">消息 ({{count}})</a>
  58. </template>
  59. <template v-else>
  60. <a class="item" @click="onLoginClick()">登录</a>
  61. <a class="item" @click="onRegisterClick">注册</a>
  62. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  63. </template>
  64. <nuxt-link class="item" to="/help/home" target="_blank">帮助中心</nuxt-link>
  65. <!--<a class="item" href="/help#/home">帮助中心</a>-->
  66. </div>
  67. </div>
  68. </nav>
  69. </header>
  70. </template>
  71. <script>
  72. export default {
  73. name: 'headerView',
  74. data () {
  75. return {
  76. // showEnterprises: false
  77. // searchEnterpriseArr: [],
  78. // keyword: '',
  79. // isSearching: false
  80. // ShowApplyAdv: true,
  81. showEnterpriseToggle: false,
  82. messageUrl: process.env.messageUrl,
  83. count: 0
  84. }
  85. },
  86. computed: {
  87. // isShowApplyAdv () {
  88. // if (this.$route.path.indexOf('/applyPurchase') === -1) {
  89. // this.ShowApplyAdv = true
  90. // }
  91. // return this.ShowApplyAdv && this.$route.path.indexOf('/applyPurchase') !== -1
  92. // },
  93. user () {
  94. // console.log(this.$store.state.option.user)
  95. return this.$store.state.option.user
  96. },
  97. enterprise () {
  98. return this.user.data.enterprise || {}
  99. },
  100. url () {
  101. return this.$store.state.option.url
  102. }
  103. },
  104. mounted () {
  105. if(this.user.logged && this.user.data) {
  106. let userUU = this.user.data.userUU
  107. let enUU = this.user.data.enterprise ? this.user.data.enterprise.uu : null
  108. if(userUU && enUU) {
  109. let param = {
  110. 'receiverUu': userUU,
  111. 'receiverEnuu': enUU,
  112. 'consumerApp': 'MALL',
  113. 'isRead': 0
  114. }
  115. this.$http.get(`/messages/count`, {params: param})
  116. .then((res) => {
  117. if(res.data) {
  118. this.count = res.data.count ? (res.data.count < 100 ? res.data.count : '99+') : 0
  119. } else {
  120. this.count = 0
  121. }
  122. }).catch((err) => {
  123. console.log(err)
  124. })
  125. }
  126. }
  127. },
  128. methods: {
  129. logout () {
  130. this.$http.get('/logout/crossBefore').then(response => {
  131. if (response.data) {
  132. window.location.href = response.data.logoutUrl + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  133. }
  134. })
  135. },
  136. onLoginClick () {
  137. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  138. if (response.data) {
  139. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  140. }
  141. })
  142. // TODO 待Account Center改版
  143. },
  144. onRegisterClick () {
  145. this.$http.get('/register/page').then(response => {
  146. if (response.data) {
  147. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + '/newLogin/other')
  148. }
  149. })
  150. },
  151. // 切换当前企业
  152. switchEnterprise (en) {
  153. this.showEnterpriseToggle = false
  154. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  155. this.$store.dispatch('loadUserInfo')
  156. // let path = this.$route.path
  157. // if (path === '/register-saler' && en.uu !== 0 && en.isVendor === 313) {
  158. // window.location.href = '/vendor#/index'
  159. // } else {
  160. // window.location.reload()
  161. // }
  162. window.location.href = '/'
  163. })
  164. // 切换帐套用
  165. this.$jsonp(`${process.env.ssoUrl}/sso/login/change/userspace?spaceUU=${en.uu}`, {timeout: 5000, name: 'successCallback'}, (err) => {
  166. console.log(err)
  167. })
  168. },
  169. toVendor: function () {
  170. let isSelf = true
  171. let tempEnterprise = {}
  172. let ens = this.user.data.enterprises
  173. if (ens && ens.length) {
  174. ens.forEach(function (item) {
  175. if (item.current) {
  176. isSelf = false
  177. tempEnterprise = item
  178. }
  179. })
  180. } else {
  181. isSelf = true
  182. }
  183. if (isSelf) {
  184. window.location.href = '/personalMaterial'
  185. } else {
  186. if (tempEnterprise.isVendor === 313) {
  187. // window.location.href = '/vendor'
  188. window.location.href = '/vendor#/index'
  189. } else {
  190. window.location.href = '/register-saler'
  191. }
  192. }
  193. }
  194. // searchEnterprise () {
  195. // let key = this.keyword
  196. // let enterprise = this.user.data.enterprises
  197. // this.isSearching = true
  198. // this.searchEnterpriseArr = []
  199. // if (this.keyword === '') {
  200. // this.isSearching = false
  201. // } else {
  202. // for (let i = 0; i < enterprise.length; i++) {
  203. // if (enterprise[i].enName.indexOf(key) !== -1) {
  204. // this.searchEnterpriseArr.push(enterprise[i])
  205. // }
  206. // }
  207. // }
  208. // }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .header .navbar{
  214. min-height: inherit;
  215. border-radius: 0;
  216. }
  217. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  218. font-size: 12px;
  219. }
  220. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  221. width: 100%;
  222. display: inline-block;
  223. overflow: hidden;
  224. text-overflow: ellipsis;
  225. white-space: nowrap;
  226. height: 25px;
  227. }
  228. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  229. height: 30px;
  230. }
  231. .apply-adv{
  232. margin: 0 auto;
  233. min-width: 1190px;
  234. position: relative;
  235. img{
  236. max-width: 100%;
  237. min-width: 1190px;
  238. }
  239. i {
  240. background: url("/images/search/search-close.png")no-repeat;
  241. width: 16px;
  242. height: 16px;
  243. position: absolute;
  244. right: 8px;
  245. top: 8px;
  246. cursor: pointer;
  247. z-index: 20000;
  248. }
  249. }
  250. .dropdown-menu>li>a{
  251. padding: 0;
  252. line-height: 30px;
  253. }
  254. .dropdown-menu>li a:hover{
  255. background: none;
  256. text-decoration: underline !important;
  257. }
  258. .dropdown-menu>li>a.pull-right{
  259. padding: 0;
  260. color: #1162a4 !important;
  261. line-height: inherit;
  262. }
  263. .member-text{
  264. width: 80%;
  265. white-space: nowrap;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. display: inline-block;
  269. }
  270. @import '~assets/scss/mixins';
  271. @import '~assets/scss/variables';
  272. $nav-height: 38px;
  273. .header {
  274. /* height: $nav-height;*/
  275. .navbar {
  276. width: 100%;
  277. height: 100%;
  278. font-size: $font-size-small;
  279. background-color: $black-light;
  280. .navbar-container {
  281. .item-wrap {
  282. display: inline-block;
  283. }
  284. .item {
  285. color: $grey;
  286. display: inline-block;
  287. height: 35px;
  288. line-height: 35px;
  289. }
  290. a {
  291. color: $grey;
  292. }
  293. .navbar-header {
  294. float: left;
  295. .navbar-logo {
  296. margin-bottom: 2px;
  297. }
  298. .navbar-slogan {
  299. margin-left: $sm-pad;
  300. }
  301. }
  302. .navbar-right {
  303. float: right;
  304. .item {
  305. padding: 0 $pad;
  306. }
  307. .dropdown {
  308. .dropdown-toggle {
  309. line-height: $nav-height;
  310. border-left: 1px solid $black-light;
  311. border-right: 1px solid $black-light;
  312. height: 35px;
  313. a {
  314. margin-left: 15px;
  315. float: right;
  316. &:hover {
  317. color: $red !important;
  318. }
  319. }
  320. &:hover {
  321. border-left: 1px solid #999;
  322. border-right: 1px solid #999;
  323. }
  324. span {
  325. display: inline-block;
  326. max-width: 190px;
  327. overflow: hidden;
  328. text-overflow: ellipsis;
  329. white-space: nowrap;
  330. float: right;
  331. }
  332. }
  333. .menu-item-first {
  334. background: #eee;
  335. padding: 0 12px;
  336. line-height: 30px;
  337. font-size: 12px;
  338. >span:nth-child(1) {
  339. cursor: default;
  340. font-weight: bold;
  341. }
  342. input {
  343. width: 174px;
  344. height: 24px;
  345. margin-left: 35px;
  346. background: #fff;
  347. border: 1px solid #5078cb;
  348. padding-left: 4px;
  349. }
  350. .search-enterprise {
  351. display: inline-block;
  352. width: 36px;
  353. height: 24px;
  354. color: #fff;
  355. background: #5078cb;
  356. text-align: center;
  357. line-height: 24px;
  358. cursor: pointer;
  359. }
  360. }
  361. .dropdown-menu {
  362. padding: 0 6px 13px;
  363. margin:0;
  364. border-radius: 0;
  365. right: unset;
  366. background: #fff;
  367. border: 1px solid #999999;
  368. border-top: none;
  369. -webkit-box-shadow: none;
  370. -moz-box-shadow: none;
  371. box-shadow: none;
  372. ::-webkit-scrollbar {
  373. background: #f6f6f6;
  374. }
  375. ul {
  376. max-height: 300px;
  377. overflow-y: auto;
  378. background: #f6f6f6;
  379. }
  380. .menu-item {
  381. padding: 0 12px;
  382. a {
  383. color: #333;
  384. max-width: 300px;
  385. line-height: 30px;
  386. width: auto;
  387. &:hover {
  388. color: #5078cb;
  389. text-decoration: none!important;
  390. }
  391. }
  392. }
  393. }
  394. &:hover {
  395. background-color: $white;
  396. .dropdown-toggle {
  397. color: $text;
  398. }
  399. a {
  400. color: $text
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408. </style>