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

469 lines
10 KiB

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