detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 @change="numChange" />
  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. onShow() {
  217. },
  218. methods: {
  219. init(sku) {
  220. const properties = []
  221. const propObject = {}
  222. let defaultArr = []
  223. for (let i = 0; i < sku.length; i++) {
  224. properties.push(sku[i].properties)
  225. }
  226. for (let i = 0; i < properties.length; i++) {
  227. const propStr = properties[i]
  228. const propArr = propStr.split(";")
  229. if (defaultArr.length === 0) {
  230. defaultArr = propArr
  231. this.defaultSku = sku[i]
  232. if (sku.length === 1) return;
  233. }
  234. for (let n = 0; n < propArr.length; n++) {
  235. const valueStr = propArr[n];
  236. const valueArr = valueStr.split(":")
  237. if (!propObject[valueArr[0]]) {
  238. propObject[valueArr[0]] = new Set()
  239. }
  240. propObject[valueArr[0]].add(valueArr[1])
  241. }
  242. }
  243. const processedData = Object.entries(propObject).map(([key, values]) => {
  244. return {
  245. label: key,
  246. options: Array.from(values).map(value => {
  247. return {
  248. label: value,
  249. value: value
  250. };
  251. })
  252. };
  253. });
  254. this.tags = processedData;
  255. for (let i = defaultArr.length - 1; i >= 0; i--) {
  256. const valueStr = defaultArr[i];
  257. const valueArr = valueStr.split(":")
  258. this.$set(this.selectedTag, valueArr[0], valueArr[1])
  259. }
  260. },
  261. selectTag(propTitle, Propvalue) {
  262. //当用户选择一个属性的时候, 我们存储他的选择
  263. this.$set(this.selectedTag, propTitle, Propvalue)
  264. //然后我们判断 用户选择的属性时候能找到对应的prop
  265. let str = ""
  266. for (let item in this.selectedTag) {
  267. str = item + ":" + this.selectedTag[item] + ";" + str
  268. }
  269. str = str.substring(0, str.length - 1)
  270. for (let i = 0; i < this.skuList.length; i++) {
  271. if (this.skuList[i].properties === str) {
  272. this.defaultSku = this.skuList[i]
  273. return;
  274. }
  275. }
  276. this.defaultSku = {}
  277. },
  278. showMsg() {
  279. this.showMain = true;
  280. },
  281. cancelMain() {
  282. this.showMain = false;
  283. },
  284. addOrCancel() {
  285. this.isCollection = !this.isCollection
  286. },
  287. shopcartAdd() {
  288. let that = this;
  289. this.shopCart.basketId = 0
  290. this.shopCart.prodId = this.prodData.prodId
  291. this.shopCart.skuId = this.defaultSku.skuId
  292. this.shopCart.shopId = this.prodData.shopId
  293. this.shopCart.count = this.confirm.orderItem.prodCount
  294. this.$forceUpdate()
  295. changeItem(this.shopCart).then(res => {
  296. uni.showToast({
  297. title: '添加成功!',
  298. //将值设置为 success 或者直接不用写icon这个参数
  299. icon: 'success',
  300. //显示持续时间为 2秒
  301. duration: 2000
  302. })
  303. that.showDesc = false
  304. }).catch(e => {
  305. console.log(e)
  306. })
  307. },
  308. formatHtml(t) {
  309. return formatHtml(t)
  310. },
  311. onClickButton() {
  312. this.showDesc = true;
  313. },
  314. numChange(event) {
  315. this.confirm.orderItem.prodCount = event.detail;
  316. },
  317. cancelDesc() {
  318. this.showDesc = false;
  319. },
  320. buynow() {
  321. this.confirm.orderItem.prodId = this.prodData.prodId
  322. this.confirm.orderItem.skuId = this.defaultSku.skuId
  323. this.confirm.orderItem.shopId = this.prodData.shopId
  324. this.confirm.orderItem.distributionCardNo = ""
  325. uni.setStorageSync("confirm", JSON.stringify(this.confirm) )
  326. uni.navigateTo({
  327. url:'/pages/order/order'
  328. })
  329. },
  330. onClickShop() {
  331. uni.switchTab({
  332. url: "/pages/shop/shop"
  333. })
  334. }
  335. }
  336. }
  337. </script>
  338. <style lang="less">
  339. .uni-margin-wrap {
  340. .swiper {
  341. width: 100%;
  342. height: 600rpx;
  343. image {
  344. width: 100%;
  345. height: 100%;
  346. }
  347. }
  348. }
  349. .mainContent {
  350. height: 600rpx;
  351. }
  352. .defaultSelect {
  353. padding: 15rpx;
  354. color: #f00;
  355. border: 1px solid #f00;
  356. }
  357. .shopcart-button {
  358. .left .van-button--normal {
  359. width: 50%;
  360. background-color: #595959;
  361. border: 1px solid #595959;
  362. }
  363. .right .van-button--normal {
  364. width: 50%;
  365. }
  366. }
  367. .tagName {
  368. font-size: 38rpx;
  369. }
  370. .submitBtn {
  371. position: absolute;
  372. bottom: 0;
  373. width: 100%;
  374. }
  375. .tagMenu {
  376. width: 100%;
  377. height: 100rpx;
  378. display: flex;
  379. justify-content: space-around;
  380. align-items: center;
  381. }
  382. .message {
  383. .name {
  384. font-size: 38rpx;
  385. }
  386. .collect {
  387. margin-left: 10rpx;
  388. font-size: 38rpx;
  389. }
  390. .tip .van-col--20 {
  391. font-size: 20rpx;
  392. margin-top: 22rpx;
  393. }
  394. .price .van-col--20 {
  395. margin-top: 18rpx;
  396. font-size: 28rpx;
  397. color: red;
  398. text {
  399. font-size: 41rpx;
  400. }
  401. }
  402. }
  403. .prop-selected {
  404. color: #FFF !important;
  405. background-color: red !important;
  406. }
  407. .prod-info /deep/ .van-tag {
  408. color: #ee0a24;
  409. margin-left: 1rem;
  410. padding: 0.3rem;
  411. }
  412. .other {
  413. display: flex;
  414. height: 100rpx;
  415. align-items: center;
  416. justify-content: space-between;
  417. padding: 0 15rpx;
  418. .name {
  419. font-size: 40rpx;
  420. font-size: 36rpx;
  421. padding-left: 6px;
  422. }
  423. }
  424. .word {
  425. height: 100rpx;
  426. width: 100%;
  427. display: flex;
  428. justify-content: space-around;
  429. align-items: center;
  430. margin: 15rpx 0;
  431. view {
  432. padding: 20rpx;
  433. text-align: center;
  434. }
  435. }
  436. </style>