userInfo.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <div class="userInfo_top-box">
  3. <div class="go_landing">
  4. <div class="center_landing">
  5. <div class="center_landingl">
  6. <p class="center_text">
  7. <span class="telnum">{{ $t("homePage.CallName") }}</span
  8. >{{ $t("taps.Telnum") }} <br /><router-link
  9. class="contact"
  10. to="/contact"
  11. >{{ $t("homePage.us") }}</router-link
  12. >
  13. </p>
  14. <el-row class="block-col-2">
  15. <el-col>
  16. <el-select v-model="locale" placeholder="" @change="changeLocale">
  17. <el-option
  18. v-for="item in list"
  19. :key="item.value"
  20. :label="item.name"
  21. :value="item.value"
  22. >
  23. </el-option>
  24. </el-select>
  25. </el-col>
  26. </el-row>
  27. </div>
  28. <div class="center_landingr">
  29. <el-row class="block-col-2" v-if="tokenShow">
  30. <el-col>
  31. <el-dropdown trigger="click">
  32. <span class="el-dropdown-link">
  33. {{ info.name || info.nickname
  34. }}<i class="el-icon-arrow-down el-icon--right"></i>
  35. </span>
  36. <el-dropdown-menu slot="dropdown">
  37. <el-dropdown-item
  38. @click.native="$router.push({ name: 'address' })"
  39. >{{ $t("checkout.Addre") }}</el-dropdown-item
  40. >
  41. <el-dropdown-item
  42. @click.native="$router.push({ name: 'orderList' })"
  43. >{{ $t("checkout.Order") }}</el-dropdown-item
  44. >
  45. <el-dropdown-item @click.native="signOut">{{
  46. $t("checkout.Sign")
  47. }}</el-dropdown-item>
  48. </el-dropdown-menu>
  49. </el-dropdown>
  50. </el-col>
  51. </el-row>
  52. <div class="login_b" v-if="!tokenShow">
  53. <el-button
  54. class="buttom"
  55. type="primary"
  56. icon="el-icon-user-solid"
  57. @click="$router.push({ name: 'login' })"
  58. >{{ $t("landing.registration") }}</el-button
  59. >
  60. </div>
  61. <div
  62. class="goshopping_box"
  63. @click="$router.push({ name: 'mycart' })"
  64. @mouseenter="mouseenterMycar"
  65. >
  66. <p class="center_text mycart_t">
  67. <!-- <i class="el-icon-shopping-cart-2"></i> -->
  68. <img
  69. src="@/assets/img/gouwugouwuchedinggou.png"
  70. class="images-mycar"
  71. />
  72. {{ $t("homePage.basket") }}
  73. <span class="goshopping_text" v-if="num > 0">({{ num }})</span>
  74. </p>
  75. <div
  76. class="taps_cart"
  77. :class="mycartShow ? 'mycart_aps' : ''"
  78. @mouseleave="mouseleaveMycar"
  79. >
  80. <dissMycart
  81. v-show="mycartShow"
  82. :list="listCart"
  83. :count="cartTotal"
  84. ref="dissMycart"
  85. ></dissMycart>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. import Bus from "@/js/bus";
  95. import dissMycart from "./diss-mycart";
  96. var that = this;
  97. export default {
  98. name: "userInfo",
  99. components: {
  100. dissMycart
  101. },
  102. data() {
  103. return {
  104. listCart: [],
  105. cartTotal: 0,
  106. mycartShow: localStorage.getItem("cartTap") === "1",
  107. info: "",
  108. // locale: this.$util.localeStorage() ? 'English': 'Chinese',
  109. locale: this.$util.localeStorage()
  110. ? this.$t("homePage.English")
  111. : this.$t("homePage.Chinese"),
  112. tokenShow: !!localStorage.getItem("token"),
  113. list: [
  114. {
  115. id: 1,
  116. value: "en",
  117. // name: 'English'
  118. name: this.$t("homePage.English")
  119. },
  120. {
  121. id: 2,
  122. value: "cn",
  123. // name: 'Chinese'
  124. name: this.$t("homePage.Chinese")
  125. }
  126. ],
  127. num: JSON.parse(localStorage.getItem("shoppingNum")) // 购物车数量
  128. };
  129. },
  130. // watch: {
  131. // '$store.state.tapscart' (newVal, oldVal) {
  132. // // console.log(newVal, '==========', oldVal)
  133. // if (oldVal > 0) {
  134. // console.log(newVal, '==========', oldVal)
  135. // // that.mycartShow = true
  136. // // this.getList()
  137. // this.mouseenterMycar()
  138. // } else {
  139. // that.mycartShow = false
  140. // }
  141. // }
  142. // },
  143. created() {
  144. this.info = JSON.parse(localStorage.getItem("info"));
  145. this.getList();
  146. },
  147. mounted() {
  148. let _this = this;
  149. Bus.$on("onmycar", val => {
  150. // this.mouseenterMycar()
  151. // console.log(val, '3333333333')
  152. if (val == 1) {
  153. // console.log(val, '88888')
  154. this.showList = false;
  155. this.mouseenterMycar();
  156. // console.log(val, '444444')
  157. } else {
  158. _this.mouseleaveMycar();
  159. }
  160. });
  161. window.addEventListener("setItemEvent", function(e) {
  162. // let key = e.key
  163. // console.log(key, '======')
  164. if (e.key === "shoppingNum") {
  165. _this.num = e.newValue;
  166. }
  167. // if (e.key === 'cartTap') {
  168. // let cartTap = localStorage.getItem('cartTap')
  169. // if (cartTap) {
  170. // _this.mouseenterMycar()
  171. // } else {
  172. // _this.mouseleaveMycar()
  173. // }
  174. // }
  175. });
  176. },
  177. methods: {
  178. changeLocale(e) {
  179. sessionStorage.removeItem("tdk");
  180. localStorage.removeItem("token");
  181. if (e == "en") {
  182. window.location.href = "https://crs.sanyoubio.com";
  183. } else {
  184. window.location.href = "https://crs.sanyoubio.com.cn";
  185. }
  186. },
  187. signOut() {
  188. let data = JSON.parse(localStorage.getItem("shoppingCart"));
  189. if (data) {
  190. localStorage.setItem("shoppingNum", JSON.stringify(data.length));
  191. } else {
  192. localStorage.setItem("shoppingNum", JSON.stringify(0));
  193. }
  194. localStorage.removeItem("user");
  195. localStorage.removeItem("token");
  196. localStorage.removeItem("info");
  197. this.$router.push({
  198. name: "login"
  199. });
  200. },
  201. mouseenterMycar() {
  202. this.mycartShow = true;
  203. this.getList();
  204. },
  205. mouseleaveMycar() {
  206. this.mycartShow = false;
  207. },
  208. getList() {
  209. let that = this;
  210. let data = JSON.parse(localStorage.getItem("shoppingCart"));
  211. let arry = [];
  212. if (JSON.parse(localStorage.getItem("token"))) {
  213. if (data && data.length > 0) {
  214. data.forEach(item => {
  215. var obj = {
  216. checked: true,
  217. id: item.id,
  218. number: item.number,
  219. productCatalog: item.productCatalog,
  220. skuId: item.skuId
  221. };
  222. arry.push(obj);
  223. });
  224. } else {
  225. arry = null;
  226. }
  227. this.$api
  228. .post("cart/index", {
  229. cartList: arry
  230. })
  231. .then(res => {
  232. if (res.code == 0) {
  233. this.listCart = res.data.cartList;
  234. that.cartTotal = res.data.cartTotal.checkedGoodsDiscount;
  235. } else {
  236. // this.$message(res.msg)
  237. }
  238. });
  239. } else {
  240. if (data && data.length > 0) {
  241. that.listCart = [];
  242. that.cartTotal = 0;
  243. data.forEach(item => {
  244. that.listCart.push(item);
  245. if (this.$util.localeStorage()) {
  246. that.cartTotal += item.number * item.discountPrice;
  247. } else {
  248. that.cartTotal += item.number * item.cnDiscountPrice;
  249. }
  250. });
  251. }
  252. }
  253. }
  254. }
  255. };
  256. </script>
  257. <style lang="scss" scoped>
  258. @media screen and (min-width: 751px) and (max-width: 9999px) {
  259. .userInfo_top-box {
  260. .go_landing {
  261. // background-color: #273949;
  262. .center_landing {
  263. margin: 0 auto;
  264. display: flex;
  265. justify-content: space-between;
  266. // align-items: center;
  267. align-content: center;
  268. .center_landingl {
  269. text-align: center;
  270. font-weight: 500;
  271. .block-col-2 /deep/ {
  272. cursor: pointer;
  273. .el-col {
  274. .el-select {
  275. width: 100px;
  276. height: 30px;
  277. .el-input__inner {
  278. border: none;
  279. height: 26px;
  280. line-height: 26px;
  281. font-size: 12px;
  282. // background-color: rgba(0, 0, 0, 0);
  283. }
  284. .el-input__suffix {
  285. .el-input__suffix-inner {
  286. display: block;
  287. height: 100%;
  288. .el-input__icon {
  289. line-height: 26px;
  290. }
  291. }
  292. }
  293. }
  294. }
  295. .el-dropdown {
  296. height: 50px;
  297. line-height: 50px;
  298. width: 100px;
  299. display: block;
  300. }
  301. .el-dropdown-link {
  302. color: #fff;
  303. margin-left: 20px;
  304. }
  305. .el-icon-arrow-down {
  306. margin-left: 10px;
  307. // color: red;
  308. }
  309. .el-dropdown:hover {
  310. background: #005bab;
  311. // color: red;
  312. }
  313. }
  314. .center_text {
  315. color: #005bab;
  316. cursor: pointer;
  317. font-weight: 600;
  318. font-size: 12px;
  319. .telnum {
  320. color: #000;
  321. margin-right: 4px;
  322. font-weight: 500;
  323. }
  324. .contact {
  325. color: #005bab;
  326. }
  327. }
  328. }
  329. .center_landingr {
  330. margin-left: 20px;
  331. .block-col-2 /deep/ {
  332. cursor: pointer;
  333. .el-dropdown {
  334. height: 28px;
  335. line-height: 28px;
  336. width: 100px;
  337. display: block;
  338. text-align: right;
  339. }
  340. .el-dropdown-link {
  341. color: #000;
  342. margin-left: 20px;
  343. font-size: 12px;
  344. }
  345. .el-icon-arrow-down {
  346. margin-left: 6px;
  347. }
  348. .el-dropdown:hover {
  349. background: #fff;
  350. }
  351. }
  352. .center_text {
  353. color: #fff;
  354. cursor: pointer;
  355. }
  356. .login_b {
  357. display: block;
  358. color: #000;
  359. .buttom /deep/ {
  360. background-color: rgba(0, 0, 0, 0);
  361. border: none;
  362. color: #000 !important;
  363. padding: 6px 8px !important;
  364. font-size: 12px;
  365. .el-icon-user-solid {
  366. color: #005bab !important;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. .goshopping_box {
  375. position: relative;
  376. .goshopping_text {
  377. font-size: 14px;
  378. }
  379. .taps_cart {
  380. display: none;
  381. position: absolute;
  382. top: 35px;
  383. z-index: 1000;
  384. // left: 50%;
  385. right: 0;
  386. // transform: translateX(-50%);
  387. }
  388. .mycart_aps {
  389. display: block !important;
  390. }
  391. }
  392. .cardpmd {
  393. display: none;
  394. }
  395. .landingpmd_imgf {
  396. display: none;
  397. }
  398. .center_text {
  399. color: #fff;
  400. a {
  401. color: #fff;
  402. cursor: pointer;
  403. text-decoration: none;
  404. }
  405. a:hover {
  406. color: #005bab;
  407. cursor: pointer;
  408. text-decoration: none;
  409. }
  410. }
  411. .mycart_t /deep/ {
  412. display: flex;
  413. align-items: center;
  414. color: #000 !important;
  415. justify-content: right;
  416. padding-right: 8px;
  417. font-weight: 500;
  418. font-size: 12px;
  419. .images-mycar {
  420. width: 30px;
  421. margin-right: 6px;
  422. }
  423. .el-icon-shopping-cart-2 {
  424. // color: #005BAB;
  425. color: red;
  426. font-weight: 600;
  427. font-size: 30px;
  428. margin-right: 6px;
  429. }
  430. .goshopping_text {
  431. margin-left: 6px;
  432. color: #005bab;
  433. }
  434. }
  435. }
  436. // @media screen and (min-width: 751px) and (max-width: 1600px) {
  437. // .taps_cart{
  438. // display: none;
  439. // position: absolute;
  440. // top: 30px;
  441. // z-index: 99;
  442. // left: -50% !important;
  443. // // transform: translateX(-50%);
  444. // }
  445. // }
  446. </style>