index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 wechat-src="/image/wechat.jpg"></site-bar>
  15. <pop :show="buyShow" :loading="buyLoading"
  16. >
  17. <div class="product-show">
  18. <div class="absolute top-0 right-0 p-2 text-red-500 text-xl">
  19. <a-icon type="close" @click="cancelBuy"/>
  20. </div>
  21. </div>
  22. </pop>
  23. </div>
  24. </template>
  25. <script>
  26. // import 'ant-design-vue/dist/antd.css'
  27. import axios from "axios";
  28. import langMap from "~/map/langMap";
  29. import { getTypeText,getTypeSubText, pTypes} from "~/map/productMap";
  30. import {handle} from "~/until/handle";
  31. import {unescape} from "~/until/unescapeHtml";
  32. import qTab from "../../../components/qTab";
  33. import DefaultFooter from "../../../components/footer/defaultFooter";
  34. import LucencyHeader from "../../../components/header/lucencyHeader";
  35. import ItemBanner from "../../../components/banner/itemBanner";
  36. import {isMediaView} from "@/until/mediaView";
  37. import {apiMap, baseUrl} from "~/map/apiMap";
  38. import BigTitle from "~/components/public/bigTitle.vue";
  39. import {toNumber,isEmpty} from "../../../until/typeTool";
  40. import Pop from "@/components/public/pop.vue";
  41. export default {
  42. name: "itemIndex",
  43. components: {Pop, BigTitle, ItemBanner, LucencyHeader, DefaultFooter, qTab},
  44. props:['uLang','pType', 'pInfo'],
  45. head() {
  46. let headInfo = {
  47. meta: []
  48. }
  49. if (this.title)
  50. {
  51. headInfo.title = this.title;
  52. }
  53. if (this.desc)
  54. {
  55. headInfo.meta.push({
  56. hid: "description",
  57. name: "description",
  58. content: this.desc,
  59. })
  60. }
  61. if(this.seo_key)
  62. {
  63. headInfo.meta.push({
  64. hid: "keywords",
  65. name: "keywords",
  66. content: this.seo_key,
  67. })
  68. }
  69. return headInfo
  70. },
  71. async asyncData(ctx){
  72. console.log(`asyncData `);
  73. // 判断是否有id,如果有id则请求数据,否则则不请求数据
  74. let err,res;
  75. let id = ctx.query.id;
  76. // id转数字
  77. let url = baseUrl + apiMap.productInfo.path ;
  78. if(!toNumber(id)){
  79. return ctx.redirect(`/product`);
  80. }
  81. console.log(`开始获取产品 id:${id}`);
  82. url += `/${id}`;
  83. [err,res] = await handle(axios.get(url));
  84. if(err){
  85. // 加载失败,返回至产品页面
  86. console.log(`查询产品数据失败`);
  87. ctx.redirect(`/product`);
  88. return {}
  89. }
  90. let result = res.data;
  91. if(result.code === 1){
  92. console.log('产品详情');
  93. console.log(result.data);
  94. let desc = result.data.remark
  95. let enDesc = ctx.lang !== langMap.lang.cn ? result.data.remark_en || result.data.remark : result.data.remark
  96. let seoKey = result.data.seo_key
  97. return {
  98. desc: desc,
  99. enDesc: enDesc,
  100. seo_key: seoKey? seoKey : `合方圆-产品中心,合方圆科技-产品中心`,
  101. title: `合方圆-${result.data.name}`,
  102. productDetail:result.data
  103. }
  104. }else{
  105. console.log(`查询产品数据失败,服务器异常`);
  106. ctx.redirect(`/product`);
  107. }
  108. return {}
  109. },
  110. data(){
  111. return {
  112. title: ``,
  113. desc: '',
  114. enDesc: '',
  115. seo_key: '',
  116. langType: langMap.lang,
  117. lang: this.uLang?this.uLang:langMap.lang.cn,
  118. productId: null,
  119. types: this.$store.getters.pTypes,
  120. productDetail: {},
  121. isPhone: false,
  122. buyShow: false,
  123. buyLoading: false,
  124. }
  125. },
  126. computed: {
  127. type(){
  128. let info = isEmpty(this.productDetail)?this.pInfo:this.productDetail
  129. let types = this.$store.getters.pTypes || this.types;
  130. let type = types.find(val => val.type_key === info.type_key);
  131. let resultType = {}
  132. if(this.lang !== langMap.lang.cn)
  133. {
  134. resultType.type_name = type.type_name_en;
  135. resultType.sub_text = type.sub_text_en;
  136. }
  137. if(!resultType.type_name) resultType.type_name = type.type_name;
  138. if(!resultType.sub_text) resultType.sub_text = type.sub_text;
  139. resultType.type_key = type.type_key;
  140. return resultType;
  141. }
  142. },
  143. beforeMount() {
  144. console.log(this.pInfo);
  145. if(isEmpty(this.productDetail) && isEmpty(this.pInfo)){
  146. console.log('没有数据');
  147. return this.$router.push('/product');
  148. }
  149. if(isEmpty(this.productDetail)){
  150. this.productDetail = this.pInfo;
  151. }
  152. },
  153. mounted() {
  154. // console.log(this.pType);
  155. // console.log(this.type);
  156. // this.$root.$on('tryBuy',this.tryBuy);
  157. this.isPhone = isMediaView(0,1024);
  158. },
  159. methods:{
  160. getLangText(str) {
  161. return langMap.getText(this.lang, str);
  162. },
  163. getAbbrText(str) {
  164. return langMap.getAbbrText(this.lang, str);
  165. },
  166. async loadProductDetail(){
  167. let err,res;
  168. let url = apiMap.productInfo.path;
  169. url += `/${this.productId}`
  170. [err,res] = await handle(this.$axios.get(url));
  171. if(err){
  172. console.error(err);
  173. return alert(err.message);
  174. }
  175. let result = res.data;
  176. if(result.code === 1){
  177. this.productDetail = result.data;
  178. console.log(this.productDetail.detail)
  179. this.productDetail.detail = unescape(this.productDetail.detail);
  180. console.log(this.productDetail.detail)
  181. }else{
  182. console.log('not match result');
  183. console.log(result);
  184. return alert('加载产品失败!!!');
  185. }
  186. },
  187. tryBuy(){
  188. console.log('tryBuy');
  189. this.buyShow = true;
  190. },
  191. cancelBuy(){
  192. this.buyShow = false;
  193. },
  194. }
  195. }
  196. </script>
  197. <style scoped>
  198. .big-title {
  199. margin: 5px auto;
  200. justify-content: left;
  201. }
  202. .product-view{
  203. height: auto;
  204. min-height: 680px;
  205. /*width: 100%;*/
  206. border-top: 1px solid #dedede;
  207. display: flex;
  208. }
  209. .product-view .left{
  210. width: 320px;
  211. height: auto;
  212. }
  213. .product-view .left .imgView{
  214. width: 300px;
  215. height: 300px;
  216. margin: 10px;
  217. position: relative;
  218. }
  219. .product-view .left .imgView img{
  220. display: block;
  221. width: 100%;
  222. height: 100%;
  223. }
  224. .product-view .right{
  225. width: calc(100% - 320px);
  226. height: auto;
  227. }
  228. .product-view .right .remark{
  229. padding: 10px 5px;
  230. border-left: 1px solid #b6b6b6;
  231. margin-top: 5px;
  232. box-sizing: border-box;
  233. }
  234. .product-view .left .concatUs{
  235. width: 100%;
  236. height: auto;
  237. border-top: 1px solid gray;
  238. }
  239. .product-view .left .concatUs .chunk{
  240. width: 90%;
  241. margin: 5px auto;
  242. display: flex;
  243. padding: 5px 15px;
  244. justify-content: center;
  245. font-size: 1.4rem;
  246. border-radius: 3px;
  247. box-shadow: 0 0 5px gainsboro;
  248. cursor: pointer;
  249. }
  250. .product-view .left .concatUs .chunk:hover{
  251. background-color: skyblue;
  252. color: white;
  253. }
  254. .product-detail{
  255. margin-top: 20px;
  256. border-top: 1px solid gainsboro;
  257. }
  258. .tab-header{
  259. display: flex;
  260. }
  261. .tab-header .header-title{
  262. }
  263. .product-show{
  264. width: 80%;
  265. height: calc(100% - 50px);
  266. overflow: auto;
  267. background-color: #fff;
  268. border-radius: 10px;
  269. position: relative;
  270. }
  271. </style>