index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="content">
  3. <lucency-header :lang="lang" page-key="product" :is-phone="isPhone" />
  4. <item-banner :title="productTypeText" :sub-title="productTypeSubText"></item-banner>
  5. <big-title>{{productDetail.name}}</big-title>
  6. <div class="conBox product-view">
  7. <div class="left">
  8. <div class="imgView">
  9. <img v-show="productDetail.image" :src="`/public/${productDetail.image}`" alt=""/>
  10. </div>
  11. <div class="concatUs">
  12. <!-- 联系销售 -->
  13. <span class="chunk">联系购买</span>
  14. <div class="imgView">
  15. <img src="/image/wechat.jpg" alt="">
  16. </div>
  17. </div>
  18. </div>
  19. <div class="right">
  20. <div class="remark">
  21. {{productDetail.remark}}
  22. </div>
  23. <div class="detail" v-html="productDetail.detail">
  24. </div>
  25. </div>
  26. </div>
  27. <!-- 更多数据页面 -->
  28. <div class="conBox product-detail">
  29. <q-tab></q-tab>
  30. </div>
  31. <!-- 页脚 -->
  32. <default-footer :lang="lang"/>
  33. <site-bar wechat-src="/image/wechat.jpg"></site-bar>
  34. </div>
  35. </template>
  36. <script>
  37. import axios from "axios";
  38. import langMap from "~/map/langMap";
  39. import { getTypeText,getTypeSubText, pTypes} from "~/map/productMap";
  40. import {handle} from "~/until/handle";
  41. import {unescape} from "~/until/unescapeHtml";
  42. import qTab from "../../../components/qTab";
  43. import DefaultFooter from "../../../components/footer/defaultFooter";
  44. import LucencyHeader from "../../../components/header/lucencyHeader";
  45. import ItemBanner from "../../../components/banner/itemBanner";
  46. import {isMediaView} from "@/until/mediaView";
  47. import {apiMap, baseUrl} from "~/map/apiMap";
  48. import BigTitle from "~/components/public/bigTitle.vue";
  49. import {toNumber,isEmpty} from "../../../until/typeTool";
  50. export default {
  51. name: "itemIndex",
  52. components: {BigTitle, ItemBanner, LucencyHeader, DefaultFooter, qTab},
  53. props:['uLang','pType', 'pInfo'],
  54. async asyncData(ctx){
  55. // 判断是否有id,如果有id则请求数据,否则则不请求数据
  56. let err,res;
  57. let id = ctx.query.id;
  58. // id转数字
  59. let url = baseUrl + apiMap.productInfo.path ;
  60. if(!toNumber(id)){
  61. return ctx.redirect(`/product`);
  62. }
  63. console.log(`开始获取产品 id:${id}`);
  64. url += `/${id}`;
  65. [err,res] = await handle(axios.get(url));
  66. if(err){
  67. // 加载失败,返回至产品页面
  68. console.log(`查询产品数据失败`);
  69. ctx.redirect(`/product`);
  70. return {}
  71. }
  72. let result = res.data;
  73. if(result.code === 1){
  74. // console.log(result.data);
  75. return {
  76. productDetail:result.data,
  77. type: result.data.type_key,
  78. }
  79. }else{
  80. console.log(`查询产品数据失败,服务器异常`);
  81. ctx.redirect(`/product`);
  82. }
  83. return {}
  84. },
  85. data(){
  86. return {
  87. langType: langMap.lang,
  88. lang: this.uLang?this.uLang:langMap.lang.cn,
  89. productId: null,
  90. types: pTypes,
  91. type: '',
  92. productTypeText: getTypeText(this.pType),
  93. productTypeSubText: getTypeSubText(this.pType),
  94. productDetail: {},
  95. isPhone: false,
  96. }
  97. },
  98. beforeMount() {
  99. console.log(this.pInfo);
  100. if(isEmpty(this.productDetail) && isEmpty(this.pInfo)){
  101. console.log('没有数据');
  102. return this.$router.push('/product');
  103. }
  104. if(isEmpty(this.productDetail)){
  105. this.productDetail = this.pInfo;
  106. }
  107. this.productDetail.detail = unescape(this.productDetail.detail);
  108. },
  109. mounted() {
  110. // console.log(this.pType);
  111. // console.log(this.type);
  112. this.isPhone = isMediaView(0,1024);
  113. if(!isEmpty(this.type)){
  114. this.type = this.pType;
  115. }
  116. },
  117. methods:{
  118. getLangText(str) {
  119. return langMap.getText(this.lang, str);
  120. },
  121. getAbbrText(str) {
  122. return langMap.getAbbrText(this.lang, str);
  123. },
  124. async loadProductDetail(){
  125. let err,res;
  126. let url = apiMap.productInfo.path;
  127. url += `/${this.productId}`
  128. [err,res] = await handle(this.$axios.get(url));
  129. if(err){
  130. console.error(err);
  131. return alert(err.message);
  132. }
  133. let result = res.data;
  134. if(result.code === 1){
  135. this.productDetail = result.data;
  136. console.log(this.productDetail.detail)
  137. this.productDetail.detail = unescape(this.productDetail.detail);
  138. console.log(this.productDetail.detail)
  139. }else{
  140. console.log('not match result');
  141. console.log(result);
  142. return alert('加载产品失败!!!');
  143. }
  144. },
  145. }
  146. }
  147. </script>
  148. <style scoped>
  149. .big-title {
  150. margin: 5px auto;
  151. justify-content: left;
  152. }
  153. .product-view{
  154. height: auto;
  155. min-height: 680px;
  156. /*width: 100%;*/
  157. border-top: 1px solid #dedede;
  158. display: flex;
  159. }
  160. .product-view .left{
  161. width: 320px;
  162. height: auto;
  163. }
  164. .product-view .left .imgView{
  165. width: 300px;
  166. height: 300px;
  167. margin: 10px;
  168. position: relative;
  169. }
  170. .product-view .left .imgView img{
  171. display: block;
  172. width: 100%;
  173. height: 100%;
  174. }
  175. .product-view .right{
  176. width: calc(100% - 320px);
  177. height: auto;
  178. }
  179. .product-view .right .remark{
  180. padding: 10px 5px;
  181. border-left: 1px solid #b6b6b6;
  182. margin-top: 5px;
  183. box-sizing: border-box;
  184. }
  185. .product-view .left .concatUs{
  186. width: 100%;
  187. height: auto;
  188. border-top: 1px solid gray;
  189. }
  190. .product-view .left .concatUs .chunk{
  191. width: 90%;
  192. margin: 5px auto;
  193. display: flex;
  194. padding: 5px 15px;
  195. justify-content: center;
  196. font-size: 1.4rem;
  197. border-radius: 3px;
  198. box-shadow: 0 0 5px gainsboro;
  199. cursor: pointer;
  200. }
  201. .product-view .left .concatUs .chunk:hover{
  202. background-color: skyblue;
  203. color: white;
  204. }
  205. .product-detail{
  206. margin-top: 20px;
  207. border-top: 1px solid gainsboro;
  208. }
  209. .tab-header{
  210. display: flex;
  211. }
  212. .tab-header .header-title{
  213. }
  214. </style>