detail.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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">
  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. <view class="word">
  50. <view>
  51. <van-tag type="warning">全部({{ commData.number }})</van-tag>
  52. </view>
  53. <view>
  54. <van-tag type="warning">好评({{ commData.praiseNumber }})</van-tag>
  55. </view>
  56. <view>
  57. <van-tag type="warning">中评({{ commData.secondaryNumber }})</van-tag>
  58. </view>
  59. <view>
  60. <van-tag type="warning">差评({{ commData.negativeNumber }})</van-tag>
  61. </view>
  62. <view>
  63. <van-tag type="warning">有图({{ commData.picNumber }})</van-tag>
  64. </view>
  65. </view>
  66. <!-- 内容页 -->
  67. <view v-html="formatHtml(prodData.content)"></view>
  68. <!-- 购物框提示 -->
  69. <van-action-sheet :show="showDesc" class="tips">
  70. <!-- 商品提示信息 -->
  71. <van-card :num="confirm.orderItem.prodCount" :price="defaultSku.price ? defaultSku.price : prodData.price"
  72. :desc="prodData.brief" :title="defaultSku.skuName ? defaultSku.skuName : prodData.prodName"
  73. :thumb="defaultSku.pic ? defaultSku.pic : prodData.pic">
  74. <template #tags>
  75. </template>
  76. <template #footer>
  77. <van-stepper v-model="confirm.orderItem.prodCount" integer />
  78. </template>
  79. </van-card>
  80. <!-- 型号 -->
  81. <view class="action-sheet-content">
  82. <view>
  83. <!-- {{tags}} -->
  84. <view v-for="(item, idx) in tags" :key="idx">
  85. <view style="text-align: left;">
  86. {{ idx }}
  87. <view class="right" v-for="(item1, index) in item" :key="index">
  88. 11111
  89. {{item1}}
  90. </view>
  91. </view>
  92. <!-- <view class="right" v-for="(a,b) in item" :key="b">
  93. aaaa{{a}}
  94. </view> -->
  95. <!-- <van-tag @click="selectTag(idx, t)"
  96. :class="{ 'prop-selected': selectedTag[idx] === t ? true : false }" plain
  97. v-for="(t, index) in tag" :key="index" type="danger">{{ t }}</van-tag> -->
  98. </view>
  99. </view>
  100. <view style="margin-top: 2rem;"></view>
  101. <!-- 按钮 -->
  102. <view class="shopcart-button">
  103. <van-button class="left" :disabled="defaultSku.price ? false : true" type="danger"
  104. @click="shopcartAdd">加入购物车</van-button>
  105. <van-button class="right" :disabled="defaultSku.price ? false : true" type="danger" @click="buynow">
  106. 立即购买</van-button>
  107. </view>
  108. </view>
  109. </van-action-sheet>
  110. <!-- 导航栏 -->
  111. <van-goods-action>
  112. <van-goods-action-icon icon="cart-o" text="购物车" @click="onClickShop" />
  113. <van-goods-action-icon icon="shop-o" text="店铺" bind:click="onClickIcon" />
  114. <van-goods-action-button text="立即购买" @click="onClickButton" />
  115. </van-goods-action>
  116. </view>
  117. </template>
  118. <script>
  119. import {
  120. prodInfo,
  121. prodComm,
  122. isCollection,
  123. addOrCancel,
  124. changeItem
  125. } from '../../api/detail.js';
  126. import {
  127. formatHtml
  128. } from '../../utils/util.js'
  129. export default {
  130. data() {
  131. return {
  132. prodList: [],
  133. bannerList: [],
  134. prodData: [],
  135. defaultSku: {},
  136. selectedTag: {},
  137. showDesc: false,
  138. isCollection: false,
  139. tags: {},
  140. commData: {
  141. positiveRating: 0,
  142. number: 0,
  143. praiseNumber: 0,
  144. secondaryNumber: 0,
  145. negativeNumber: 0,
  146. picNumber: 0
  147. },
  148. confirm: {
  149. basketIds: [],
  150. orderItem: {
  151. prodId: 0,
  152. skuId: 0,
  153. prodCount: 1,
  154. shopId: 0,
  155. distributionCardNo: ""
  156. },
  157. addrId: 0,
  158. userChangeCoupon: 0,
  159. couponIds: [],
  160. shopcart: {
  161. basketId: 0,
  162. prodId: 0,
  163. skuId: 0,
  164. shopId: 0,
  165. count: 0,
  166. distributionCardNo: ""
  167. }
  168. },
  169. }
  170. },
  171. async onLoad(options) {
  172. console.log(options)
  173. let result = await prodInfo({
  174. prodId: 71
  175. })
  176. console.log(result)
  177. this.bannerList = result.skuList;
  178. this.prodList = result;
  179. this.prodData = result;
  180. this.init(result.skuList)
  181. prodComm({
  182. prodId: 71
  183. }).then(res => {
  184. this.commData = res
  185. })
  186. this.isCollection = await isCollection({prodId:71})
  187. },
  188. methods: {
  189. init(sku) {
  190. const properties = []
  191. const propObject = {}
  192. let defaultArr = []
  193. for (let i = 0; i < sku.length; i++) {
  194. properties.push(sku[i].properties)
  195. }
  196. for (let i = 0; i < properties.length; i++) {
  197. const propStr = properties[i]
  198. const propArr = propStr.split(";")
  199. if (defaultArr.length === 0) {
  200. defaultArr = propArr
  201. this.defaultSku = sku[i]
  202. if (sku.length === 1) return;
  203. }
  204. for (let n = 0; n < propArr.length; n++) {
  205. const valueStr = propArr[n];
  206. const valueArr = valueStr.split(":")
  207. if (!propObject[valueArr[0]]) {
  208. propObject[valueArr[0]] = new Set()
  209. }
  210. propObject[valueArr[0]].add(valueArr[1])
  211. }
  212. }
  213. this.tags = propObject;
  214. console.log(this.tags, 'this.tags')
  215. for (let i = defaultArr.length - 1; i >= 0; i--) {
  216. const valueStr = defaultArr[i];
  217. const valueArr = valueStr.split(":")
  218. this.$set(this.selectedTag, valueArr[0], valueArr[1])
  219. }
  220. },
  221. async addOrCancel() {
  222. addOrCancel(71).then(res => {console.log(res,'收藏')})
  223. // await addOrCancel(this.prodData.prodId)
  224. // await addOrCancel({prodId:this.prodData.prodId})
  225. this.isCollection = await isCollection({ prodId: this.prodData.prodId })
  226. },
  227. shopcartAdd() {
  228. this.shopcart.basketId = 0
  229. this.shopcart.prodId = this.prodData.prodId
  230. this.shopcart.skuId = this.defaultSku.skuId
  231. this.shopcart.shopId = this.prodData.shopId
  232. this.shopcart.count = this.confirm.orderItem.prodCount
  233. changeItem(this.shopcart).then(r => {
  234. Toast("添加成功!")
  235. this.showDesc = false
  236. }).catch(e => {
  237. console.log(e)
  238. })
  239. },
  240. selectTag(propTitle, Propvalue) {
  241. //当用户选择一个属性的时候, 我们存储他的选择
  242. this.$set(this.selectedTag, propTitle, Propvalue)
  243. //然后我们判断 用户选择的属性时候能找到对应的prop
  244. let str = ""
  245. for (let item in this.selectedTag) {
  246. str = item + ":" + this.selectedTag[item] + ";" + str
  247. }
  248. str = str.substring(0, str.length - 1)
  249. for (let i = 0; i < this.skuList.length; i++) {
  250. if (this.skuList[i].properties === str) {
  251. this.defaultSku = this.skuList[i]
  252. return;
  253. }
  254. }
  255. this.defaultSku = {}
  256. },
  257. formatHtml(t) {
  258. return formatHtml(t)
  259. },
  260. onClickButton() {
  261. this.showDesc = !this.showDesc;
  262. },
  263. onClickShop() {
  264. uni.switchTab({
  265. url: "/pages/shop/shop"
  266. })
  267. }
  268. }
  269. }
  270. </script>
  271. <style lang="less">
  272. .uni-margin-wrap {
  273. .swiper {
  274. width: 100%;
  275. height: 600rpx;
  276. image {
  277. width: 100%;
  278. height: 100%;
  279. }
  280. }
  281. }
  282. .shopcart-button {
  283. .left .van-button--normal {
  284. width: 50%;
  285. background-color: #595959;
  286. border: 1px solid #595959;
  287. }
  288. .right .van-button--normal {
  289. width: 50%;
  290. }
  291. }
  292. .message {
  293. .name {
  294. font-size: 38rpx;
  295. }
  296. .collect {
  297. margin-left: 10rpx;
  298. font-size: 38rpx;
  299. }
  300. .tip .van-col--20 {
  301. font-size: 20rpx;
  302. margin-top: 22rpx;
  303. }
  304. .price .van-col--20 {
  305. margin-top: 18rpx;
  306. font-size: 28rpx;
  307. color: red;
  308. text {
  309. font-size: 41rpx;
  310. }
  311. }
  312. }
  313. .prop-selected {
  314. color: #FFF !important;
  315. background-color: red !important;
  316. }
  317. .prod-info /deep/ .van-tag {
  318. color: #ee0a24;
  319. margin-left: 1rem;
  320. padding: 0.3rem;
  321. }
  322. .other {
  323. display: flex;
  324. height: 100rpx;
  325. align-items: center;
  326. justify-content: space-between;
  327. padding: 0 15rpx;
  328. .choose {
  329. // flex: 5;
  330. }
  331. .name {
  332. font-size: 40rpx;
  333. font-size: 36rpx;
  334. padding-left: 6px;
  335. }
  336. .space {
  337. // flex: 1;
  338. }
  339. }
  340. .word {
  341. height: 100rpx;
  342. width: 100%;
  343. display: flex;
  344. justify-content: space-around;
  345. align-items: center;
  346. margin: 15rpx 0;
  347. view {
  348. padding: 20rpx;
  349. text-align: center;
  350. }
  351. }
  352. </style>