index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="content">
  3. <lucency-header :lang="lang" page-key="product" :is-phone="isPhone" />
  4. <item-banner :title="type.type_name" :sub-title="type.sub_text"></item-banner>
  5. <big-title>
  6. <a :href="`/product/${type.type_key}`">{{type.type_name}}</a>-
  7. {{productDetail.name}}
  8. </big-title>
  9. <div class="container product-view mx-auto ">
  10. <product-info :product="productDetail" :lang="lang" :unescape="true" @tryBuy="tryBuy"/>
  11. </div>
  12. <!-- 页脚 -->
  13. <default-footer :lang="lang"/>
  14. <site-bar></site-bar>
  15. <pop :show="buyShow" :loading="buyLoading"
  16. >
  17. <div class="product-buy">
  18. <div class="product-buy-con">
  19. <big-title>
  20. <span>{{productDetail.name}}</span>
  21. </big-title>
  22. <div class="buy-fn" v-if="productDetail.shop_addr||platform.shop_addr">
  23. <div class="fn-name">网店购买</div>
  24. <div class="fn-show">
  25. <a target="_blank"
  26. rel="noopener noreferrer"
  27. :href="productDetail.shop_addr?productDetail.shop_addr:platform.shop_addr"
  28. >打开网店</a>
  29. </div>
  30. </div>
  31. <div class="buy-fn">
  32. <div class="fn-name">联系销售</div>
  33. <div class="fn-show">
  34. <img class=" wx-qrc z-50" :src="imagePathBabel(platform.wx_qrc)" alt="销售微信">
  35. </div>
  36. </div>
  37. </div>
  38. <div class="close-btn" @click="cancelBuy">
  39. <svg-icon icon-class="close" />
  40. </div>
  41. </div>
  42. </pop>
  43. </div>
  44. </template>
  45. <script>
  46. // import 'ant-design-vue/dist/antd.css'
  47. import axios from "axios";
  48. import langMap from "~/map/langMap";
  49. import { getTypeText,getTypeSubText, pTypes} from "~/map/productMap";
  50. import {handle} from "~/until/handle";
  51. import {unescape} from "~/until/unescapeHtml";
  52. import qTab from "../../../components/qTab";
  53. import DefaultFooter from "../../../components/footer/defaultFooter";
  54. import LucencyHeader from "../../../components/header/lucencyHeader";
  55. import ItemBanner from "../../../components/banner/itemBanner";
  56. import {isMediaView} from "@/until/mediaView";
  57. import {apiMap, baseUrl} from "~/map/apiMap";
  58. import BigTitle from "~/components/public/bigTitle.vue";
  59. import {toNumber,isEmpty} from "../../../until/typeTool";
  60. import Pop from "@/components/public/pop.vue";
  61. import ImageViewer from "@/components/public/imageViewer.vue";
  62. import {imagePathBabel} from "@/tools/imagePath";
  63. export default {
  64. name: "itemIndex",
  65. components: {ImageViewer, Pop, BigTitle, ItemBanner, LucencyHeader, DefaultFooter, qTab},
  66. props:['uLang','pType', 'pInfo'],
  67. head() {
  68. let headInfo = {
  69. meta: []
  70. }
  71. if (this.title)
  72. {
  73. headInfo.title = this.title;
  74. }
  75. if (this.desc)
  76. {
  77. headInfo.meta.push({
  78. hid: "description",
  79. name: "description",
  80. content: this.desc,
  81. })
  82. }
  83. if(this.seo_key)
  84. {
  85. headInfo.meta.push({
  86. hid: "keywords",
  87. name: "keywords",
  88. content: this.seo_key,
  89. })
  90. }
  91. return headInfo
  92. },
  93. async asyncData(ctx){
  94. console.log(`asyncData `);
  95. // 判断是否有id,如果有id则请求数据,否则则不请求数据
  96. let err,res;
  97. let id = ctx.query.id;
  98. // id转数字
  99. let url = baseUrl + apiMap.productInfo.path ;
  100. if(!toNumber(id)){
  101. return ctx.redirect(`/product`);
  102. }
  103. console.log(`开始获取产品 id:${id}`);
  104. url += `/${id}`;
  105. [err,res] = await handle(axios.get(url));
  106. if(err){
  107. // 加载失败,返回至产品页面
  108. console.log(`查询产品数据失败`);
  109. ctx.redirect(`/product`);
  110. return {}
  111. }
  112. let result = res.data;
  113. if(result.code === 1){
  114. console.log('产品详情');
  115. console.log(result.data);
  116. let desc = result.data.remark
  117. let enDesc = ctx.lang !== langMap.lang.cn ? result.data.remark_en || result.data.remark : result.data.remark
  118. let seoKey = result.data.seo_key
  119. return {
  120. desc: desc,
  121. enDesc: enDesc,
  122. seo_key: seoKey? seoKey : `合方圆-产品中心,合方圆科技-产品中心`,
  123. title: `合方圆-${result.data.name}`,
  124. productDetail:result.data
  125. }
  126. }else{
  127. console.log(`查询产品数据失败,服务器异常`);
  128. ctx.redirect(`/product`);
  129. }
  130. return {}
  131. },
  132. data(){
  133. return {
  134. title: ``,
  135. desc: '',
  136. enDesc: '',
  137. seo_key: '',
  138. langType: langMap.lang,
  139. lang: this.uLang?this.uLang:langMap.lang.cn,
  140. productId: null,
  141. types: this.$store.getters.pTypes,
  142. productDetail: {},
  143. isPhone: false,
  144. buyShow: false,
  145. buyLoading: false,
  146. }
  147. },
  148. computed: {
  149. type(){
  150. let info = isEmpty(this.productDetail)?this.pInfo:this.productDetail
  151. let types = this.$store.getters.pTypes || this.types;
  152. let type = types.find(val => val.type_key === info.type_key);
  153. let resultType = {}
  154. if(this.lang !== langMap.lang.cn)
  155. {
  156. resultType.type_name = type.type_name_en;
  157. resultType.sub_text = type.sub_text_en;
  158. }
  159. if(!resultType.type_name) resultType.type_name = type.type_name;
  160. if(!resultType.sub_text) resultType.sub_text = type.sub_text;
  161. resultType.type_key = type.type_key;
  162. return resultType;
  163. },
  164. platform(){
  165. let info = this.$store.getters.platform;
  166. return info
  167. }
  168. },
  169. beforeMount() {
  170. console.log(this.pInfo);
  171. if(isEmpty(this.productDetail) && isEmpty(this.pInfo)){
  172. console.log('没有数据');
  173. return this.$router.push('/product');
  174. }
  175. if(isEmpty(this.productDetail)){
  176. this.productDetail = this.pInfo;
  177. }
  178. },
  179. mounted() {
  180. // console.log(this.pType);
  181. // console.log(this.type);
  182. // this.$root.$on('tryBuy',this.tryBuy);
  183. this.isPhone = isMediaView(0,1024);
  184. },
  185. methods:{
  186. imagePathBabel,
  187. getLangText(str) {
  188. return langMap.getText(this.lang, str);
  189. },
  190. getAbbrText(str) {
  191. return langMap.getAbbrText(this.lang, str);
  192. },
  193. async loadProductDetail(){
  194. let err,res;
  195. let url = apiMap.productInfo.path;
  196. url += `/${this.productId}`
  197. [err,res] = await handle(this.$axios.get(url));
  198. if(err){
  199. console.error(err);
  200. return alert(err.message);
  201. }
  202. let result = res.data;
  203. if(result.code === 1){
  204. this.productDetail = result.data;
  205. console.log(this.productDetail.detail)
  206. this.productDetail.detail = unescape(this.productDetail.detail);
  207. console.log(this.productDetail.detail)
  208. }else{
  209. console.log('not match result');
  210. console.log(result);
  211. return alert('加载产品失败!!!');
  212. }
  213. },
  214. tryBuy(){
  215. console.log('tryBuy');
  216. this.buyShow = true;
  217. },
  218. cancelBuy(){
  219. this.buyShow = false;
  220. },
  221. }
  222. }
  223. </script>
  224. <style scoped>
  225. .big-title {
  226. margin: 5px auto;
  227. justify-content: left;
  228. }
  229. .product-view{
  230. height: auto;
  231. min-height: 680px;
  232. /*width: 100%;*/
  233. border-top: 1px solid #dedede;
  234. display: flex;
  235. }
  236. .product-view .left{
  237. width: 320px;
  238. height: auto;
  239. }
  240. .product-view .left .imgView{
  241. width: 300px;
  242. height: 300px;
  243. margin: 10px;
  244. position: relative;
  245. }
  246. .product-view .left .imgView img{
  247. display: block;
  248. width: 100%;
  249. height: 100%;
  250. }
  251. .product-view .right{
  252. width: calc(100% - 320px);
  253. height: auto;
  254. }
  255. .product-view .right .remark{
  256. padding: 10px 5px;
  257. border-left: 1px solid #b6b6b6;
  258. margin-top: 5px;
  259. box-sizing: border-box;
  260. }
  261. .product-view .left .concatUs{
  262. width: 100%;
  263. height: auto;
  264. border-top: 1px solid gray;
  265. }
  266. .product-view .left .concatUs .chunk{
  267. width: 90%;
  268. margin: 5px auto;
  269. display: flex;
  270. padding: 5px 15px;
  271. justify-content: center;
  272. font-size: 1.4rem;
  273. border-radius: 3px;
  274. box-shadow: 0 0 5px gainsboro;
  275. cursor: pointer;
  276. }
  277. .product-view .left .concatUs .chunk:hover{
  278. background-color: skyblue;
  279. color: white;
  280. }
  281. .product-detail{
  282. margin-top: 20px;
  283. border-top: 1px solid gainsboro;
  284. }
  285. .tab-header{
  286. display: flex;
  287. }
  288. .tab-header .header-title{
  289. }
  290. .product-buy{
  291. width: 70%;
  292. max-width: 1200px;
  293. height: calc(100% - 260px);
  294. overflow: auto;
  295. background-color: #fff;
  296. border-radius: 10px;
  297. position: relative;
  298. padding: 10px;
  299. }
  300. .close-btn{
  301. position: absolute;
  302. top: 10px;
  303. right: 10px;
  304. cursor: pointer;
  305. color: #fff;
  306. font-size: 1.6rem;
  307. transition: all 0.3s;
  308. background-color: orangered;
  309. border-radius: 50%;
  310. box-shadow: 0 0 5px gainsboro;
  311. width: 30px;
  312. height: 30px;
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. }
  317. .product-buy-con{
  318. width: 100%;
  319. height: 100%;
  320. position: relative;
  321. overflow: hidden;
  322. }
  323. .buy-fn{
  324. width: 100%;
  325. height: auto;
  326. display: flex;
  327. align-items: center;
  328. margin-top: 10px;
  329. }
  330. .buy-fn:nth-child(1){
  331. margin-top: 0;
  332. }
  333. .buy-fn .fn-name{
  334. width: 120px;
  335. height: 40px;
  336. line-height: 40px;
  337. text-align: center;
  338. }
  339. .buy-fn .fn-show{
  340. width: calc(100% - 130px);
  341. height: auto;
  342. max-height: 260px;
  343. overflow: auto;
  344. box-sizing: border-box;
  345. padding: 5px;
  346. border-left: 1px solid gainsboro;
  347. margin-left: 10px;
  348. }
  349. .wx-qrc{
  350. width: 220px;
  351. height: 220px;
  352. }
  353. </style>