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

510 lines
9.9 KiB

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