detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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="(item, idx) in tags" :key="idx">
  91. <text style="text-align: left;">
  92. {{item.label}}
  93. </text>
  94. <view class="right" v-for="(news, index) in item.options" :key="index">
  95. {{news.value}}
  96. </view>
  97. </view>
  98. </view>
  99. <view style="margin-top: 2rem;"></view>
  100. <!-- 按钮 -->
  101. <view class="shopcart-button">
  102. <van-button class="left" :disabled="defaultSku.price ? false : true" type="danger"
  103. @click="shopcartAdd">加入购物车</van-button>
  104. <van-button class="right" :disabled="defaultSku.price ? false : true" type="danger" @click="buynow">
  105. 立即购买</van-button>
  106. </view>
  107. </view>
  108. </van-action-sheet>
  109. </van-action-sheet>
  110. <!-- 型号选择 -->
  111. <van-action-sheet :show="showMain" @click-overlay="cancelMain">
  112. <view class="action-sheet-content">
  113. <view>
  114. <view v-for="(tag, idx) in tags" :key="idx">
  115. <view style="text-align: left;">
  116. {{ tag.label }}
  117. </view>
  118. <van-tag @click="selectTag(idx, t)"
  119. :class="{ 'prop-selected': selectedTag[idx] === t ? true : false }" plain
  120. v-for="(t, index) in tag.options" :key="index" type="danger">{{ t.value }}</van-tag>
  121. </view>
  122. </view>
  123. <view style="margin-top: 2rem;"></view>
  124. <van-button :disabled="defaultSku.skuName ? false : true" type="danger" block
  125. @click="showMain = false">确定</van-button>
  126. </view>
  127. </van-action-sheet>
  128. <!-- 导航栏 -->
  129. <van-goods-action>
  130. <van-goods-action-icon icon="cart-o" text="购物车" @click="onClickShop" />
  131. <van-goods-action-icon icon="shop-o" text="店铺" bind:click="onClickIcon" />
  132. <van-goods-action-button text="立即购买" @click="onClickButton" />
  133. </van-goods-action>
  134. </view>
  135. </template>
  136. <script>
  137. import {
  138. prodInfo,
  139. prodComm,
  140. isCollection,
  141. addOrCancel,
  142. changeItem
  143. } from '../../api/detail.js';
  144. import {
  145. formatHtml
  146. } from '../../utils/util.js'
  147. export default {
  148. data() {
  149. return {
  150. prodList: [],
  151. bannerList: [],
  152. prodData: [],
  153. defaultSku: {},
  154. selectedTag: {},
  155. showDesc: false,
  156. isCollection: false,
  157. showMain:false,
  158. tags: {},
  159. commData: {
  160. positiveRating: 0,
  161. number: 0,
  162. praiseNumber: 0,
  163. secondaryNumber: 0,
  164. negativeNumber: 0,
  165. picNumber: 0
  166. },
  167. confirm: {
  168. basketIds: [],
  169. orderItem: {
  170. prodId: 0,
  171. skuId: 0,
  172. prodCount: 1,
  173. shopId: 0,
  174. distributionCardNo: ""
  175. },
  176. addrId: 0,
  177. userChangeCoupon: 0,
  178. couponIds: [],
  179. skuList: [],
  180. shopcart: {
  181. basketId: 0,
  182. prodId: 0,
  183. skuId: 0,
  184. shopId: 0,
  185. count: 0,
  186. distributionCardNo: ""
  187. }
  188. },
  189. }
  190. },
  191. async onLoad(options) {
  192. console.log(options)
  193. let result = await prodInfo({
  194. prodId: 71
  195. })
  196. console.log(result,'99')
  197. this.bannerList = result.skuList;
  198. this.skuList = result.skuList;
  199. this.prodList = result;
  200. this.prodData = result;
  201. this.init(result.skuList)
  202. prodComm({
  203. prodId: 71
  204. }).then(res => {
  205. this.commData = res
  206. })
  207. this.isCollection = await isCollection({prodId:71})
  208. },
  209. methods: {
  210. init(sku) {
  211. const properties = []
  212. const propObject = {}
  213. let defaultArr = []
  214. for (let i = 0; i < sku.length; i++) {
  215. properties.push(sku[i].properties)
  216. }
  217. for (let i = 0; i < properties.length; i++) {
  218. const propStr = properties[i]
  219. const propArr = propStr.split(";")
  220. if (defaultArr.length === 0) {
  221. defaultArr = propArr
  222. this.defaultSku = sku[i]
  223. if (sku.length === 1) return;
  224. }
  225. for (let n = 0; n < propArr.length; n++) {
  226. const valueStr = propArr[n];
  227. const valueArr = valueStr.split(":")
  228. if (!propObject[valueArr[0]]) {
  229. propObject[valueArr[0]] = new Set()
  230. }
  231. propObject[valueArr[0]].add(valueArr[1])
  232. }
  233. }
  234. const processedData = Object.entries(propObject).map(([key, values]) => {
  235. return {
  236. label: key,
  237. options: Array.from(values).map(value => {
  238. return {
  239. label: value,
  240. value: value
  241. };
  242. })
  243. };
  244. });
  245. this.tags = processedData;
  246. console.log(this.tags, 'this.tags')
  247. for (let i = defaultArr.length - 1; i >= 0; i--) {
  248. const valueStr = defaultArr[i];
  249. const valueArr = valueStr.split(":")
  250. this.$set(this.selectedTag, valueArr[0], valueArr[1])
  251. }
  252. },
  253. showMsg() {
  254. this.showMain = true;
  255. },
  256. cancelMain() {
  257. this.showMain = false;
  258. },
  259. addOrCancel() {
  260. this.isCollection = !this.isCollection
  261. },
  262. shopcartAdd() {
  263. this.shopcart.basketId = 0
  264. this.shopcart.prodId = this.prodData.prodId
  265. this.shopcart.skuId = this.defaultSku.skuId
  266. this.shopcart.shopId = this.prodData.shopId
  267. this.shopcart.count = this.confirm.orderItem.prodCount
  268. changeItem(this.shopcart).then(r => {
  269. Toast("添加成功!")
  270. this.showDesc = false
  271. }).catch(e => {
  272. console.log(e)
  273. })
  274. },
  275. selectTag(propTitle, Propvalue) {
  276. //当用户选择一个属性的时候, 我们存储他的选择
  277. this.$set(this.selectedTag, propTitle, Propvalue)
  278. //然后我们判断 用户选择的属性时候能找到对应的prop
  279. let str = ""
  280. for (let item in this.selectedTag) {
  281. str = item + ":" + this.selectedTag[item] + ";" + str
  282. }
  283. str = str.substring(0, str.length - 1)
  284. for (let i = 0; i < this.skuList.length; i++) {
  285. if (this.skuList[i].properties === str) {
  286. this.defaultSku = this.skuList[i]
  287. return;
  288. }
  289. }
  290. this.defaultSku = {}
  291. },
  292. formatHtml(t) {
  293. return formatHtml(t)
  294. },
  295. onClickButton() {
  296. this.showDesc = true;
  297. },
  298. cancelDesc() {
  299. this.showDesc = false;
  300. },
  301. onClickShop() {
  302. uni.switchTab({
  303. url: "/pages/shop/shop"
  304. })
  305. }
  306. }
  307. }
  308. </script>
  309. <style lang="less">
  310. .uni-margin-wrap {
  311. .swiper {
  312. width: 100%;
  313. height: 600rpx;
  314. image {
  315. width: 100%;
  316. height: 100%;
  317. }
  318. }
  319. }
  320. .shopcart-button {
  321. .left .van-button--normal {
  322. width: 50%;
  323. background-color: #595959;
  324. border: 1px solid #595959;
  325. }
  326. .right .van-button--normal {
  327. width: 50%;
  328. }
  329. }
  330. .message {
  331. .name {
  332. font-size: 38rpx;
  333. }
  334. .collect {
  335. margin-left: 10rpx;
  336. font-size: 38rpx;
  337. }
  338. .tip .van-col--20 {
  339. font-size: 20rpx;
  340. margin-top: 22rpx;
  341. }
  342. .price .van-col--20 {
  343. margin-top: 18rpx;
  344. font-size: 28rpx;
  345. color: red;
  346. text {
  347. font-size: 41rpx;
  348. }
  349. }
  350. }
  351. .prop-selected {
  352. color: #FFF !important;
  353. background-color: red !important;
  354. }
  355. .prod-info /deep/ .van-tag {
  356. color: #ee0a24;
  357. margin-left: 1rem;
  358. padding: 0.3rem;
  359. }
  360. .other {
  361. display: flex;
  362. height: 100rpx;
  363. align-items: center;
  364. justify-content: space-between;
  365. padding: 0 15rpx;
  366. .choose {
  367. // flex: 5;
  368. }
  369. .name {
  370. font-size: 40rpx;
  371. font-size: 36rpx;
  372. padding-left: 6px;
  373. }
  374. .space {
  375. // flex: 1;
  376. }
  377. }
  378. .word {
  379. height: 100rpx;
  380. width: 100%;
  381. display: flex;
  382. justify-content: space-around;
  383. align-items: center;
  384. margin: 15rpx 0;
  385. view {
  386. padding: 20rpx;
  387. text-align: center;
  388. }
  389. }
  390. </style>