多租户商城-商户小程序端
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.

619 lines
17 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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(http://36.138.125.206:8081/ceres-local-file/image/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}}{{$t('common.payticktip')}}</view>
  22. <view class="addInfo">
  23. <view class="price">{{item.price}}</view>
  24. <view class="selectBtn" @click.stop="showRuleBox(item, index)">
  25. <image src="http://36.138.125.206:8081/ceres-local-file/static/images/cart1.png" v-if="item.selected === 0"></image>
  26. <image v-else src="http://36.138.125.206:8081/ceres-local-file/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(http://36.138.125.206:8081/ceres-local-file/image/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">{{$t('common.stocknum', {number: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: this.$t('common.understock'),
  294. icon: "none"
  295. })
  296. }
  297. },
  298. //加入购物车
  299. addCart() {
  300. let _this = this;
  301. //判断是否登录
  302. if (this.stockNumber < 1) {
  303. uni.showToast({
  304. title: this.$t('common.understock'),
  305. icon: "none"
  306. })
  307. } else {
  308. // uni.showLoading({
  309. // mask: true,
  310. // title: '添加中...',
  311. // })
  312. NET.request(API.ShoppingaddCart, {
  313. skuId: this.skuProdId,
  314. number: this.buyNum,
  315. }, 'POST').then(res => {
  316. uni.hideLoading()
  317. uni.showToast({
  318. title: '添加成功',
  319. icon: 'none'
  320. })
  321. setTimeout(() => {
  322. this.productList[this.currentIndex].selected = 1
  323. this.goosDetailshowFlag = false
  324. uni.showModal({
  325. title: _this.$t('common.notice_dialog_title'),
  326. content: '商品已成功加入购物车?',
  327. confirmText: "去结算",
  328. cancelText: '继续添加',
  329. success: res => {
  330. if (res.confirm) {
  331. uni.switchTab({
  332. url: '../../pages/tabbar/cart/index'
  333. })
  334. } else if (res.cancel) {
  335. }
  336. }
  337. })
  338. }, 1000);
  339. this.buyNum = 1
  340. }).catch(res => {
  341. uni.hideLoading()
  342. if (res.data.code == 40005) {
  343. uni.navigateTo({
  344. url: '../../pages_category_page2/userModule/login'
  345. })
  346. }
  347. })
  348. }
  349. }
  350. }
  351. }
  352. </script>
  353. <style lang="scss" scoped>
  354. page {
  355. background: #333333;
  356. }
  357. .combinationBox {
  358. .topInfo {
  359. margin: 40rpx 0;
  360. .topBg {
  361. margin: 30rpx auto;
  362. width: 670rpx;
  363. height: 86rpx;
  364. line-height: 86rpx;
  365. text-align: center;
  366. background: url("http://36.138.125.206:8081/ceres-local-file/static/images/combinationBg.png") no-repeat center center;
  367. background-size: contain;
  368. overflow: hidden;
  369. }
  370. }
  371. .combinationList {
  372. display: flex;
  373. flex-flow: wrap;
  374. justify-content: space-between;
  375. padding: 0 20rpx;
  376. .combinationItem {
  377. margin-bottom: 30rpx;
  378. background: #FFFFFF;
  379. .imgBox {
  380. width: 348rpx;
  381. height: 314rpx;
  382. background: #F5F5F5;
  383. image {
  384. width: 100%;
  385. height: 100%;
  386. object-fit: contain
  387. }
  388. }
  389. .itemInfoBox {
  390. padding: 20rpx;
  391. width: 348rpx;
  392. .itemTit {
  393. color: #333333;
  394. font-size: 28rpx;
  395. overflow: hidden;
  396. text-overflow: ellipsis;
  397. white-space: nowrap;
  398. margin-bottom: 15rpx;
  399. }
  400. .itemNum {
  401. color: #C5AA7B;
  402. font-size: 20rpx;
  403. font-weight: 400;
  404. border: 2rpx solid #E4E5E6;
  405. display: inline;
  406. padding: 5rpx 10rpx;
  407. }
  408. .addInfo {
  409. display: flex;
  410. align-items: center;
  411. justify-content: space-between;
  412. .price {
  413. font-size: 40rpx;
  414. color: #C83732;
  415. }
  416. .selectBtn {
  417. width: 80rpx;
  418. height: 80rpx;
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. image {
  423. width: 54rpx;
  424. height: 54rpx;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. .goosDetailshow-box {
  433. padding-bottom: 10upx;
  434. .detailImg-box {
  435. margin-top: 30upx;
  436. margin-left: 30upx;
  437. border-bottom: 2upx solid #EDEDED;
  438. padding-bottom: 20upx;
  439. width: 100%;
  440. .detailImg {
  441. width: 180upx;
  442. height: 180upx;
  443. }
  444. }
  445. .color-box {
  446. padding: 30upx 30upx;
  447. border-bottom: 1upx solid #EDEDED;
  448. width: 100%;
  449. .colorName-box {
  450. display: flex;
  451. flex-wrap: wrap;
  452. flex-direction: row;
  453. justify-content: flex-start;
  454. align-items: center;
  455. margin-top: 30upx;
  456. margin-left: -30upx;
  457. .colorName {
  458. background-color: #FFFFFF;
  459. margin-left: 30upx;
  460. padding: 10upx 32upx;
  461. font-size: 26upx;
  462. border: 2rpx solid #E4E5E6;
  463. z-index: 2;
  464. color: #333333;
  465. }
  466. .colorName-on {
  467. box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
  468. color: #C5AA7B;
  469. margin-left: 30upx;
  470. padding: 10upx 32upx;
  471. font-size: 26upx;
  472. text-align: center;
  473. z-index: 1;
  474. border: none;
  475. }
  476. }
  477. }
  478. .modelNum-box {
  479. padding: 30upx 30upx;
  480. border-bottom: 1upx solid #EDEDED;
  481. width: 690upx;
  482. .modelNumName-box {
  483. display: flex;
  484. flex-wrap: wrap;
  485. flex-direction: row;
  486. justify-content: flex-start;
  487. align-items: center;
  488. margin-top: 30upx;
  489. margin-left: -30upx;
  490. .modelNumName-on {
  491. background-color: #FFE4D0;
  492. color: #FF7800;
  493. margin-left: 30upx;
  494. padding: 10upx 32upx;
  495. border-radius: 28upx;
  496. border: 1upx solid #FF7800;
  497. font-size: 26upx;
  498. text-align: center;
  499. }
  500. .modelNumName {
  501. background-color: #F5F5F5;
  502. margin-left: 30upx;
  503. padding: 10upx 32upx;
  504. border-radius: 28upx;
  505. font-size: 26upx;
  506. }
  507. }
  508. }
  509. .goodsNum-box {
  510. padding: 30upx 30upx;
  511. width: 100%;
  512. padding-bottom: 200upx;
  513. .goodsNum{
  514. height: 50upx;
  515. text {
  516. display: inline-block;
  517. width: 50upx;
  518. height: 50upx;
  519. border: 1upx solid #999999;
  520. text-align: center;
  521. line-height: 50upx;
  522. }
  523. .subtract {
  524. border-right: 0upx;
  525. }
  526. .add {
  527. border-left: 0upx;
  528. }
  529. }
  530. }
  531. .bottom-line {
  532. border-bottom: 1upx solid #EDEDED;
  533. }
  534. .huabei-box {
  535. padding: 30upx 30upx;
  536. width: 690upx;
  537. .fenqi-box {
  538. margin-top: 15upx;
  539. width: 120%;
  540. .huabei-item {
  541. display: inline-block;
  542. background: #f3f3f3;
  543. padding: 16upx 24upx;
  544. margin: 5upx 10upx;
  545. border-radius: 15upx;
  546. text-align: center;
  547. font-size: 7upx;
  548. .huabei-period {
  549. display: block;
  550. }
  551. }
  552. .fenqi-on {
  553. border: 1px solid #EF7F93;
  554. color: #EF7F93;
  555. }
  556. .disabled {
  557. color: #cacaca;
  558. }
  559. }
  560. }
  561. .goosDetailbut-box {
  562. justify-content: center;
  563. .joinShopCartBut {
  564. width: 343upx;
  565. height: 80upx;
  566. border-radius: 40upx 0 0 40upx;
  567. background-color: #FFC300;
  568. color: #FFFEFE;
  569. font-size: 28upx;
  570. line-height: 80upx;
  571. text-align: center;
  572. margin-left: 30upx;
  573. }
  574. .buyNowBut {
  575. width: 343upx;
  576. height: 80upx;
  577. background-color: #333333;
  578. font-size: 28upx;
  579. line-height: 80upx;
  580. text-align: center;
  581. color: #FFEBC4;
  582. }
  583. .cancelBtn {
  584. background-color: #FFFFFF !important;
  585. border: 2rpx solid #333333;
  586. color: #333333;
  587. }
  588. }
  589. .btnBox {
  590. padding-bottom: 20rpx;
  591. }
  592. }
  593. </style>