酒店桌布为微信小程序
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.

566 lines
11 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <template>
  2. <view class="page">
  3. <navbar />
  4. <view class="user">
  5. <uv-checkbox-group shape="circle" v-model="checkboxValue"
  6. v-if="list.records.length > 0">
  7. <uv-swipe-action>
  8. <view v-for="(item, index) in list.records" :key="index">
  9. <view style="margin-top: 20rpx;"></view>
  10. <uv-swipe-action-item :options="options" @click="delCart(item, index)">
  11. <view class="item" @click="selectItem(item)">
  12. <view class="checkbox">
  13. <uv-checkbox
  14. :name="item.id"
  15. activeColor="#FA5A0A"
  16. size="40rpx"
  17. @click.stop
  18. icon-size="35rpx"></uv-checkbox>
  19. </view>
  20. <image class="image"
  21. :src="item.pic || 'https://img95.699pic.com/photo/50058/1378.jpg_wh860.jpg'"
  22. mode=""></image>
  23. <view class="info">
  24. <view class="title">
  25. <view class="text-ellipsis"
  26. style="width: 220rpx;"
  27. >{{ item.name }}</view>
  28. <view style="flex-shrink: 0;">
  29. <uv-number-box v-model="item.num"
  30. @change="e => valChange(item, e)"></uv-number-box>
  31. </view>
  32. </view>
  33. <view class="unit" @click.stop="toggleDropdown(item)">
  34. 规格{{ item.title }}
  35. <uv-icon name="arrow-down"></uv-icon>
  36. </view>
  37. <view class="price">
  38. <text>{{ item.depositPrice }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. </uv-swipe-action-item>
  43. </view>
  44. </uv-swipe-action>
  45. </uv-checkbox-group>
  46. <uv-empty
  47. v-else
  48. text="空空如也"
  49. textSize="30rpx"
  50. iconSize="200rpx"
  51. icon="list"></uv-empty>
  52. <view class="action">
  53. <view class="icon">
  54. <image src="/static/image/cart/1.png" mode=""></image>
  55. <view class="num">{{ checkboxValue.length }}</view>
  56. </view>
  57. <view class="price">
  58. <view class="count">
  59. 合计
  60. <view>
  61. <text>{{ totalPrice }}</text>
  62. </view>
  63. </view>
  64. <view class="text">
  65. {{ checkboxValue.length }}已享受更低优惠
  66. </view>
  67. </view>
  68. <view class="btn" @click="goCleaning">去结算</view>
  69. </view>
  70. </view>
  71. <!-- 规格 -->
  72. <uv-popup ref="skuPopup" :round="30" closeable>
  73. <view class="submit-unit">
  74. <view class="title">
  75. 规格选择
  76. </view>
  77. <view class="list">
  78. <view :class="{act : unitIndex == index}" v-for="(item, index) in skuList"
  79. @click="selectUnit(item, index)" :key="index">
  80. {{ item.title }}
  81. <text v-if="item.colour">,{{ item.colour }}</text>
  82. </view>
  83. </view>
  84. </view>
  85. </uv-popup>
  86. <cartSubmitSelect
  87. @submit="ordersPay"
  88. :price="totalPrice"
  89. :depositPrice="totalPrice"
  90. :depositPriceList="depositPriceList"
  91. ref="cartSubmitSelect"/>
  92. <tabber select="3" />
  93. </view>
  94. </template>
  95. <script>
  96. import tabber from '@/components/base/tabbar.vue'
  97. import cartSubmitSelect from '@/components/user/cartSubmitSelect.vue'
  98. export default {
  99. components: {
  100. tabber,
  101. cartSubmitSelect
  102. },
  103. data() {
  104. return {
  105. queryParams: {
  106. pageNo: 1,
  107. pageSize: 10,
  108. },
  109. list: {
  110. records : [],
  111. },
  112. skuList: [],
  113. editSkuForm: {
  114. id: '', //购物车id
  115. goodsId: '', //商品id
  116. skuId: '', //规格id
  117. },
  118. value: 0,
  119. checkboxValue: [],
  120. options: [{
  121. text: '删除',
  122. style: {
  123. backgroundColor: '#FA5A0A'
  124. }
  125. }, ],
  126. unit: {},
  127. unitIndex: 0,
  128. }
  129. },
  130. computed: {
  131. totalPrice() {
  132. if (!this.checkboxValue.length) {
  133. return 0
  134. }
  135. let price = 0
  136. this.list.records.forEach(n => {
  137. if (this.checkboxValue.includes(n.id)) {
  138. price += n.depositPrice * n.num
  139. }
  140. })
  141. return price.toFixed(2)
  142. },
  143. depositPriceList(){
  144. if (!this.checkboxValue.length) {
  145. return []
  146. }
  147. let list = []
  148. this.list.records.forEach(n => {
  149. if (this.checkboxValue.includes(n.id)) {
  150. // price += n.depositPrice * n.num
  151. let len = list.length
  152. for(let i = 0;i < len;i++){
  153. let item = list[i]
  154. if(item.price == n.depositPrice){
  155. item.num += n.num
  156. return
  157. }
  158. }
  159. list.push({
  160. price : n.depositPrice,
  161. num : n.num,
  162. })
  163. }
  164. })
  165. return list
  166. },
  167. },
  168. onShow() {
  169. this.getData()
  170. },
  171. //滚动到屏幕底部
  172. onReachBottom() {
  173. if (this.queryParams.pageSize < this.list.total) {
  174. this.queryParams.pageSize += 10
  175. this.getData()
  176. }
  177. },
  178. methods: {
  179. // 选择物品
  180. selectItem(item){
  181. let index = this.checkboxValue.indexOf(item.id)
  182. if(index == -1){
  183. this.checkboxValue.push(item.id)
  184. return
  185. }
  186. this.checkboxValue.splice(index, 1)
  187. },
  188. // 修改商品规格弹框
  189. toggleDropdown(item) {
  190. this.editSkuForm.id = item.id
  191. this.editSkuForm.goodsId = item.goodsId
  192. // 根据商品id获取规格
  193. this.$api('goodsSku', {
  194. id: item.goodsId
  195. }, res => {
  196. if (res.code == 200) {
  197. this.skuList = res.result
  198. // 打开规格弹框
  199. this.$refs.skuPopup.open('bottom')
  200. }
  201. })
  202. },
  203. // 选择规格
  204. selectUnit(item, index) {
  205. this.unit = item
  206. this.unitIndex = index
  207. this.editSkuForm.skuId = item.id
  208. this.$api('editSku', this.editSkuForm, res => {
  209. if (res.code == 200) {
  210. this.$refs.skuPopup.close()
  211. this.getData()
  212. }
  213. })
  214. },
  215. // 去结算按钮
  216. goCleaning() {
  217. if (this.checkboxValue.length < 1) {
  218. uni.showToast({
  219. title: "请勾选商品",
  220. icon: 'none'
  221. })
  222. return
  223. }
  224. // 打开弹框
  225. this.$refs.cartSubmitSelect.open('bottom')
  226. },
  227. //商品下单
  228. ordersPay({ addressId, couponId }) {
  229. var self = this
  230. var deleteCartIds = this.checkboxValue.join(",") //待删除的购物车id
  231. let data = []
  232. let records = this.list.records
  233. for (var i = 0; i < records.length; i++) {
  234. if (this.checkboxValue.includes(records[i].id)) {
  235. data.push({
  236. id: records[i].goodsId, //商品id
  237. skuId: records[i].skuId, //规格id
  238. addressId, //地址id
  239. sku: records[i].title, //规格
  240. num: records[i].num,
  241. })
  242. }
  243. }
  244. this.$api('orderCreate', {
  245. req: JSON.stringify(data)
  246. }, res => {
  247. if (res.code == 200) {
  248. let form = {
  249. id: res.result.id
  250. }
  251. if(couponId){
  252. form.couponId = couponId
  253. }
  254. this.$api('orderPay', form, res => {
  255. if (res.code == 200) {
  256. uni.requestPayment({
  257. provider: 'wxpay', // 服务提提供商
  258. timeStamp: res.result.timeStamp, // 时间戳
  259. nonceStr: res.result.nonceStr, // 随机字符串
  260. package: res.result.packageValue,
  261. signType: res.result.signType, // 签名算法
  262. paySign: res.result.paySign, // 签名
  263. success: function(res) {
  264. console.log('支付成功', res);
  265. self.delsCart(deleteCartIds)
  266. uni.redirectTo({
  267. url: '/pages/index/order'
  268. })
  269. },
  270. fail: function(err) {
  271. self.delsCart(deleteCartIds)
  272. console.log('支付失败', err);
  273. uni.redirectTo({
  274. url:'/pages/index/order'
  275. })
  276. // self.$refs.confirmationPopup.close()
  277. uni.showToast({
  278. icon: 'none',
  279. title: "支付失败"
  280. })
  281. }
  282. });
  283. }
  284. })
  285. }
  286. })
  287. },
  288. valChange(item, e) {
  289. console.log(e.value);
  290. this.$api('cartNum', {
  291. id: item.id,
  292. num: e.value,
  293. })
  294. },
  295. // 购物车分页
  296. getData() {
  297. this.$api('cartPage', this.queryParams, res => {
  298. if (res.code == 200) {
  299. this.list = res.result
  300. }
  301. })
  302. },
  303. // 删除购物车
  304. delCart(item, index) {
  305. this.$api('cartDel', {
  306. id: item.id
  307. }, res => {
  308. if (res.code == 200) {
  309. this.getData()
  310. uni.showToast({
  311. title: '删除成功',
  312. });
  313. }
  314. })
  315. },
  316. //批量删除购物车
  317. delsCart(deleteCartIds){
  318. // 不管有没有支付,都要清除购物车数据
  319. this.$api('cartDel', {
  320. id: deleteCartIds
  321. }, res => {
  322. if (res.code == 200) {
  323. this.getData()
  324. }
  325. })
  326. },
  327. }
  328. }
  329. </script>
  330. <style scoped lang="scss">
  331. .page {
  332. padding-bottom: 200rpx;
  333. /deep/ .uv-swipe-action {
  334. width: 100%;
  335. }
  336. }
  337. .user {
  338. .item {
  339. background-color: #fff;
  340. display: flex;
  341. padding: 30rpx;
  342. .checkbox {
  343. display: flex;
  344. justify-content: center;
  345. align-items: center;
  346. flex-shrink: 0;
  347. }
  348. .image {
  349. width: 200rpx;
  350. height: 200rpx;
  351. border-radius: 20rpx;
  352. flex-shrink: 0;
  353. }
  354. .info {
  355. flex: 1;
  356. .title {
  357. display: flex;
  358. padding: 10rpx 20rpx;
  359. justify-content: space-between;
  360. .text-ellipsis{
  361. width: 280rpx;
  362. overflow: hidden; //超出的文本隐藏
  363. text-overflow: ellipsis; //溢出用省略号显示
  364. white-space: nowrap; //溢出不换行
  365. }
  366. }
  367. .unit {
  368. font-size: 24rpx;
  369. padding: 10rpx 20rpx;
  370. color: #717171;
  371. display: flex;
  372. align-items: center;
  373. }
  374. .price {
  375. color: $uni-color;
  376. font-size: 28rpx;
  377. padding: 10rpx 20rpx;
  378. text {
  379. font-size: 36rpx;
  380. font-weight: 900;
  381. }
  382. }
  383. }
  384. }
  385. .action {
  386. width: 700rpx;
  387. position: fixed;
  388. bottom: 220rpx;
  389. left: 25rpx;
  390. background-color: #fff;
  391. height: 100rpx;
  392. border-radius: 50rpx;
  393. box-shadow: 0 0 6rpx 6rpx #00000010;
  394. display: flex;
  395. justify-content: center;
  396. align-items: center;
  397. overflow: hidden;
  398. z-index: 99;
  399. .icon {
  400. position: relative;
  401. width: 80rpx;
  402. height: 80rpx;
  403. margin: 0 20rpx;
  404. image {
  405. width: 80rpx;
  406. height: 80rpx;
  407. }
  408. .num {
  409. position: absolute;
  410. right: 10rpx;
  411. top: 0rpx;
  412. background-color: $uni-color;
  413. color: #fff;
  414. font-size: 18rpx;
  415. border-radius: 50%;
  416. height: 30rpx;
  417. width: 30rpx;
  418. display: flex;
  419. justify-content: center;
  420. align-items: center;
  421. }
  422. }
  423. .price {
  424. .count {
  425. display: flex;
  426. font-size: 26rpx;
  427. align-items: center;
  428. view {
  429. color: $uni-color;
  430. margin-left: 10rpx;
  431. text {
  432. font-size: 32rpx;
  433. font-weight: 900;
  434. }
  435. }
  436. }
  437. .text {
  438. font-size: 20rpx;
  439. color: #717171;
  440. }
  441. }
  442. .btn {
  443. margin-left: auto;
  444. background-color: $uni-color;
  445. height: 100%;
  446. padding: 0 50rpx;
  447. color: #fff;
  448. display: flex;
  449. justify-content: center;
  450. align-items: center;
  451. }
  452. }
  453. }
  454. .example-body {
  455. padding: 12px;
  456. background-color: #FFFFFF;
  457. }
  458. .result-box {
  459. text-align: center;
  460. padding: 20px 0px;
  461. font-size: 16px;
  462. }
  463. .text {
  464. font-size: 12px;
  465. color: #666;
  466. margin-top: 5px;
  467. }
  468. .uni-px-5 {
  469. padding-left: 10px;
  470. padding-right: 10px;
  471. }
  472. .uni-pb-5 {
  473. padding-bottom: 10px;
  474. }
  475. .submit-unit {
  476. padding: 30rpx;
  477. background-color: #fff;
  478. height: 60vh;
  479. overflow: auto;
  480. .title {
  481. font-size: 28rpx;
  482. font-weight: 600;
  483. }
  484. .list {
  485. display: flex;
  486. flex-wrap: wrap;
  487. font-size: 22rpx;
  488. .act {
  489. color: $uni-color;
  490. border: 1px solid $uni-color;
  491. background-color: #F9E7DE;
  492. }
  493. view {
  494. border-radius: 15rpx;
  495. width: 320rpx;
  496. background-color: #F3F3F3;
  497. border: 1px solid #F3F3F3;
  498. margin: 10rpx;
  499. display: flex;
  500. justify-content: center;
  501. padding: 15rpx 0;
  502. }
  503. }
  504. }
  505. </style>