index.vue 8.9 KB

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