detail.vue 11 KB

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