detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <view class="detail">
  3. <view class="part1">
  4. <!-- 轮播图 -->
  5. <view class="uni-margin-wrap">
  6. <swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay"
  7. :interval="interval" :duration="duration">
  8. <swiper-item v-for="(item,index) in bannerList" :key="index">
  9. <image :src="item" mode="" class="pictures"></image>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <van-divider />
  14. <!-- 商品描述信息 -->
  15. <view class="main">
  16. <view class="left">
  17. <view class="title">
  18. {{prodList.prodName}}
  19. </view>
  20. <view class="discribe">
  21. {{prodList.brief}}
  22. </view>
  23. <view class="price">
  24. ¥<text>{{prodList.price}}</text>
  25. </view>
  26. </view>
  27. <view class="right">
  28. <van-icon name="like-o" v-if="isCollect" size="24" @click="addCollect" />
  29. <van-icon name="like" v-if="!isCollect" size="24" @click="addCollect" />
  30. <text>收藏</text>
  31. </view>
  32. </view>
  33. </view>
  34. <van-divider hairline customStyle="border:12px solid #eee;" />
  35. <!-- 已选 -->
  36. <view class="choose" @click="showDialog">
  37. <view class="left">
  38. 已选<text>{{defaultStr.skuName}}</text>
  39. </view>
  40. <view class="right">
  41. ...
  42. </view>
  43. </view>
  44. <van-divider hairline customStyle="border:12px solid #eee;" />
  45. <!-- 好评部分 -->
  46. <van-cell is-link value="共0条">
  47. <template #title>
  48. <view class="van-cell-text">评价:好评{{evaluate.positiveRating}}%</view>
  49. </template>
  50. </van-cell>
  51. <view class="evaluate">
  52. <van-tag type="warning">全部:{{evaluate.number}}</van-tag>
  53. <van-tag type="warning">好评:{{evaluate.praiseNumber}}</van-tag>
  54. <van-tag type="warning">中评:{{evaluate.secondaryNumber}}</van-tag>
  55. <van-tag type="warning">差评:{{evaluate.negativeNumber}}</van-tag>
  56. <van-tag type="warning">有图:{{evaluate.picNumber}}</van-tag>
  57. </view>
  58. <!-- 内容页 -->
  59. <view v-html="formatHtml(prodList.content)"></view>
  60. <!-- 商品导航 -->
  61. <van-goods-action>
  62. <van-goods-action-icon icon="cart-o" text="购物车" @click="goToShop" />
  63. <van-goods-action-icon icon="shop-o" text="店铺" />
  64. <van-goods-action-button text="立即购买" @click="onClickButton" />
  65. </van-goods-action>
  66. <!-- 型号选择 -->
  67. <van-action-sheet @click-overlay="submitBtn" @close="submitBtn" :show="show" title="选择产品类别">
  68. <view class="choise" v-if="tagList[0].label != ''">
  69. <view class="box" v-for="(item,index) in tagList" :key="index">
  70. <view class="tit">
  71. {{item.label}}
  72. </view>
  73. <view class="main">
  74. <text class="size" v-for="(item1,index1) in item.option" :key="index1"
  75. :class="{selected:selectTag[item.label] === item1 ? true : false}"
  76. @click="selectTag1(item.label,item1)">
  77. {{item1}}
  78. </text>
  79. </view>
  80. </view>
  81. </view>
  82. <van-button :disabled="defaultStr.skuName ? false : true" type="danger" @click="submitBtn" square class="btn">确定</van-button>
  83. </van-action-sheet>
  84. <!-- 立即购买 -->
  85. <van-action-sheet @click-overlay="cancelShow" :show="isshow">
  86. <view class="cardMain">
  87. <van-card :num="confirm.orderItem.prodCount" :price="defaultStr.price ? defaultStr.price : prodList.price" :desc="prodList.brief"
  88. :title="defaultStr.skuName ? defaultStr.skuName : prodList.prodName"
  89. :thumb="defaultStr.pic? defaultStr.pic : prodList.pic">
  90. <template slot="footer">
  91. <van-stepper :value="confirm.orderItem.prodCount" @change="onChange" />
  92. </template>
  93. </van-card>
  94. </view>
  95. <view class="choise news" v-if="tagList[0].label != ''">
  96. <view class="box" v-for="(item,index) in tagList" :key="index">
  97. <view class="tit">
  98. {{item.label}}
  99. </view>
  100. <view class="newsMain">
  101. <text class="size" v-for="(item1,index1) in item.option" :key="index1"
  102. :class="{selected:selectTag[item.label] === item1 ? true : false}"
  103. @click="selectTag1(item.label,item1)">
  104. {{item1}}
  105. </text>
  106. </view>
  107. </view>
  108. </view>
  109. <view class="footerBtn">
  110. <view class="btn1" @click="addShop">加入购物车</view>
  111. <view class="btn2">立即购买</view>
  112. </view>
  113. </van-action-sheet>
  114. </view>
  115. </template>
  116. <script>
  117. import {
  118. prodInfo,
  119. prodCommData,
  120. confirmWay,
  121. changeItem
  122. } from '@/api/detail.js'
  123. import {
  124. formatHtml
  125. } from "@/utils/util.js";
  126. export default {
  127. data() {
  128. return {
  129. ids: "",
  130. indicatorDots: true,
  131. autoplay: true,
  132. interval: 2000,
  133. duration: 500,
  134. prodList: [], //商品信息数组
  135. bannerList: [], //轮播数组
  136. isCollect: true, //控制收藏显示
  137. defalutList: [], //默认展示内容的数组
  138. evaluate: [], //好评部分
  139. show: false, //控制型号选择显示隐藏
  140. typeList: [], //存储型号列表
  141. tagList: [], //渲染型号列表
  142. selectTag: {}, //选中的值
  143. defaultStr: {}, //存放已选字段
  144. isshow: false, //购买弹框
  145. // 商品结单字段
  146. confirm: {
  147. basketIds: [
  148. 0
  149. ],
  150. orderItem: {
  151. prodId: 0,
  152. skuId: 0,
  153. prodCount: 1,
  154. shopId: 0,
  155. distributionCardNo: ""
  156. },
  157. addrId: 0,
  158. userChangeCoupon: 0,
  159. couponIds: [
  160. 0
  161. ]
  162. },
  163. // 购物车字段
  164. shopList:{
  165. basketId: 0,
  166. prodId: 0,
  167. skuId: 0,
  168. shopId: 0,
  169. count: 0,
  170. distributionCardNo: ""
  171. }
  172. }
  173. },
  174. onLoad(options) {
  175. this.ids = options.id;
  176. // 获得详情页的商品信息
  177. this.init();
  178. },
  179. methods: {
  180. init() {
  181. // 商品信息
  182. prodInfo({
  183. prodId: this.ids
  184. }).then(res => {
  185. this.prodList = res.data;
  186. this.bannerList = this.prodList.imgs.split(',');
  187. this.defalutList = res.data.skuList;
  188. var popObject = {};
  189. var defaultArr = [];
  190. for (var i = 0; i < this.defalutList.length; i++) {
  191. this.defaultStr = this.defalutList[0];
  192. this.typeList.push(this.defalutList[i].properties)
  193. }
  194. for (var i = 0; i < this.typeList.length; i++) {
  195. var popStr = this.typeList[i].split(";");
  196. if (defaultArr.length == 0) {
  197. defaultArr = popStr;
  198. }
  199. for (var j = 0; j < popStr.length; j++) {
  200. var valueArr = popStr[j];
  201. var valueStr = valueArr.split(":");
  202. if (!popObject[valueStr[0]]) {
  203. popObject[valueStr[0]] = new Set()
  204. }
  205. popObject[valueStr[0]].add(valueStr[1])
  206. this.tagList = Object.entries(popObject).map(([key, value]) => {
  207. return {
  208. label: key,
  209. option: Array.from(value).map(item => {
  210. return item
  211. })
  212. }
  213. });
  214. console.log(this.tagList,'标签')
  215. for (let x = defaultArr.length - 1; x >= 0; x--) {
  216. let newStr = defaultArr[x];
  217. let newArr = newStr.split(":");
  218. this.$set(this.selectTag, newArr[0], newArr[1])
  219. }
  220. }
  221. }
  222. }).catch(err => {
  223. console.log(err, '失败')
  224. })
  225. // 好评信息
  226. prodCommData({
  227. prodId: this.ids
  228. }).then(res => {
  229. this.evaluate = res.data;
  230. }).catch(err => {
  231. console.log(err, '失败')
  232. })
  233. },
  234. // 控制收藏显示
  235. addCollect() {
  236. this.isCollect = !this.isCollect;
  237. },
  238. formatHtml(t) {
  239. return formatHtml(t)
  240. },
  241. // 展示型号弹框
  242. showDialog() {
  243. this.show = true;
  244. },
  245. // 选中事件
  246. selectTag1(popTitle, popValue) {
  247. this.$set(this.selectTag, popTitle, popValue)
  248. let str = "";
  249. for (let item in this.selectTag) {
  250. str = item + ":" + this.selectTag[item] + ";" + str;
  251. }
  252. let str1 = str.substring(0, str.length - 1)
  253. for (var i = 0; i < this.defalutList.length; i++) {
  254. if (this.defalutList[i].properties === str1) {
  255. this.defaultStr = this.defalutList[i];
  256. return;
  257. }
  258. }
  259. },
  260. //确定
  261. submitBtn() {
  262. console.log("执行")
  263. this.show = false;
  264. },
  265. // 取消立即购买弹框
  266. cancelShow() {
  267. this.isshow = false;
  268. },
  269. // 立即购买
  270. onClickButton() {
  271. console.log(this.defalutList,'defalutList')
  272. console.log(this.defaultStr,'defaultStr')
  273. console.log(this.typeList,'typeList')
  274. console.log(this.tagList,'tagList')
  275. console.log(this.prodList,'prodList')
  276. this.isshow = true;
  277. },
  278. // 修改商品中弹框数量
  279. onChange(event) {
  280. this.confirm.orderItem.prodCount = event.detail;
  281. },
  282. // 去购物车
  283. goToShop() {
  284. uni.switchTab({
  285. url:"/pages/shop/shop"
  286. })
  287. },
  288. // 加入购物车
  289. addShop() {
  290. this.shopList.basketId = 0;
  291. this.shopList.prodId = this.prodList.prodId;
  292. this.shopList.skuId = this.defaultStr.skuId;
  293. this.shopList.shopId = this.prodList.shopId;
  294. this.shopList.count = this.confirm.orderItem.prodCount;
  295. console.log(this.shopList,'传参')
  296. changeItem(this.shopList).then(res => {
  297. console.log(res,'成功')
  298. uni.showToast({
  299. title:"添加成功",
  300. icon:"success",
  301. duration:2000
  302. })
  303. this.isshow = false;
  304. }).catch(err => {
  305. console.log(err,'失败')
  306. })
  307. }
  308. }
  309. }
  310. </script>
  311. <style scoped lang='scss'>
  312. .uni-margin-wrap {
  313. width: 690rpx;
  314. width: 100%;
  315. }
  316. .swiper {
  317. height: 700rpx;
  318. }
  319. .swiper-item {
  320. display: block;
  321. height: 700rpx;
  322. line-height: 700rpx;
  323. text-align: center;
  324. }
  325. .pictures {
  326. width: 100%;
  327. height: 700rpx;
  328. }
  329. .main {
  330. width: 96%;
  331. height: 200rpx;
  332. display: flex;
  333. margin: 0 auto;
  334. justify-content: space-between;
  335. .left {
  336. .title {
  337. font-size: 38rpx;
  338. font-weight: bold;
  339. }
  340. .discribe {
  341. font-size: 27rpx;
  342. margin-top: 10rpx;
  343. }
  344. .price {
  345. font-size: 24rpx;
  346. margin-top: 10rpx;
  347. color: red;
  348. text {
  349. font-size: 38rpx;
  350. font-weight: bold;
  351. }
  352. }
  353. }
  354. .right {
  355. display: flex;
  356. align-items: center;
  357. width: 120rpx;
  358. justify-content: space-around;
  359. text {
  360. font-size: 38rpx;
  361. }
  362. }
  363. }
  364. .choose {
  365. width: 100%;
  366. height: 100rpx;
  367. display: flex;
  368. justify-content: space-between;
  369. align-items: center;
  370. .left {
  371. margin-left: 15rpx;
  372. text {
  373. font-size: 38rpx;
  374. font-weight: bold;
  375. }
  376. }
  377. .right {
  378. margin-right: 15rpx;
  379. }
  380. }
  381. .evaluate {
  382. width: 100%;
  383. height: 100rpx;
  384. display: flex;
  385. justify-content: space-around;
  386. align-items: center;
  387. }
  388. ::v-deep .van-tag {
  389. color: red;
  390. height: 60rpx;
  391. }
  392. .choise {
  393. height: 550rpx;
  394. .box {
  395. width: 92%;
  396. margin: 0 auto;
  397. .tit {
  398. font-size: 40rpx;
  399. }
  400. .main {
  401. display: flex;
  402. justify-content: space-around;
  403. align-items: center;
  404. height: 172rpx;
  405. .size {
  406. padding: 19rpx;
  407. color: #f00;
  408. border: 1px solid #f00;
  409. height: 30rpx;
  410. text-align: center;
  411. line-height: 30rpx;
  412. }
  413. }
  414. }
  415. }
  416. .btn {
  417. ::v-deep .van-button--normal {
  418. width: 100%;
  419. height: 100rpx;
  420. }
  421. }
  422. .selected {
  423. color: #fff !important;
  424. background: #f00 !important;
  425. }
  426. .news {
  427. height: 320rpx;
  428. }
  429. .footerBtn {
  430. width: 90%;
  431. height: 80rpx;
  432. display: flex;
  433. margin: 30rpx auto;
  434. text-align: center;
  435. line-height: 80rpx;
  436. .btn1 {
  437. flex: 1;
  438. height: 100%;
  439. color: #fff;
  440. background: #595959;
  441. }
  442. .btn2 {
  443. flex: 1;
  444. height: 100%;
  445. color: #fff;
  446. background: #ff0000;
  447. }
  448. }
  449. .newsMain {
  450. display: flex;
  451. justify-content: space-around;
  452. align-items: center;
  453. height: 100rpx;
  454. .size {
  455. padding: 19rpx;
  456. color: #f00;
  457. border: 1px solid #f00;
  458. height: 30rpx;
  459. text-align: center;
  460. line-height: 30rpx;
  461. }
  462. }
  463. </style>