MobileHeader.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="mobile-nav">
  3. <!-- <div class="mobile-modal" v-if="showStoreInfo || showShare" @click="cancelModal">
  4. <div class="mobile-modal-box" v-if="showStoreInfo" @click="stopPropagation($event)">
  5. <div class="mobile-modal-header">联系方式<i @click="showStoreInfo = false" class="icon-guanbi iconfont"></i></div>
  6. <div class="mobile-modal-content" v-if="showDefaultAddr">
  7. <div>商家地址:深圳市南山区英唐大厦6楼</div>
  8. <div class="content-line link-url">在线咨询</div>
  9. <div>致电:<a href="tel:0755-96586323" class="content-line link-url">0755-96586323</a></div>
  10. <div>邮件:<a href="mailto:yrsc@usoftchina.com" class="content-line link-url">yrsc@usoftchina.com</a></div>
  11. </div>
  12. <div class="mobile-modal-content" v-if="!showDefaultAddr">
  13. <div>商家地址:{{store.enterprise.enAddress || store.enterprise.address}}</div>
  14. <div class="content-line link-url">在线咨询</div>
  15. <div>致电:<a :href="'tel:'+store.enterprise.enTel" class="content-line link-url">{{store.enterprise.enTel}}</a></div>
  16. <div>邮件:<a :href="'mailto:'+store.enterprise.enEmail" class="content-line link-url">{{store.enterprise.enEmail}}</a></div>
  17. </div>
  18. </div>
  19. <div class="mobile-share-box" v-if="showShare" @click="stopPropagation($event)">
  20. <div class="share-area">
  21. <ul>
  22. <li class="share-item" @click="shareWeChat">
  23. <i class="icon-weixin iconfont" style="color: #07af12;"></i>
  24. <span>微信</span>
  25. </li>
  26. <li class="share-item" @click="shareQQ">
  27. <i class="icon-qq1 iconfont" style="color: #5872f4;"></i>
  28. <span>QQ</span>
  29. </li>
  30. <li class="share-item" @click="shareWeibo">
  31. <i class="icon-ff0000 iconfont" style="color: #ff0000;"></i>
  32. <span>微博</span>
  33. </li>
  34. <li class="share-item" @click="shareMessage">
  35. <i class="icon-msnui-msg-invert iconfont" style="color: #25cdb7"></i>
  36. <span>短信</span>
  37. <a href="sms:" class="hide" id="share-sms"></a>
  38. </li>
  39. <li class="share-item" @click="shareEmail">
  40. <i class="icon-youjian iconfont" style="height: .57rem;font-size: .41rem;color:#f18215;"></i>
  41. <span>邮件</span>
  42. <a href="mailto:" class="hide" id="share-mail"></a>
  43. </li>
  44. <li class="share-item" @click="flash">
  45. <i class="icon-shuaxin iconfont" style="color: #2584cd;"></i>
  46. <span>刷新</span>
  47. </li>
  48. <li class="share-item" @click="copyLink" id="copyLink" :data-clipboard-text="url">
  49. <i class="icon-lianjie iconfont" style="color: #73b0df;"></i>
  50. <span>复制链接</span>
  51. </li>
  52. </ul>
  53. </div>
  54. <div class="cancel-share" @click="showShare=false">取消</div>
  55. </div>
  56. </div>-->
  57. <div class="mobile-header" v-if="showHeader && !showMainSearch">
  58. <a @click="goLastPage"><i class="iconfont icon-fanhui"></i></a>
  59. <p>{{title}}
  60. <span @click="goMainSearch" v-if="showSearchIcon"><i class="icon-sousuo iconfont"></i>搜索</span>
  61. </p>
  62. </div>
  63. <main-search v-if="showMainSearch" @cancelSearchAction="onCancelSearch"></main-search>
  64. <!-- <i v-show="rightIcon=='share'" class="iconfont icon-fenxiang" @click="showShare = true" @touchmove="onTouchMove($event)"></i>
  65. <i v-show="rightIcon=='phone'" class="iconfont icon-dianhua" @click="showLink" @touchmove="onTouchMove($event)"></i>-->
  66. </div>
  67. </template>
  68. <script>
  69. // import Clipboard from 'clipboard'
  70. import MainSearch from '~/components/mobile/search/MainSearch.vue'
  71. export default {
  72. data () {
  73. return {
  74. // showStoreInfo: false,
  75. // showShare: false,
  76. // rightIcon: 'phone',
  77. // showDefaultAddr: true,
  78. // url: '',
  79. // clipboard: {},
  80. showMainSearch: false,
  81. title: '优软商城',
  82. showHeader: false,
  83. showSearchIcon: true
  84. // showSearch: false
  85. }
  86. },
  87. components: {
  88. MainSearch
  89. },
  90. watch: {
  91. $route: function (val, oldVal) {
  92. this.showMainSearch = false
  93. this.title = this.initHeader(val.path, val.query)
  94. }
  95. },
  96. created () {
  97. this.title = this.initHeader(this.$route.path, this.$route.query)
  98. },
  99. computed: {
  100. brandDetail () {
  101. return this.$store.state.brandDetail.detail.data
  102. },
  103. store () {
  104. return this.$store.state.shop.storeInfo.store.data
  105. },
  106. component () {
  107. return this.$store.state.componentDetail.detail.data
  108. }
  109. // showHeader () {
  110. // return this.$route.path !== '/' || !this.$route.path || this.$route.path === ''
  111. // },
  112. // showSearch () {
  113. // return this.$route.path !== '/' && !this.$route.path.startsWith('/mobile/search')
  114. // }
  115. },
  116. // mounted () {
  117. // let _this = this
  118. // _this.url = window.location.href
  119. // _this.clipboard = new Clipboard('#copyLink')
  120. // _this.clipboard.on('success', e => {
  121. // _this.clipboard.destroy()
  122. // _this.showShare = false
  123. // })
  124. // _this.clipboard.on('error', e => {
  125. // alert('浏览器不支持自动复制,请手动复制')
  126. // _this.clipboard.destroy()
  127. // })
  128. // },
  129. methods: {
  130. goLastPage: function () {
  131. window.history.back(-1)
  132. },
  133. initHeader: function (val, query) {
  134. // if (val !== '/' || !val || val === '') {
  135. // this.showHeader = true
  136. // this.showSearch = !val.startsWith('/mobile/search')
  137. // } else {
  138. // this.showHeader = false
  139. // this.showSearch = false
  140. // }
  141. this.showSearchIcon = false
  142. this.showHeader = val && val !== '/' && val !== '/mobile/applyPurchase/list' && !this.startWith(val, '/mobile/supplier')
  143. // this.showSearch = val !== '/' && !this.startWith(val, '/mobile/search')
  144. let title = '优软商城'
  145. if (this.startWith(val, '/mobile/brand/componentDetail/')) {
  146. title = this.component.code
  147. // this.rightIcon = 'share'
  148. } else if (this.startWith(val, '/mobile/brand/brandCenter')) {
  149. title = '品牌墙'
  150. // this.rightIcon = 'share'
  151. } else if (this.startWith(val, '/mobile/brand/')) {
  152. if (this.brandDetail.nameCn) {
  153. if (this.brandDetail.nameCn !== this.brandDetail.nameEn) {
  154. title = this.brandDetail.nameEn + '(' + this.brandDetail.nameCn + ')'
  155. } else {
  156. title = this.brandDetail.nameCn
  157. }
  158. } else {
  159. if (this.component.brand.nameCn !== this.component.brand.nameEn) {
  160. title = this.component.brand.nameEn + '(' + this.component.brand.nameCn + ')'
  161. } else {
  162. title = this.component.brand.nameCn
  163. }
  164. }
  165. // this.rightIcon = 'share'
  166. } else if (this.startWith(val, '/mobile/shop/')) {
  167. title = this.store.storeName
  168. // this.rightIcon = 'phone'
  169. } else if (this.startWith(val, '/mobile/shop')) {
  170. title = '店铺列表'
  171. // this.rightIcon = 'phone'
  172. } else if (this.startWith(val, '/mobile/center/vendor/product')) {
  173. if (this.$route.query.providerType === 'enterprise') {
  174. title = '企业产品库'
  175. } else if (this.$route.query.providerType === 'person') {
  176. title = '个人产品库'
  177. } else {
  178. title = '在售产品'
  179. }
  180. // this.rightIcon = 'phone'
  181. } else if (this.startWith(val, '/mobile/search')) {
  182. title = '搜索结果'
  183. // this.rightIcon = 'share'
  184. } else if (this.startWith(val, '/mobile/user/info/personal')) {
  185. this.showSearchIcon = false
  186. title = '个人信息'
  187. } else if (this.startWith(val, '/mobile/user/info/admin')) {
  188. this.showSearchIcon = false
  189. title = '管理员信息'
  190. } else {
  191. this.showSearchIcon = true
  192. title = '优软商城'
  193. // this.rightIcon = 'phone'
  194. }
  195. return title
  196. },
  197. // showLink: function () {
  198. // this.showStoreInfo = true
  199. // if (this.$route.path.startsWith('/mobile/shop/')) {
  200. // this.showDefaultAddr = false
  201. // } else {
  202. // this.showDefaultAddr = true
  203. // }
  204. // },
  205. // shareWeibo: function () {
  206. // let _shareUrl = 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136' // 真实的appkey,必选参数
  207. // _shareUrl += '&url=' + encodeURIComponent(document.location) // 参数url设置分享的内容链接|默认当前页location,可选参数
  208. // _shareUrl += '&title=' + encodeURIComponent(document.title) // 参数title设置分享的标题|默认当前页标题,可选参数
  209. // _shareUrl += '&source=' + encodeURIComponent('')
  210. // _shareUrl += '&sourceUrl=' + encodeURIComponent('')
  211. // _shareUrl += '&content=' + 'utf-8' // 参数content设置页面编码gb2312|utf-8,可选参数
  212. // _shareUrl += '&pic=' + encodeURIComponent('') // 参数pic设置图片链接|默认为空,可选参数
  213. // window.open(_shareUrl)
  214. // this.showShare = false
  215. // },
  216. // shareWeChat: function () {
  217. // },
  218. // shareQQ: function () {
  219. // let url = encodeURIComponent(document.location)
  220. // let title = encodeURIComponent(document.title)
  221. // let source = encodeURIComponent('')
  222. // let desc = '优软商城'
  223. // let pics = 'http://dfs.ubtob.com/group1/M00/4F/C3/CgpkyFnxWjOAMy5DAAlh1PrLlc8684.png'
  224. // window.open('http://connect.qq.com/widget/shareqq/index.html?url=' +
  225. // url + '&title=' + title + '&source=' + source + '&desc=' + desc + '&pics=' + pics)
  226. // this.showShare = false
  227. // },
  228. // shareMessage: function () {
  229. // document.getElementById('share-sms').click()
  230. // },
  231. // shareEmail: function () {
  232. // document.getElementById('share-mail').click()
  233. // },
  234. // flash: function () {
  235. // window.location.reload()
  236. // },
  237. // copyLink: function () {
  238. // let _this = this
  239. // _this.url = window.location.href
  240. // _this.clipboard = new Clipboard('#copyLink')
  241. // },
  242. // onTouchMove: function (e) {
  243. // let width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
  244. // let height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
  245. // let x = Math.min(width - 40, e.touches[0].clientX)
  246. // let y = Math.min(height - 40, e.touches[0].clientY)
  247. // x = Math.max(0, x)
  248. // y = Math.max(0, y)
  249. // e.preventDefault()
  250. // e.target.style.left = x * 2 / 100.0 + 'rem'
  251. // e.target.style.top = y * 2 / 100.0 + 'rem'
  252. // },
  253. onCancelSearch: function () {
  254. this.showMainSearch = false
  255. },
  256. // cancelModal: function () {
  257. // this.showStoreInfo = false
  258. // this.showShare = false
  259. // },
  260. stopPropagation: function (event) {
  261. event.stopPropagation()
  262. },
  263. goMainSearch: function () {
  264. this.showMainSearch = true
  265. this.$store.dispatch('searchData/getSearchHistory')
  266. },
  267. startWith: function (str, s) {
  268. let reg = new RegExp('^' + s)
  269. return reg.test(str)
  270. }
  271. }
  272. }
  273. </script>
  274. <style lang="scss" scoped>
  275. .mobile-header{
  276. position: fixed;
  277. top: 0;
  278. z-index: 10;
  279. width:100%;
  280. height:.88rem;
  281. line-height: .88rem;
  282. border-bottom:.01rem solid #ccc;
  283. background: #3e82f5;
  284. padding:0 .2rem 0 .1rem;
  285. color:#fff;
  286. }
  287. .mobile-header p{
  288. overflow: hidden;
  289. text-overflow: ellipsis;
  290. white-space: nowrap;
  291. font-size:.36rem;
  292. text-align: center;
  293. margin: 0;
  294. width: 6rem;
  295. padding-left: 1rem;
  296. }
  297. .mobile-header a{
  298. font-size:.28rem;
  299. color:#fff;
  300. position: absolute;
  301. }
  302. .mobile-header a i{
  303. font-size: .48rem;
  304. margin-right: -.1rem;
  305. }
  306. .mobile-header p span {
  307. position: absolute;
  308. right: .4rem;
  309. font-size: .28rem;
  310. }
  311. .mobile-header p span i {
  312. font-size: .28rem;
  313. }
  314. .mobile-nav >i{
  315. font-size: .4rem;
  316. position: fixed;
  317. right: .25rem;
  318. top: .25rem;
  319. z-index: 1000;
  320. color: #fff;
  321. background: rgba( 0, 0, 0, .251 );
  322. width: .8rem;
  323. height: .8rem;
  324. line-height: .8rem;
  325. border-radius: 100%;
  326. padding-left: .2rem;
  327. }
  328. .hide {
  329. display: none;
  330. }
  331. .search-content {
  332. margin-left: .5rem;
  333. input {
  334. color: #333;
  335. }
  336. }
  337. </style>