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

611 lines
12 KiB

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