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

512 lines
10 KiB

9 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
9 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
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
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">
  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. padding-bottom: 200rpx;
  292. /deep/ .uv-swipe-action {
  293. width: 100%;
  294. }
  295. }
  296. .user {
  297. .item {
  298. background-color: #fff;
  299. display: flex;
  300. padding: 30rpx;
  301. .checkbox {
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. }
  306. .image {
  307. width: 200rpx;
  308. height: 200rpx;
  309. border-radius: 20rpx;
  310. }
  311. .info {
  312. flex: 1;
  313. .title {
  314. display: flex;
  315. padding: 10rpx 20rpx;
  316. justify-content: space-between;
  317. }
  318. .unit {
  319. font-size: 24rpx;
  320. padding: 10rpx 20rpx;
  321. color: #717171;
  322. display: flex;
  323. align-items: center;
  324. }
  325. .price {
  326. color: $uni-color;
  327. font-size: 28rpx;
  328. padding: 10rpx 20rpx;
  329. text {
  330. font-size: 36rpx;
  331. font-weight: 900;
  332. }
  333. }
  334. }
  335. }
  336. .action {
  337. width: 700rpx;
  338. position: fixed;
  339. bottom: 220rpx;
  340. left: 25rpx;
  341. background-color: #fff;
  342. height: 100rpx;
  343. border-radius: 50rpx;
  344. box-shadow: 0 0 6rpx 6rpx #00000010;
  345. display: flex;
  346. justify-content: center;
  347. align-items: center;
  348. overflow: hidden;
  349. z-index: 99;
  350. .icon {
  351. position: relative;
  352. width: 80rpx;
  353. height: 80rpx;
  354. margin: 0 20rpx;
  355. image {
  356. width: 80rpx;
  357. height: 80rpx;
  358. }
  359. .num {
  360. position: absolute;
  361. right: 10rpx;
  362. top: 0rpx;
  363. background-color: $uni-color;
  364. color: #fff;
  365. font-size: 18rpx;
  366. border-radius: 50%;
  367. height: 30rpx;
  368. width: 30rpx;
  369. display: flex;
  370. justify-content: center;
  371. align-items: center;
  372. }
  373. }
  374. .price {
  375. .count {
  376. display: flex;
  377. font-size: 26rpx;
  378. align-items: center;
  379. view {
  380. color: $uni-color;
  381. margin-left: 10rpx;
  382. text {
  383. font-size: 32rpx;
  384. font-weight: 900;
  385. }
  386. }
  387. }
  388. .text {
  389. font-size: 20rpx;
  390. color: #717171;
  391. }
  392. }
  393. .btn {
  394. margin-left: auto;
  395. background-color: $uni-color;
  396. height: 100%;
  397. padding: 0 50rpx;
  398. color: #fff;
  399. display: flex;
  400. justify-content: center;
  401. align-items: center;
  402. }
  403. }
  404. }
  405. .example-body {
  406. padding: 12px;
  407. background-color: #FFFFFF;
  408. }
  409. .result-box {
  410. text-align: center;
  411. padding: 20px 0px;
  412. font-size: 16px;
  413. }
  414. .text {
  415. font-size: 12px;
  416. color: #666;
  417. margin-top: 5px;
  418. }
  419. .uni-px-5 {
  420. padding-left: 10px;
  421. padding-right: 10px;
  422. }
  423. .uni-pb-5 {
  424. padding-bottom: 10px;
  425. }
  426. .submit-unit {
  427. padding: 30rpx;
  428. background-color: #fff;
  429. height: 60vh;
  430. overflow: auto;
  431. .title {
  432. font-size: 28rpx;
  433. font-weight: 600;
  434. }
  435. .list {
  436. display: flex;
  437. flex-wrap: wrap;
  438. font-size: 22rpx;
  439. .act {
  440. color: $uni-color;
  441. border: 1px solid $uni-color;
  442. background-color: #F9E7DE;
  443. }
  444. view {
  445. border-radius: 15rpx;
  446. width: 320rpx;
  447. background-color: #F3F3F3;
  448. border: 1px solid #F3F3F3;
  449. margin: 10rpx;
  450. display: flex;
  451. justify-content: center;
  452. padding: 15rpx 0;
  453. }
  454. }
  455. }
  456. </style>