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

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