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

539 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
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
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. // 不管有没有支付,都要清除购物车数据
  227. self.$api('cartDel', {
  228. id: deleteCartIds
  229. }, res => {
  230. if (res.code == 200) {
  231. self.getData()
  232. }
  233. })
  234. this.$api('orderPay', form, res => {
  235. if (res.code == 200) {
  236. uni.requestPayment({
  237. provider: 'wxpay', // 服务提提供商
  238. timeStamp: res.result.timeStamp, // 时间戳
  239. nonceStr: res.result.nonceStr, // 随机字符串
  240. package: res.result.packageValue,
  241. signType: res.result.signType, // 签名算法
  242. paySign: res.result.paySign, // 签名
  243. success: function(res) {
  244. console.log('支付成功', res);
  245. uni.redirectTo({
  246. url: '/pages/index/order'
  247. })
  248. },
  249. fail: function(err) {
  250. console.log('支付失败', err);
  251. // self.$refs.confirmationPopup.close()
  252. uni.showToast({
  253. icon: 'none',
  254. title: "支付失败"
  255. })
  256. }
  257. });
  258. }
  259. })
  260. }
  261. })
  262. },
  263. // 修改购物车里面商品的规格
  264. unitChange(item, e) {
  265. // TODO 查询商品规格
  266. // this.$api('goodsOne', this.queryParams, res => {
  267. // if (res.code == 200) {
  268. // this.list = res.result
  269. // }
  270. // })
  271. },
  272. // 获取地址列表
  273. getAddressListA() {
  274. this.$refs.addressList.getAddressList().then(res => {
  275. this.addressTotal = res.total
  276. if (this.addressTotal != 0) {
  277. this.address = res.records[0]
  278. }
  279. })
  280. },
  281. valChange(item, e) {
  282. console.log(e.value);
  283. this.$api('cartNum', {
  284. id: item.id,
  285. num: e.value,
  286. })
  287. },
  288. // 购物车分页
  289. getData() {
  290. this.$api('cartPage', this.queryParams, res => {
  291. if (res.code == 200) {
  292. this.list = res.result
  293. }
  294. })
  295. },
  296. // 删除购物车
  297. delCart(item, index) {
  298. this.$api('cartDel', {
  299. id: item.id
  300. }, res => {
  301. if (res.code == 200) {
  302. this.getData()
  303. uni.showToast({
  304. title: '删除成功',
  305. });
  306. }
  307. })
  308. },
  309. }
  310. }
  311. </script>
  312. <style scoped lang="scss">
  313. .page {
  314. /deep/ .uv-swipe-action {
  315. width: 100%;
  316. }
  317. }
  318. .user {
  319. .item {
  320. background-color: #fff;
  321. display: flex;
  322. padding: 30rpx;
  323. .checkbox {
  324. display: flex;
  325. justify-content: center;
  326. align-items: center;
  327. }
  328. .image {
  329. width: 200rpx;
  330. height: 200rpx;
  331. border-radius: 20rpx;
  332. }
  333. .info {
  334. flex: 1;
  335. .title {
  336. display: flex;
  337. padding: 10rpx 20rpx;
  338. justify-content: space-between;
  339. }
  340. .unit {
  341. font-size: 24rpx;
  342. padding: 10rpx 20rpx;
  343. color: #717171;
  344. display: flex;
  345. align-items: center;
  346. }
  347. .price {
  348. color: $uni-color;
  349. font-size: 28rpx;
  350. padding: 10rpx 20rpx;
  351. text {
  352. font-size: 36rpx;
  353. font-weight: 900;
  354. }
  355. }
  356. }
  357. }
  358. .action {
  359. width: 700rpx;
  360. position: fixed;
  361. bottom: 220rpx;
  362. left: 25rpx;
  363. background-color: #fff;
  364. height: 100rpx;
  365. border-radius: 50rpx;
  366. box-shadow: 0 0 6rpx 6rpx #00000010;
  367. display: flex;
  368. justify-content: center;
  369. align-items: center;
  370. overflow: hidden;
  371. .icon {
  372. position: relative;
  373. width: 80rpx;
  374. height: 80rpx;
  375. margin: 0 20rpx;
  376. image {
  377. width: 80rpx;
  378. height: 80rpx;
  379. }
  380. .num {
  381. position: absolute;
  382. right: 10rpx;
  383. top: 0rpx;
  384. background-color: $uni-color;
  385. color: #fff;
  386. font-size: 18rpx;
  387. border-radius: 50%;
  388. height: 30rpx;
  389. width: 30rpx;
  390. display: flex;
  391. justify-content: center;
  392. align-items: center;
  393. }
  394. }
  395. .price {
  396. .count {
  397. display: flex;
  398. font-size: 26rpx;
  399. align-items: center;
  400. view {
  401. color: $uni-color;
  402. margin-left: 10rpx;
  403. text {
  404. font-size: 32rpx;
  405. font-weight: 900;
  406. }
  407. }
  408. }
  409. .text {
  410. font-size: 20rpx;
  411. color: #717171;
  412. }
  413. }
  414. .btn {
  415. margin-left: auto;
  416. background-color: $uni-color;
  417. height: 100%;
  418. padding: 0 50rpx;
  419. color: #fff;
  420. display: flex;
  421. justify-content: center;
  422. align-items: center;
  423. }
  424. }
  425. }
  426. .example-body {
  427. padding: 12px;
  428. background-color: #FFFFFF;
  429. }
  430. .result-box {
  431. text-align: center;
  432. padding: 20px 0px;
  433. font-size: 16px;
  434. }
  435. .text {
  436. font-size: 12px;
  437. color: #666;
  438. margin-top: 5px;
  439. }
  440. .uni-px-5 {
  441. padding-left: 10px;
  442. padding-right: 10px;
  443. }
  444. .uni-pb-5 {
  445. padding-bottom: 10px;
  446. }
  447. .submit-unit {
  448. padding: 30rpx;
  449. background-color: #fff;
  450. .title {
  451. font-size: 28rpx;
  452. font-weight: 600;
  453. }
  454. .list {
  455. display: flex;
  456. flex-wrap: wrap;
  457. font-size: 22rpx;
  458. .act {
  459. color: $uni-color;
  460. border: 1px solid $uni-color;
  461. background-color: #F9E7DE;
  462. }
  463. view {
  464. border-radius: 15rpx;
  465. width: 320rpx;
  466. background-color: #F3F3F3;
  467. border: 1px solid #F3F3F3;
  468. margin: 10rpx;
  469. display: flex;
  470. justify-content: center;
  471. padding: 15rpx 0;
  472. }
  473. }
  474. }
  475. </style>