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

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