detail.vue 11 KB

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