detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <view class="detail">
  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 bannerList" :key="index">
  8. <image class="pictures" :src="item.pic" mode=""></image>
  9. </swiper-item>
  10. </swiper>
  11. </view>
  12. <van-viewider />
  13. <!-- 商品信息12 -->
  14. <view class="message">
  15. <van-row>
  16. <van-col span="18" class="name">
  17. {{prodList.prodName}}
  18. </van-col>
  19. <van-col span="6">
  20. <view @click="addOrCancel">
  21. <van-icon name="like-o" v-if="!isCollection" size="20" />
  22. <van-icon name="like" v-if="isCollection" size="20" />
  23. <text class="collect">收藏</text>
  24. </view>
  25. </van-col>
  26. </van-row>
  27. <van-row>
  28. <van-col span="20" class="tip">
  29. {{prodList.brief}}
  30. </van-col>
  31. <van-col span="4">
  32. </van-col>
  33. </van-row>
  34. <van-row>
  35. <van-col span="20" class="price">
  36. ¥<text> {{prodList.price}}</text>
  37. </van-col>
  38. <van-col span="4">
  39. </van-col>
  40. </van-row>
  41. </view>
  42. <van-viewider customStyle="font-width: 3rpx;" />
  43. <!-- 类别 -->
  44. <view class="other" @click="showMsg">
  45. <text class="choose">已选:<text class="name">{{defaultSku.skuName}}</text></text>
  46. <text class="space">...</text>
  47. </view>
  48. <van-viewider customStyle="font-width: 3rpx;" />
  49. <van-cell title-style="cell-title" center value="共0条" is-link>
  50. <template #title>
  51. <text>评价:</text>
  52. <text class="total">
  53. 好评{{commData.positiveRating}}%
  54. </text>
  55. </template>
  56. </van-cell>
  57. <view class="word">
  58. <view>
  59. <van-tag type="warning">全部({{ commData.number }})</van-tag>
  60. </view>
  61. <view>
  62. <van-tag type="warning">好评({{ commData.praiseNumber }})</van-tag>
  63. </view>
  64. <view>
  65. <van-tag type="warning">中评({{ commData.secondaryNumber }})</van-tag>
  66. </view>
  67. <view>
  68. <van-tag type="warning">差评({{ commData.negativeNumber }})</van-tag>
  69. </view>
  70. <view>
  71. <van-tag type="warning">有图({{ commData.picNumber }})</van-tag>
  72. </view>
  73. </view>
  74. <!-- 内容页 -->
  75. <view v-html="formatHtml(prodData.content)"></view>
  76. <!-- 购物框提示 -->
  77. <van-action-sheet :show="showDesc" class="tips" @click-overlay="cancelDesc">
  78. <!-- 商品提示信息 -->
  79. <van-card :num="confirm.orderItem.prodCount" :price="defaultSku.price ? defaultSku.price : prodData.price"
  80. :desc="prodData.brief" :title="defaultSku.skuName ? defaultSku.skuName : prodData.prodName"
  81. :thumb="defaultSku.pic ? defaultSku.pic : prodData.pic">
  82. <template #footer>
  83. <van-stepper :value="confirm.orderItem.prodCount" integer />
  84. </template>
  85. </van-card>
  86. <!-- 型号 -->
  87. <view class="action-sheet-content">
  88. <view>
  89. <!-- {{tags}} -->
  90. <view v-for="(tag, idx) in tags" :key="idx">
  91. <view class="tagName">
  92. {{ tag.label }}
  93. </view>
  94. <view class="tagMenu">
  95. <view class="defaultSelect"
  96. :class="{ 'prop-selected': selectedTag[tag.label] === t.value ? true : false }"
  97. v-for="(t, index) in tag.options" :key="index" type="danger"
  98. @click="selectTag(tag.label, t.value)">
  99. {{ t.value }}
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. <view style="margin-top: 2rem;"></view>
  105. <!-- 按钮 -->
  106. <view class="shopcart-button">
  107. <van-button class="left" :disabled="defaultSku.price ? false : true" type="danger"
  108. @click="shopcartAdd">加入购物车</van-button>
  109. <van-button class="right" :disabled="defaultSku.price ? false : true" type="danger" @click="buynow">
  110. 立即购买</van-button>
  111. </view>
  112. </view>
  113. </van-action-sheet>
  114. </van-action-sheet>
  115. <!-- 型号选择 -->
  116. <van-action-sheet :show="showMain" @click-overlay="cancelMain" description="选择产品类别">
  117. <view class="mainContent">
  118. <view v-for="(tag, idx) in tags" :key="idx">
  119. <view class="tagName">
  120. {{ tag.label }}
  121. </view>
  122. <view class="tagMenu">
  123. <view class="defaultSelect"
  124. :class="{ 'prop-selected': selectedTag[tag.label] === t.value ? true : false }"
  125. v-for="(t, index) in tag.options" :key="index" type="danger"
  126. @click="selectTag(tag.label, t.value)">
  127. {{ t.value }}
  128. </view>
  129. </view>
  130. </view>
  131. <van-button class="submitBtn" :disabled="defaultSku.skuName ? false : true" type="danger" block
  132. @click="cancelMain">确定</van-button>
  133. </view>
  134. </van-action-sheet>
  135. <!-- 导航栏 -->
  136. <van-goods-action>
  137. <van-goods-action-icon icon="cart-o" text="购物车" @click="onClickShop" />
  138. <van-goods-action-icon icon="shop-o" text="店铺" bind:click="onClickIcon" />
  139. <van-goods-action-button text="立即购买" @click="onClickButton" />
  140. </van-goods-action>
  141. </view>
  142. </template>
  143. <script>
  144. import {
  145. prodInfo,
  146. prodComm,
  147. isCollection,
  148. addOrCancel,
  149. changeItem
  150. } from '../../api/detail.js';
  151. import {
  152. formatHtml
  153. } from '../../utils/util.js'
  154. export default {
  155. data() {
  156. return {
  157. prodList: [],
  158. bannerList: [],
  159. prodData: [],
  160. defaultSku: {},
  161. selectedTag: {},
  162. showDesc: false,
  163. isCollection: false,
  164. showMain: false,
  165. tags: {},
  166. commData: {
  167. positiveRating: 0,
  168. number: 0,
  169. praiseNumber: 0,
  170. secondaryNumber: 0,
  171. negativeNumber: 0,
  172. picNumber: 0
  173. },
  174. confirm: {
  175. basketIds: [],
  176. orderItem: {
  177. prodId: 0,
  178. skuId: 0,
  179. prodCount: 1,
  180. shopId: 0,
  181. distributionCardNo: ""
  182. },
  183. addrId: 0,
  184. userChangeCoupon: 0,
  185. couponIds: [],
  186. },
  187. skuList: [],
  188. shopCart:{
  189. basketId: 0,
  190. prodId: 0,
  191. skuId: 0,
  192. shopId: 0,
  193. count: 0,
  194. distributionCardNo: ""
  195. }
  196. }
  197. },
  198. async onLoad(options) {
  199. let result = await prodInfo({
  200. prodId: options.id
  201. })
  202. this.bannerList = result.skuList;
  203. this.skuList = result.skuList;
  204. this.prodList = result;
  205. this.prodData = result;
  206. this.init(result.skuList)
  207. prodComm({
  208. prodId: options.id
  209. }).then(res => {
  210. this.commData = res
  211. })
  212. this.isCollection = await isCollection({
  213. prodId: options.id
  214. })
  215. },
  216. methods: {
  217. init(sku) {
  218. const properties = []
  219. const propObject = {}
  220. let defaultArr = []
  221. for (let i = 0; i < sku.length; i++) {
  222. properties.push(sku[i].properties)
  223. }
  224. for (let i = 0; i < properties.length; i++) {
  225. const propStr = properties[i]
  226. const propArr = propStr.split(";")
  227. if (defaultArr.length === 0) {
  228. defaultArr = propArr
  229. this.defaultSku = sku[i]
  230. if (sku.length === 1) return;
  231. }
  232. for (let n = 0; n < propArr.length; n++) {
  233. const valueStr = propArr[n];
  234. const valueArr = valueStr.split(":")
  235. if (!propObject[valueArr[0]]) {
  236. propObject[valueArr[0]] = new Set()
  237. }
  238. propObject[valueArr[0]].add(valueArr[1])
  239. }
  240. }
  241. const processedData = Object.entries(propObject).map(([key, values]) => {
  242. return {
  243. label: key,
  244. options: Array.from(values).map(value => {
  245. return {
  246. label: value,
  247. value: value
  248. };
  249. })
  250. };
  251. });
  252. this.tags = processedData;
  253. for (let i = defaultArr.length - 1; i >= 0; i--) {
  254. const valueStr = defaultArr[i];
  255. const valueArr = valueStr.split(":")
  256. this.$set(this.selectedTag, valueArr[0], valueArr[1])
  257. }
  258. },
  259. selectTag(propTitle, Propvalue) {
  260. //当用户选择一个属性的时候, 我们存储他的选择
  261. this.$set(this.selectedTag, propTitle, Propvalue)
  262. //然后我们判断 用户选择的属性时候能找到对应的prop
  263. let str = ""
  264. for (let item in this.selectedTag) {
  265. str = item + ":" + this.selectedTag[item] + ";" + str
  266. }
  267. str = str.substring(0, str.length - 1)
  268. for (let i = 0; i < this.skuList.length; i++) {
  269. if (this.skuList[i].properties === str) {
  270. this.defaultSku = this.skuList[i]
  271. return;
  272. }
  273. }
  274. this.defaultSku = {}
  275. },
  276. showMsg() {
  277. this.showMain = true;
  278. },
  279. cancelMain() {
  280. this.showMain = false;
  281. },
  282. addOrCancel() {
  283. this.isCollection = !this.isCollection
  284. },
  285. shopcartAdd() {
  286. let that = this;
  287. this.shopCart.basketId = 0
  288. this.shopCart.prodId = this.prodData.prodId
  289. this.shopCart.skuId = this.defaultSku.skuId
  290. this.shopCart.shopId = this.prodData.shopId
  291. this.shopCart.count = this.confirm.orderItem.prodCount
  292. changeItem(this.shopCart).then(res => {
  293. uni.showToast({
  294. title: '添加成功!',
  295. //将值设置为 success 或者直接不用写icon这个参数
  296. icon: 'success',
  297. //显示持续时间为 2秒
  298. duration: 2000
  299. })
  300. that.showDesc = false
  301. }).catch(e => {
  302. console.log(e)
  303. })
  304. },
  305. formatHtml(t) {
  306. return formatHtml(t)
  307. },
  308. onClickButton() {
  309. this.showDesc = true;
  310. },
  311. cancelDesc() {
  312. this.showDesc = false;
  313. },
  314. buynow() {
  315. this.confirm.orderItem.prodId = this.prodData.prodId
  316. this.confirm.orderItem.skuId = this.defaultSku.skuId
  317. this.confirm.orderItem.shopId = this.prodData.shopId
  318. this.confirm.orderItem.distributionCardNo = ""
  319. uni.setStorageSync("confirm", JSON.stringify(this.confirm) )
  320. uni.navigateTo({
  321. url:'/pages/order/order'
  322. })
  323. },
  324. onClickShop() {
  325. uni.switchTab({
  326. url: "/pages/shop/shop"
  327. })
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="less">
  333. .uni-margin-wrap {
  334. .swiper {
  335. width: 100%;
  336. height: 600rpx;
  337. image {
  338. width: 100%;
  339. height: 100%;
  340. }
  341. }
  342. }
  343. .mainContent {
  344. height: 600rpx;
  345. }
  346. .defaultSelect {
  347. padding: 15rpx;
  348. color: #f00;
  349. border: 1px solid #f00;
  350. }
  351. .shopcart-button {
  352. .left .van-button--normal {
  353. width: 50%;
  354. background-color: #595959;
  355. border: 1px solid #595959;
  356. }
  357. .right .van-button--normal {
  358. width: 50%;
  359. }
  360. }
  361. .tagName {
  362. font-size: 38rpx;
  363. }
  364. .submitBtn {
  365. position: absolute;
  366. bottom: 0;
  367. width: 100%;
  368. }
  369. .tagMenu {
  370. width: 100%;
  371. height: 100rpx;
  372. display: flex;
  373. justify-content: space-around;
  374. align-items: center;
  375. }
  376. .message {
  377. .name {
  378. font-size: 38rpx;
  379. }
  380. .collect {
  381. margin-left: 10rpx;
  382. font-size: 38rpx;
  383. }
  384. .tip .van-col--20 {
  385. font-size: 20rpx;
  386. margin-top: 22rpx;
  387. }
  388. .price .van-col--20 {
  389. margin-top: 18rpx;
  390. font-size: 28rpx;
  391. color: red;
  392. text {
  393. font-size: 41rpx;
  394. }
  395. }
  396. }
  397. .prop-selected {
  398. color: #FFF !important;
  399. background-color: red !important;
  400. }
  401. .prod-info /deep/ .van-tag {
  402. color: #ee0a24;
  403. margin-left: 1rem;
  404. padding: 0.3rem;
  405. }
  406. .other {
  407. display: flex;
  408. height: 100rpx;
  409. align-items: center;
  410. justify-content: space-between;
  411. padding: 0 15rpx;
  412. .name {
  413. font-size: 40rpx;
  414. font-size: 36rpx;
  415. padding-left: 6px;
  416. }
  417. }
  418. .word {
  419. height: 100rpx;
  420. width: 100%;
  421. display: flex;
  422. justify-content: space-around;
  423. align-items: center;
  424. margin: 15rpx 0;
  425. view {
  426. padding: 20rpx;
  427. text-align: center;
  428. }
  429. }
  430. </style>