bd-detail.vue 5.9 KB

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