index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <view class="combinationBox">
  3. <JHeader :dark="false" title="组合优惠" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view class="topInfo">
  5. <view class="topBg">
  6. <swiper class="swiper" circular autoplay vertical :duration="2000">
  7. <swiper-item v-for="(item, index) in ruleList" :key="index">
  8. <view class="swiper-item uni-bg-red">{{ item.price }}元任选{{ item.number }}件</view>
  9. </swiper-item>
  10. </swiper>
  11. </view>
  12. </view>
  13. <view class="combinationList">
  14. <view v-if="productList && productList.length" class="listBox">
  15. <view
  16. v-for="(item, index) in productList" :key="index" class="combinationItem"
  17. @click="goodsDateils(item.shopId, item.productId, item.skuId)"
  18. >
  19. <view class="imgBox">
  20. <image :src="common.seamingImgUrl(item.image)" class="pic-img default-img"></image>
  21. </view>
  22. <view class="itemInfoBox">
  23. <view class="itemTit">{{ item.productName }}</view>
  24. <view class="itemNum">{{ item.number }}人付款</view>
  25. <view class="addInfo">
  26. <view class="price">¥{{ item.price }}</view>
  27. <view class="selectBtn" @click.stop="showRuleBox(item, index)">
  28. <tui-icon v-if="item.selected === 0" name="cart" :size="54" unit="upx" color="#cccccc"></tui-icon>
  29. <tui-icon v-else name="cart-fill" :size="54" unit="upx" color="#333333"></tui-icon>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view style="padding-bottom: 45upx;">
  36. <LoadingMore
  37. :status="!isEmpty && !productList.length
  38. ? 'loading' : !isEmpty && productList.length && (productList.length >= productTotal) ? 'no-more' : ''"
  39. >
  40. </LoadingMore>
  41. <tui-no-data v-if="isEmpty" :fixed="false" style="margin-top: 60upx;">暂无数据</tui-no-data>
  42. </view>
  43. </view>
  44. <!-- 商品详情 -->
  45. <tui-bottom-popup :show="goosDetailshowFlag" @close="goosDetailshowFlag = false">
  46. <view class="goosDetailshow-box">
  47. <view class="detailImg-box flex-row-plus">
  48. <image class="detailImg default-img" :src="common.seamingImgUrl(skuImg)"></image>
  49. <view class="flex-column-plus mar-left-40">
  50. <view class="font-color-C5AA7B">
  51. <label class="fs24">¥</label>
  52. <label class="fs36 mar-left-10" v-text="detailList.activityType == 1 ? skuOriginalPrice : skuPrice"></label>
  53. </view>
  54. <label class="fs24 font-color-999 mar-top-20">库存 {{ stockNumber }} 件</label>
  55. <label class="fs24 mar-top-20">已选</label>
  56. </view>
  57. </view>
  58. <view class="color-box flex-column-plus">
  59. <view v-for="(attritem, index) in skuProdList.names" :key="index">
  60. <label class="fs24 font-color-999">{{ attritem.skuName }}</label>
  61. <view class="colorName-box">
  62. <view v-for="(attrRes, resIndex) in attritem.values" :key="resIndex" class="pad-bot-30">
  63. <view
  64. class="colorName" :class="{ 'colorName-on': subIndex[index] == resIndex }"
  65. @click="colorActiveClick(attrRes, index, resIndex)"
  66. >
  67. {{ attrRes.skuValue }}
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="goodsNum-box flex-row-plus flex-sp-between">
  74. <label class="font-color-999 fs24">数量</label>
  75. <view class="goodsNum">
  76. <text class="subtract" @click="numSub()">-</text>
  77. <text class="goodsNumber">{{ buyNum }}</text>
  78. <text class="add" @click.stop="numAdd()">+</text>
  79. </view>
  80. </view>
  81. <view class="flex-items flex-sp-around btnBox">
  82. <view class="goosDetailbut-box flex-row-plus" @click="goosDetailshowFlag = false">
  83. <view class="buyNowBut cancelBtn">取消</view>
  84. </view>
  85. <view class="goosDetailbut-box flex-items-plus" @click="goosDetailshowFlag = false">
  86. <view class="buyNowBut" @click="addCart">确定</view>
  87. </view>
  88. </view>
  89. </view>
  90. </tui-bottom-popup>
  91. </view>
  92. </template>
  93. <script>
  94. import { getSelectByPriceIdApi, getSelectProductListByPriceIdApi, getProductDetailsByIdApi, getProductsSkuApi, addCartShoppingApi } from '../../../api/anotherTFInterface'
  95. export default {
  96. name: 'Combination',
  97. data() {
  98. return {
  99. isEmpty: false,
  100. productList: [],
  101. productTotal: 0,
  102. queryInfo: {
  103. page: 1,
  104. pageSize: 20,
  105. priceId: null
  106. },
  107. ruleList: [],
  108. buyNum: 1,
  109. goosDetailshowFlag: false, // 规格选择
  110. selectedMsg: {
  111. shopId: 0,
  112. skuId: 0,
  113. productId: 0
  114. },
  115. skuProdId: '',
  116. skuPrice: '',
  117. skuOriginalPrice: '',
  118. attrItemIdArr: [],
  119. detailList: [],
  120. subIndex: [],
  121. selectArr: [], // 存放被选中的值
  122. skuProdList: [],
  123. stockNumber: 0,
  124. skuImg: '',
  125. currentIndex: null
  126. }
  127. },
  128. onLoad(option) {
  129. this.priceId = option.priceId
  130. this.getSelectByPriceId() // 获取定价
  131. this.getSelectProductListByPriceId()
  132. },
  133. methods: {
  134. getSelectByPriceId() {
  135. // uni.showLoading({
  136. // mask: true,
  137. // title: '加载中...',
  138. // })
  139. getSelectByPriceIdApi({
  140. priceId: this.priceId
  141. }).then((res) => {
  142. uni.hideLoading()
  143. this.ruleList = res.data
  144. })
  145. },
  146. showRuleBox(item, index) {
  147. this.selectedMsg.shopId = item.shopId
  148. this.productId = item.productId
  149. this.selectedMsg.skuId = item.skuId
  150. this.currentIndex = index
  151. this.goosDetailshowFlag = true
  152. this.getProductSku()
  153. this.queryProductDetail()
  154. },
  155. getSelectProductListByPriceId(isLoadmore) {
  156. uni.showLoading()
  157. getSelectProductListByPriceIdApi(this.queryInfo).then((res) => {
  158. this.productTotal = res.data.total
  159. if (isLoadmore) {
  160. this.productList.push(...res.data.list)
  161. } else {
  162. this.productList = res.data.list
  163. }
  164. this.isEmpty = this.productList.length === 0
  165. uni.hideLoading()
  166. })
  167. .catch((e) => {
  168. uni.hideLoading()
  169. })
  170. },
  171. // 商品详情
  172. goodsDateils(shopId, productId, skuId) {
  173. uni.navigateTo({
  174. url: '/another-tf/another-serve/goodsDetails/index?shopId=' + shopId + '&productId=' + productId + '&skuId=' + skuId
  175. })
  176. },
  177. // 获取商品详情
  178. queryProductDetail() {
  179. getProductDetailsByIdApi({
  180. shopId: this.selectedMsg.shopId,
  181. productId: this.productId,
  182. skuId: this.selectedMsg.skuId,
  183. terminal: 1
  184. }).then((res) => {
  185. this.detailList = res.data
  186. this.skuPrice = res.data.price
  187. this.skuOriginalPrice = res.data.originalPrice
  188. for (let i = 0; i < res.data.attrList.length; i++) {
  189. this.subIndex[i] = 0
  190. }
  191. this.attrItemIdArr[0] = res.data.attrList[0].attrValueList[0].id
  192. this.$forceUpdate()
  193. })
  194. },
  195. getProductSku() {
  196. getProductsSkuApi(API.QueryProductSku, {
  197. skuId: this.selectedMsg.skuId,
  198. productId: this.productId
  199. }).then((res) => {
  200. this.skuProdList = res.data
  201. // 渲染商详之后,默认先选中第一个规格
  202. this.colorActiveClick(res.data.names[0].values[0], 0, 0)
  203. this.skuProdId = this.selectedMsg.skuId
  204. // this.skuImg = res.data.image
  205. this.skuPrice = res.data.price
  206. this.skuOriginalPrice = res.data.originalPrice
  207. this.stockNumber = res.data.stockNumber
  208. this.detailList.ifHuabei = res.data.ifHuabei
  209. this.$forceUpdate()
  210. })
  211. },
  212. // 颜色选中事件
  213. colorActiveClick(res, index, resIndex) {
  214. const t = this
  215. t.selectArr[index] = res
  216. t.subIndex[index] = resIndex
  217. t.attrItemIdArr[index] = res.valueCode
  218. t.checkItem()
  219. t.checkItemDataClick(t.attrItemIdArr)
  220. },
  221. checkItemDataClick(attrItemIdArr) {
  222. let attrkey = ''
  223. for (let i = 0; i < attrItemIdArr.length; i++) {
  224. attrkey += attrItemIdArr[i] + ','
  225. }
  226. attrkey = attrkey.substring(0, attrkey.length - 1)
  227. const mapinfo = this.skuProdList.map
  228. for (var key in mapinfo) {
  229. if (attrkey == key) {
  230. this.skuProdId = mapinfo[key].skuId
  231. this.skuImg = mapinfo[key].skuImg
  232. this.skuPrice = mapinfo[key].price
  233. this.skuOriginalPrice = mapinfo[key].originalPrice
  234. this.stockNumber = mapinfo[key].stockNumber
  235. }
  236. }
  237. // console.log(attrItemIdArr.length, 'num')
  238. var currentCode = ''
  239. for (var i = 0; i < attrItemIdArr.length; i++) {
  240. if (i === 1 && attrItemIdArr.length > 1) {
  241. currentCode += ',' + attrItemIdArr[i]
  242. } else {
  243. currentCode += attrItemIdArr[i]
  244. }
  245. }
  246. for (const key in this.skuProdList.map) {
  247. if (key == currentCode) {
  248. this.skuImg = this.skuProdList.map[key].image
  249. this.detailList.originalPrice = this.skuProdList.map[key].originalPrice
  250. if (this.skuProdList.map[key].activityType == 1) {
  251. this.ifGroupPro = true
  252. return false
  253. }
  254. this.ifGroupPro = false
  255. }
  256. }
  257. },
  258. checkItem() {
  259. var self = this
  260. var option = self.skuProdList.names
  261. var result = [] // 定义数组存储被选中的值
  262. for (const i in option) {
  263. result[i] = self.selectArr[i] ? self.selectArr[i] : ''
  264. if (!self.subIndex[i]) {
  265. self.subIndex[i] = 0
  266. }
  267. if (!self.attrItemIdArr[i]) {
  268. self.attrItemIdArr[i] = option[i].values[0].valueCode
  269. }
  270. }
  271. for (const i in option) {
  272. var last = result[i] // 把选中的值存放到字符串last去
  273. for (const k in option[i].item) {
  274. result[i] = option[i].item[k].name // 赋值,存在直接覆盖,不存在往里面添加name值
  275. }
  276. result[i] = last // 还原,目的是记录点下去那个值,避免下一次执行循环时避免被覆盖
  277. }
  278. self.$forceUpdate() // 重绘
  279. },
  280. // 数量减
  281. numSub() {
  282. if (this.buyNum > 1) {
  283. this.buyNum = this.buyNum - 1
  284. } else {
  285. uni.showToast({
  286. title: '亲!至少一件哦!',
  287. icon: 'none'
  288. })
  289. }
  290. },
  291. // 数量加
  292. numAdd() {
  293. if (this.buyNum < this.stockNumber) {
  294. this.buyNum = this.buyNum + 1
  295. } else {
  296. uni.showToast({
  297. title: '库存不足!',
  298. icon: 'none'
  299. })
  300. }
  301. },
  302. // 加入购物车
  303. addCart() {
  304. // 判断是否登录
  305. if (this.stockNumber < 1) {
  306. uni.showToast({
  307. title: '库存不足',
  308. icon: 'none'
  309. })
  310. } else {
  311. uni.showLoading({
  312. mask: true,
  313. title: '添加中...'
  314. })
  315. addCartShoppingApi({
  316. skuId: this.skuProdId,
  317. number: this.buyNum
  318. }).then((res) => {
  319. uni.hideLoading()
  320. uni.showToast({
  321. title: '添加成功',
  322. icon: 'none'
  323. })
  324. setTimeout(() => {
  325. this.productList[this.currentIndex].selected = 1
  326. this.goosDetailshowFlag = false
  327. uni.showModal({
  328. title: '温馨提示',
  329. content: '商品已成功加入购物车?',
  330. confirmText: '去结算',
  331. cancelText: '继续添加',
  332. success: (res) => {
  333. if (res.confirm) {
  334. this.go('/another-tf/another-serve/shopCar/shopCar')
  335. } else if (res.cancel) {
  336. }
  337. }
  338. })
  339. }, 1000)
  340. this.buyNum = 1
  341. })
  342. .catch((e) => {
  343. uni.hideLoading()
  344. })
  345. }
  346. }
  347. },
  348. onReachBottom() {
  349. if (this.productList.length < this.productTotal) {
  350. ++this.queryInfo.page
  351. this.getSelectProductListByPriceId(true)
  352. }
  353. }
  354. }
  355. </script>
  356. <style lang="less" scoped>
  357. .combinationBox {
  358. background-color: #333333;
  359. min-height: 100vh;
  360. box-sizing: border-box;
  361. .topInfo {
  362. margin: 40rpx 0;
  363. .topBg {
  364. margin: 30rpx auto;
  365. width: 670rpx;
  366. height: 86rpx;
  367. line-height: 86rpx;
  368. text-align: center;
  369. background-color: #d5bd90;
  370. overflow: hidden;
  371. }
  372. }
  373. .combinationList {
  374. padding: 0 20rpx;
  375. .combinationItem {
  376. margin-bottom: 30rpx;
  377. background: #FFFFFF;
  378. .imgBox {
  379. width: 348rpx;
  380. height: 314rpx;
  381. background: #F5F5F5;
  382. image {
  383. width: 100%;
  384. height: 100%;
  385. object-fit: contain
  386. }
  387. }
  388. .itemInfoBox {
  389. padding: 20rpx;
  390. width: 348rpx;
  391. .itemTit {
  392. color: #333333;
  393. font-size: 28rpx;
  394. overflow: hidden;
  395. text-overflow: ellipsis;
  396. white-space: nowrap;
  397. margin-bottom: 15rpx;
  398. }
  399. .itemNum {
  400. color: #C5AA7B;
  401. font-size: 20rpx;
  402. font-weight: 400;
  403. border: 2rpx solid #E4E5E6;
  404. display: inline;
  405. padding: 5rpx 10rpx;
  406. }
  407. .addInfo {
  408. display: flex;
  409. align-items: center;
  410. justify-content: space-between;
  411. .price {
  412. font-size: 40rpx;
  413. color: #C83732;
  414. }
  415. .selectBtn {
  416. width: 80rpx;
  417. height: 80rpx;
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. }
  422. }
  423. }
  424. }
  425. }
  426. }
  427. .goosDetailshow-box {
  428. padding-bottom: 10upx;
  429. box-sizing: border-box;
  430. .detailImg-box {
  431. margin-top: 30upx;
  432. margin-left: 30upx;
  433. border-bottom: 2upx solid #EDEDED;
  434. padding-bottom: 20upx;
  435. .detailImg {
  436. width: 180upx;
  437. height: 180upx;
  438. }
  439. }
  440. .color-box {
  441. padding: 30upx 30upx;
  442. border-bottom: 1upx solid #EDEDED;
  443. .colorName-box {
  444. display: flex;
  445. flex-wrap: wrap;
  446. flex-direction: row;
  447. justify-content: flex-start;
  448. align-items: center;
  449. margin-top: 30upx;
  450. margin-left: -30upx;
  451. .colorName {
  452. background-color: #FFFFFF;
  453. margin-left: 30upx;
  454. padding: 10upx 32upx;
  455. font-size: 26upx;
  456. border: 2rpx solid #E4E5E6;
  457. z-index: 2;
  458. color: #333333;
  459. }
  460. .colorName-on {
  461. box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
  462. color: #C5AA7B;
  463. margin-left: 30upx;
  464. padding: 10upx 32upx;
  465. font-size: 26upx;
  466. text-align: center;
  467. z-index: 1;
  468. border: none;
  469. }
  470. }
  471. }
  472. .goodsNum-box {
  473. padding: 30upx 30upx;
  474. padding-bottom: 200upx;
  475. .goodsNum {
  476. height: 50upx;
  477. text {
  478. display: inline-block;
  479. width: 50upx;
  480. height: 50upx;
  481. border: 1upx solid #999999;
  482. text-align: center;
  483. line-height: 50upx;
  484. }
  485. .subtract {
  486. border-right: 0upx;
  487. }
  488. .add {
  489. border-left: 0upx;
  490. }
  491. }
  492. }
  493. .goosDetailbut-box {
  494. justify-content: center;
  495. .buyNowBut {
  496. width: 343upx;
  497. height: 80upx;
  498. background-color: #333333;
  499. font-size: 28upx;
  500. line-height: 80upx;
  501. text-align: center;
  502. color: #FFEBC4;
  503. }
  504. .cancelBtn {
  505. background-color: #FFFFFF !important;
  506. border: 2rpx solid #333333;
  507. color: #333333;
  508. }
  509. }
  510. .btnBox {
  511. padding-bottom: 20rpx;
  512. }
  513. }
  514. </style>