bd-detail.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="bd-detail">
  3. <view class="detail" v-if="newDetail">
  4. <!-- <image src="/static/image/icon/goods-detail.png"></image> -->
  5. <view class="detail-title">
  6. <view class="detail-text" :class="{'active':tab==1}" @click="tab=1">图文详情</view>
  7. <view class="detail-text" v-if="showTab" :class="{'active':tab==2}" @click="tab=2">详细参数</view>
  8. <view class="detail-text" v-if="showTab&&after_detail!=''" :class="{'active':tab==3}" @click="tab=3">售后保障</view>
  9. </view>
  10. <app-rich-text v-if="tab==1"
  11. :content="newDetail"
  12. ></app-rich-text>
  13. <view class="contrast" v-if="tab==2">
  14. <view class="list" v-for="(item,index) of contrastList.list" :key="index" v-if="contrastList.list">
  15. <view class="contrast_title" v-if="item.length>0">{{item[0].title}}</view>
  16. <view class="contrast_item" v-for="(value,key) of item" :key="key">
  17. <view class="contrast_key" :class="'contrast_key'+(ind+1)" v-for="(ite,ind) of value.text" :key="ind">
  18. {{ite||'-'}}
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <app-rich-text v-if="tab==3&&after_detail!=''"
  24. :content="newAfterDetail"
  25. ></app-rich-text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import appRichText from "../../basic-component/app-rich/parse";
  31. export default {
  32. name: "bd-detail",
  33. components: {
  34. 'app-rich-text': appRichText,
  35. },
  36. data(){
  37. return{
  38. tab:1,
  39. contrastList:null,
  40. showAfterDetail:true
  41. }
  42. },
  43. props: {
  44. goodsId:{
  45. default:null
  46. },
  47. showTab: {
  48. type: Boolean,
  49. default() {
  50. return true;
  51. }
  52. },
  53. detail: {
  54. type: String,
  55. default() {
  56. return '';
  57. }
  58. },
  59. after_detail: {
  60. type: String,
  61. default() {
  62. return '';
  63. }
  64. }
  65. },
  66. watch:{
  67. goodsId:{
  68. handler(newName, oldName) {
  69. this.$request({
  70. url: this.$api.poster.goods_contrast,
  71. data: {
  72. goods_id: this.goodsId
  73. }
  74. }).then(response => {
  75. if(response.code == 0){
  76. this.formatData(response.data)
  77. }
  78. })
  79. },
  80. immediate: true
  81. }
  82. },
  83. created() {
  84. this.$store.dispatch('gConfig/setImageWidth', 48);
  85. },
  86. methods:{
  87. getParams(){
  88. this.$request({
  89. url: this.$api.poster.goods_contrast,
  90. data: {
  91. goods_id: params
  92. }
  93. }).then(response => {
  94. if(response.code == 0){
  95. this.formatData(response.data)
  96. }
  97. })
  98. },
  99. formatData(data){
  100. let _this = this
  101. let list = []
  102. let info = []
  103. console.log(data)
  104. //商品信息
  105. data.forEach((items,indexs)=>{
  106. let obj = {}
  107. obj.guarantee_pic = items.goods.guarantee_pic
  108. obj.id = items.goods.id
  109. obj.name = items.goods.name
  110. obj.price = items.goods.price
  111. info.push(obj)
  112. })
  113. console.log(288)
  114. console.log(info)
  115. //参数信息
  116. data.forEach((items,indexs)=>{
  117. if(indexs==0){
  118. data[indexs].params.forEach((item,index)=>{
  119. let line = []
  120. data[indexs].params[index].params.forEach((ite,inde)=>{
  121. let text = []
  122. let title = ''
  123. text.push(data[indexs].params[index].params[inde].name)
  124. text.push(data[indexs].params[index].params[inde].value)
  125. data.forEach((it,i)=>{
  126. if(i!=0){
  127. text.push(data[i].params[index].params[inde].value)
  128. }
  129. })
  130. title = data[indexs].params[index].name
  131. line.push({
  132. title:title,
  133. text:text
  134. })
  135. })
  136. list.push(line)
  137. })
  138. }
  139. })
  140. this.contrastList = {}
  141. this.contrastList.list = list
  142. this.contrastList.info = info
  143. console.log(128)
  144. console.log(this.contrastList)
  145. },
  146. },
  147. computed: {
  148. newDetail() {
  149. let detail = '正在加载数据,模拟网络延迟2秒😝';
  150. if (this.detail) {
  151. detail = this.detail;
  152. }
  153. return detail;
  154. },
  155. newAfterDetail() {
  156. let after_detail = '正在加载数据,模拟网络延迟2秒😝';
  157. if (this.after_detail) {
  158. after_detail = this.after_detail;
  159. }
  160. return after_detail;
  161. },
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .bd-detail {
  167. width: 702upx;
  168. padding: 20upx 0;
  169. background-color: #ffffff;
  170. border-radius: 15upx;
  171. margin: 24upx 24upx 0 24upx;
  172. image {
  173. width: 100%;
  174. height: #{80rpx};
  175. display: block;
  176. }
  177. .detail-title{
  178. display:flex;
  179. padding-bottom:8px;
  180. .detail-text{
  181. justify-content: space-between;
  182. width:50%;
  183. text-align: center;
  184. line-height:31px;
  185. display: block;
  186. text-align: center;
  187. font-size:14px;
  188. }
  189. .active{
  190. color:rgb(242,28,28);
  191. }
  192. }
  193. }
  194. .list{
  195. background:#fff;border:0.5px solid #f7f7f7;
  196. .contrast_title {
  197. line-height:38px;height:40px;box-sizing:border-box;text-align:center;padding:0 8px;font-weight:600;
  198. font-size:12px;color:#2d2d32;border:0.5px solid #f7f7f7;
  199. }
  200. .contrast_item {
  201. display:flex;
  202. .contrast_key{
  203. font-size:12px;
  204. width:80px;
  205. height:auto;
  206. box-sizing:border-box;
  207. text-align:center;
  208. padding:10px 8px;
  209. line-height:20px;
  210. min-height:40px;
  211. border:0.5px solid #f7f7f7;
  212. display:flex;
  213. text-align:center;
  214. align-items: center;
  215. overflow:hidden;
  216. flex-wrap: wrap;
  217. .pic{
  218. width:100%;height:100px;
  219. text-align:center;
  220. float:left;
  221. image{
  222. width:100px;
  223. height:100px;
  224. }
  225. }
  226. .name{
  227. margin-top:10px;
  228. width:100%;
  229. float:left;
  230. font-size:12px;
  231. line-height: 14px;
  232. max-height: 28px;
  233. height:28px;
  234. overflow: hidden;
  235. }
  236. .price{
  237. width:100%;
  238. float:left;
  239. color:#f21c1c;
  240. font-size:12px;
  241. }
  242. .buy{
  243. display: block;
  244. width: 90px;
  245. height: 30px;
  246. text-align: center;
  247. line-height: 30px;
  248. border-radius: 3px;
  249. margin: 5px auto 8px;
  250. color:#fff;
  251. background:#f21c1c;
  252. }
  253. .cancel{
  254. width:100%;
  255. float:left;
  256. color: #3caaff;
  257. }
  258. .unable{
  259. color:#aaa;
  260. }
  261. }
  262. .contrast_key2,.contrast_key3,.contrast_key4,.contrast_key5{justify-content: space-around;width:calc(100% - 80px);text-align:center;}
  263. }
  264. }
  265. </style>