多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

618 lines
17 KiB

2 years ago
2 years ago
2 years ago
  1. <template>
  2. <view class="combinationBox">
  3. <global-loading />
  4. <view class="topInfo">
  5. <view class="topBg">
  6. <swiper class="swiper" :circular="circular" :autoplay="autoplay" :vertical="vertical" :duration="duration">
  7. <swiper-item v-for="(item, index) of 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 class="combinationItem" v-for="(item, index) of productList" :key="index" @click="goodsDateils(item.shopId,item.productId,item.skuId)">
  15. <view class="imgBox">
  16. <image :src="item.image" class="pic-img default-img"
  17. onerror="this.src='url(https://ceres.zkthink.com/static/root/default.png) no-repeat center';this.οnerrοr=null"></image>
  18. </view>
  19. <view class="itemInfoBox">
  20. <view class="itemTit">{{item.productName}}</view>
  21. <view class="itemNum">{{item.number}}人付款</view>
  22. <view class="addInfo">
  23. <view class="price">{{item.price}}</view>
  24. <view class="selectBtn" @click.stop="showRuleBox(item, index)">
  25. <image src="https://ceres.zkthink.com/static/images/cart1.png" v-if="item.selected === 0"></image>
  26. <image v-else src="https://ceres.zkthink.com/static/images/cart2.png"></image>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 商品详情-->
  33. <u-popup v-model="goosDetailshowFlag" mode="bottom" border-radius="14">
  34. <view class="goosDetailshow-box">
  35. <view class="detailImg-box flex-row-plus">
  36. <image class="detailImg default-img" :src="skuImg"
  37. onerror="this.src='url(https://ceres.zkthink.com/static/root/default.png) no-repeat center';this.οnerrοr=null"></image>
  38. <view class="flex-column-plus mar-left-40">
  39. <view class="font-color-C5AA7B">
  40. <label class="fs24">¥</label>
  41. <label class="fs36 mar-left-10"
  42. v-text="detailList.activityType == 1 ? skuOriginalPrice : skuPrice"></label>
  43. </view>
  44. <label class="fs24 font-color-999 mar-top-20">库存 {{stockNumber}} </label>
  45. <label class="fs24 mar-top-20">已选</label>
  46. </view>
  47. </view>
  48. <view class="color-box flex-column-plus">
  49. <view v-for="(attritem,index) in skuProdList.names" :key="index">
  50. <label class="fs24 font-color-999">{{attritem.skuName}}</label>
  51. <view class="colorName-box">
  52. <view class="pad-bot-30" v-for="(attrRes, resIndex) in attritem.values" :key="resIndex">
  53. <view class="colorName" :class="{'colorName-on' :subIndex[index] == resIndex}"
  54. @click="colorActiveClick(attrRes,index,resIndex)">{{attrRes.skuValue}}</view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="goodsNum-box flex-row-plus flex-sp-between">
  60. <label class="font-color-999 fs24">数量</label>
  61. <view class="goodsNum">
  62. <text class="subtract" @click="numSub()">-</text>
  63. <text class="goodsNumber" v-model="buyNum">{{buyNum}}</text>
  64. <text class="add" @click.stop="numAdd()">+</text>
  65. </view>
  66. </view>
  67. <view class="flex-items flex-sp-around btnBox">
  68. <view class="goosDetailbut-box flex-row-plus" @click="goosDetailshowFlag = false">
  69. <view class="buyNowBut cancelBtn">取消</view>
  70. </view>
  71. <view class="goosDetailbut-box flex-items-plus" @click="goosDetailshowFlag = false">
  72. <view class="buyNowBut" @click="addCart">确定</view>
  73. </view>
  74. </view>
  75. </view>
  76. </u-popup>
  77. </view>
  78. </template>
  79. <script>
  80. // selectCompose
  81. const NET = require('../../utils/request')
  82. const API = require('../../config/api')
  83. export default {
  84. name: "combination",
  85. data() {
  86. return {
  87. page: 1,
  88. pageSize: 10,
  89. list:[],
  90. pricing: {},
  91. productList: [],
  92. ruleList: [],
  93. autoplay: true,
  94. duration: 2000,
  95. vertical: true,
  96. circular: true,
  97. buyNum: 1,
  98. goosDetailshowFlag: false, // 规格选择
  99. shopId: 0,
  100. skuId: 0,
  101. terminal: 1,
  102. skuPrice: '',
  103. skuOriginalPrice: '',
  104. attrItemIdArr: [],
  105. detailList: [],
  106. subIndex: [],
  107. selectArr: [], // 存放被选中的值
  108. skuProdList: [],
  109. stockNumber: 0,
  110. skuImg: '',
  111. currentIndex: null,
  112. priceId: null
  113. }
  114. },
  115. onLoad(option) {
  116. this.priceId = option.priceId
  117. this.getSelectByPriceId() // 获取定价
  118. this.getSelectProductListByPriceId()
  119. },
  120. methods: {
  121. getSelectByPriceId() {
  122. // uni.showLoading({
  123. // mask: true,
  124. // title: '加载中...',
  125. // })
  126. NET.request(API.selectByPriceId,{
  127. priceId: this.priceId
  128. },'GET').then(res => {
  129. uni.hideLoading()
  130. this.ruleList = res.data
  131. }).catch(res => {
  132. })
  133. },
  134. showRuleBox(item, index) {
  135. this.shopId = item.shopId
  136. this.productId = item.productId
  137. this.skuId = item.skuId
  138. this.currentIndex = index
  139. this.goosDetailshowFlag = true
  140. this.getProductSku()
  141. this.queryProductDetail()
  142. },
  143. getSelectProductListByPriceId() {
  144. NET.request(API.selectProductListByPriceId,{
  145. priceId: this.priceId,
  146. page: this.page,
  147. pageSize: this.pageSize
  148. },'GET').then(res => {
  149. uni.hideLoading()
  150. // this.productList = res.data.list
  151. var proList = res.data.list
  152. proList.forEach((item) => {
  153. item['selected'] = 0
  154. this.productList.push(item)
  155. })
  156. }).catch(res => {
  157. })
  158. },
  159. //商品详情
  160. goodsDateils(shopId,productId,skuId){
  161. uni.navigateTo({
  162. url: 'goodsDetails?shopId='+shopId + '&productId='+productId +'&skuId='+skuId
  163. })
  164. },
  165. //获取商品详情
  166. queryProductDetail() {
  167. NET.request(API.QueryProductDetail, {
  168. shopId: this.shopId,
  169. productId: this.productId,
  170. skuId: this.skuId,
  171. terminal: 1
  172. },
  173. "GET").then(res => {
  174. this.detailList = res.data
  175. this.skuPrice = res.data.price
  176. this.skuOriginalPrice = res.data.originalPrice
  177. for (let i = 0; i < res.data.attrList.length; i++) {
  178. this.subIndex[i] = 0
  179. }
  180. this.attrItemIdArr[0] = res.data.attrList[0].attrValueList[0].id
  181. this.$forceUpdate()
  182. }).catch(res => {
  183. })
  184. },
  185. getProductSku() {
  186. NET.request(API.QueryProductSku, {
  187. skuId: this.skuId,
  188. productId: this.productId
  189. }, 'GET').then(res => {
  190. this.skuProdList = res.data
  191. this.attrList = res.data.names
  192. this.attrValueList = res.data.names[0].values
  193. console.log(this.attrValueList[0], 'arr')
  194. //渲染商详之后,默认先选中第一个规格
  195. this.colorActiveClick(this.attrValueList[0], 0, 0)
  196. this.skuProdId = this.skuId
  197. // this.skuImg = res.data.image
  198. this.skuPrice = res.data.price
  199. this.skuOriginalPrice = res.data.originalPrice
  200. this.stockNumber = res.data.stockNumber
  201. this.detailList.ifHuabei = res.data.ifHuabei
  202. //this.renderHuabei(this.skuPrice)
  203. this.$forceUpdate()
  204. }).catch(res => {
  205. })
  206. },
  207. //颜色选中事件
  208. colorActiveClick(res, index, resIndex) {
  209. let t = this;
  210. t.selectArr[index] = res;
  211. t.subIndex[index] = resIndex;
  212. t.attrItemIdArr[index] = res.valueCode
  213. t.checkItem();
  214. t.checkItemDataClick(t.attrItemIdArr)
  215. },
  216. checkItemDataClick(attrItemIdArr) {
  217. let attrkey = ''
  218. for (let i = 0; i < attrItemIdArr.length; i++) {
  219. attrkey += attrItemIdArr[i] + ','
  220. }
  221. attrkey = attrkey.substring(0, attrkey.length - 1)
  222. let mapinfo = this.skuProdList.map
  223. for (var key in mapinfo) {
  224. if (attrkey == key) {
  225. this.skuProdId = mapinfo[key].skuId
  226. this.skuImg = mapinfo[key].skuImg
  227. this.skuPrice = mapinfo[key].price
  228. this.skuOriginalPrice = mapinfo[key].originalPrice
  229. this.stockNumber = mapinfo[key].stockNumber
  230. }
  231. }
  232. //console.log(attrItemIdArr.length, 'num')
  233. var currentCode = ''
  234. for (var i = 0; i < attrItemIdArr.length; i++) {
  235. if (i === 1 && attrItemIdArr.length > 1) {
  236. currentCode += ',' + attrItemIdArr[i]
  237. } else {
  238. currentCode += attrItemIdArr[i]
  239. }
  240. }
  241. for (let key in this.skuProdList.map) {
  242. if (key == currentCode) {
  243. this.skuImg = this.skuProdList.map[key].image
  244. this.detailList.originalPrice = this.skuProdList.map[key].originalPrice
  245. if (this.skuProdList.map[key].activityType == 1) {
  246. this.ifGroupPro = true
  247. return false
  248. } else {
  249. this.ifGroupPro = false
  250. }
  251. }
  252. }
  253. },
  254. checkItem() {
  255. var self = this;
  256. var option = self.attrList;
  257. var result = []; // 定义数组存储被选中的值
  258. for (let i in option) {
  259. result[i] = self.selectArr[i] ? self.selectArr[i] : "";
  260. if (!self.subIndex[i]) {
  261. self.subIndex[i] = 0
  262. }
  263. if (!self.attrItemIdArr[i]) {
  264. self.attrItemIdArr[i] = option[i].values[0].valueCode
  265. }
  266. }
  267. for (let i in option) {
  268. var last = result[i]; // 把选中的值存放到字符串last去
  269. for (let k in option[i].item) {
  270. result[i] = option[i].item[k].name; // 赋值,存在直接覆盖,不存在往里面添加name值
  271. }
  272. result[i] = last; // 还原,目的是记录点下去那个值,避免下一次执行循环时避免被覆盖
  273. }
  274. self.$forceUpdate(); // 重绘
  275. },
  276. // 数量减
  277. numSub() {
  278. if (this.buyNum > 1) {
  279. this.buyNum = this.buyNum - 1
  280. } else {
  281. uni.showToast({
  282. title: '亲!至少一件哦!',
  283. icon: "none"
  284. })
  285. }
  286. },
  287. // 数量加
  288. numAdd() {
  289. if (this.buyNum < this.stockNumber) {
  290. this.buyNum = this.buyNum + 1
  291. } else {
  292. uni.showToast({
  293. title: '库存不足!',
  294. icon: "none"
  295. })
  296. }
  297. },
  298. //加入购物车
  299. addCart() {
  300. //判断是否登录
  301. if (this.stockNumber < 1) {
  302. uni.showToast({
  303. title: '库存不足',
  304. icon: "none"
  305. })
  306. } else {
  307. // uni.showLoading({
  308. // mask: true,
  309. // title: '添加中...',
  310. // })
  311. NET.request(API.ShoppingaddCart, {
  312. skuId: this.skuProdId,
  313. number: this.buyNum,
  314. }, 'POST').then(res => {
  315. uni.hideLoading()
  316. uni.showToast({
  317. title: '添加成功',
  318. icon: 'none'
  319. })
  320. setTimeout(() => {
  321. this.productList[this.currentIndex].selected = 1
  322. this.goosDetailshowFlag = false
  323. uni.showModal({
  324. title: '温馨提示',
  325. content: '商品已成功加入购物车?',
  326. confirmText: "去结算",
  327. cancelText: '继续添加',
  328. success: res => {
  329. if (res.confirm) {
  330. uni.switchTab({
  331. url: '../../pages/tabbar/cart/index'
  332. })
  333. } else if (res.cancel) {
  334. }
  335. }
  336. })
  337. }, 1000);
  338. this.buyNum = 1
  339. }).catch(res => {
  340. uni.hideLoading()
  341. if (res.data.code == 40005) {
  342. uni.navigateTo({
  343. url: '../../pages_category_page2/userModule/login'
  344. })
  345. }
  346. })
  347. }
  348. }
  349. }
  350. }
  351. </script>
  352. <style lang="scss" scoped>
  353. page {
  354. background: #333333;
  355. }
  356. .combinationBox {
  357. .topInfo {
  358. margin: 40rpx 0;
  359. .topBg {
  360. margin: 30rpx auto;
  361. width: 670rpx;
  362. height: 86rpx;
  363. line-height: 86rpx;
  364. text-align: center;
  365. background: url("https://ceres.zkthink.com/static/images/combinationBg.png") no-repeat center center;
  366. background-size: contain;
  367. overflow: hidden;
  368. }
  369. }
  370. .combinationList {
  371. display: flex;
  372. flex-flow: wrap;
  373. justify-content: space-between;
  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. image {
  422. width: 54rpx;
  423. height: 54rpx;
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. .goosDetailshow-box {
  432. padding-bottom: 10upx;
  433. .detailImg-box {
  434. margin-top: 30upx;
  435. margin-left: 30upx;
  436. border-bottom: 2upx solid #EDEDED;
  437. padding-bottom: 20upx;
  438. width: 100%;
  439. .detailImg {
  440. width: 180upx;
  441. height: 180upx;
  442. }
  443. }
  444. .color-box {
  445. padding: 30upx 30upx;
  446. border-bottom: 1upx solid #EDEDED;
  447. width: 100%;
  448. .colorName-box {
  449. display: flex;
  450. flex-wrap: wrap;
  451. flex-direction: row;
  452. justify-content: flex-start;
  453. align-items: center;
  454. margin-top: 30upx;
  455. margin-left: -30upx;
  456. .colorName {
  457. background-color: #FFFFFF;
  458. margin-left: 30upx;
  459. padding: 10upx 32upx;
  460. font-size: 26upx;
  461. border: 2rpx solid #E4E5E6;
  462. z-index: 2;
  463. color: #333333;
  464. }
  465. .colorName-on {
  466. box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
  467. color: #C5AA7B;
  468. margin-left: 30upx;
  469. padding: 10upx 32upx;
  470. font-size: 26upx;
  471. text-align: center;
  472. z-index: 1;
  473. border: none;
  474. }
  475. }
  476. }
  477. .modelNum-box {
  478. padding: 30upx 30upx;
  479. border-bottom: 1upx solid #EDEDED;
  480. width: 690upx;
  481. .modelNumName-box {
  482. display: flex;
  483. flex-wrap: wrap;
  484. flex-direction: row;
  485. justify-content: flex-start;
  486. align-items: center;
  487. margin-top: 30upx;
  488. margin-left: -30upx;
  489. .modelNumName-on {
  490. background-color: #FFE4D0;
  491. color: #FF7800;
  492. margin-left: 30upx;
  493. padding: 10upx 32upx;
  494. border-radius: 28upx;
  495. border: 1upx solid #FF7800;
  496. font-size: 26upx;
  497. text-align: center;
  498. }
  499. .modelNumName {
  500. background-color: #F5F5F5;
  501. margin-left: 30upx;
  502. padding: 10upx 32upx;
  503. border-radius: 28upx;
  504. font-size: 26upx;
  505. }
  506. }
  507. }
  508. .goodsNum-box {
  509. padding: 30upx 30upx;
  510. width: 100%;
  511. padding-bottom: 200upx;
  512. .goodsNum{
  513. height: 50upx;
  514. text {
  515. display: inline-block;
  516. width: 50upx;
  517. height: 50upx;
  518. border: 1upx solid #999999;
  519. text-align: center;
  520. line-height: 50upx;
  521. }
  522. .subtract {
  523. border-right: 0upx;
  524. }
  525. .add {
  526. border-left: 0upx;
  527. }
  528. }
  529. }
  530. .bottom-line {
  531. border-bottom: 1upx solid #EDEDED;
  532. }
  533. .huabei-box {
  534. padding: 30upx 30upx;
  535. width: 690upx;
  536. .fenqi-box {
  537. margin-top: 15upx;
  538. width: 120%;
  539. .huabei-item {
  540. display: inline-block;
  541. background: #f3f3f3;
  542. padding: 16upx 24upx;
  543. margin: 5upx 10upx;
  544. border-radius: 15upx;
  545. text-align: center;
  546. font-size: 7upx;
  547. .huabei-period {
  548. display: block;
  549. }
  550. }
  551. .fenqi-on {
  552. border: 1px solid #EF7F93;
  553. color: #EF7F93;
  554. }
  555. .disabled {
  556. color: #cacaca;
  557. }
  558. }
  559. }
  560. .goosDetailbut-box {
  561. justify-content: center;
  562. .joinShopCartBut {
  563. width: 343upx;
  564. height: 80upx;
  565. border-radius: 40upx 0 0 40upx;
  566. background-color: #FFC300;
  567. color: #FFFEFE;
  568. font-size: 28upx;
  569. line-height: 80upx;
  570. text-align: center;
  571. margin-left: 30upx;
  572. }
  573. .buyNowBut {
  574. width: 343upx;
  575. height: 80upx;
  576. background-color: #333333;
  577. font-size: 28upx;
  578. line-height: 80upx;
  579. text-align: center;
  580. color: #FFEBC4;
  581. }
  582. .cancelBtn {
  583. background-color: #FFFFFF !important;
  584. border: 2rpx solid #333333;
  585. color: #333333;
  586. }
  587. }
  588. .btnBox {
  589. padding-bottom: 20rpx;
  590. }
  591. }
  592. </style>