settleBottomBtn.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <view class="container">
  3. <view class="item-box" @click="handlerOpenPop">
  4. <view class="item-left">
  5. <image class="img" src="@/static/images/shopCarts.png"></image>
  6. <view class="edge-box">
  7. <u-badge class="edge" type="warning" max="99" :value="allNumb"></u-badge>
  8. </view>
  9. <view class="left-price">
  10. <p class="price">
  11. <span class="price-symbal">¥</span><span class="price-text1">{{ allPrice.price }}</span>
  12. <span class="price-text2">¥{{ allPrice.originalPrice }}</span>
  13. </p>
  14. </view>
  15. </view>
  16. <view class="item-right" @click.stop="handlerSettleBtn"> 去结算 </view>
  17. </view>
  18. <u-popup :show="pop_show" @close="pop_show = false" round='20' mode='bottom'>
  19. <view class="pop" v-for="(item,index) of goodsCateList" :key='index'>
  20. <view class="pop-box">
  21. <!-- <u-swipe-action> -->
  22. <!-- <u-swipe-action-item :options="options1"> -->
  23. <view class="pop-item">
  24. <view class="left">
  25. <view class="item-left">
  26. <image class="left-img" :src='item.goodsPic'></image>
  27. </view>
  28. <view class="item-right">
  29. <view class="right-name">{{ item.goodsName }}</view>
  30. <view class="right-price"> <span>¥</span> {{ item.price }}</view>
  31. </view>
  32. </view>
  33. <view class="right">
  34. <u-number-box v-model="item.quantity" @change="valChange(item,$event)"></u-number-box>
  35. <button class="btn" @click.stop="handlerService(item)">删除</button>
  36. </view>
  37. </view>
  38. <!-- </u-swipe-action-item> -->
  39. <!-- </u-swipe-action> -->
  40. </view>
  41. </view>
  42. </u-popup>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. addShoppingCart,
  48. editGoodsNumb,
  49. deleteCartItem
  50. } from '@/api/client/business.js';
  51. export default {
  52. data() {
  53. return {
  54. pop_show: false,
  55. // options1: [{
  56. // text: '删除'
  57. // }]
  58. }
  59. },
  60. props: {
  61. goodsCateList: {
  62. type: Array,
  63. default: []
  64. },
  65. ids: {
  66. type: String,
  67. default: ''
  68. }
  69. },
  70. watch: {
  71. goodsCateList(newValue) {
  72. if (newValue.length == 0) {
  73. this.pop_show = false
  74. }
  75. }
  76. },
  77. computed: {
  78. allPrice() {
  79. let price = 0
  80. let originalPrice = 0
  81. this.goodsCateList.map(rs => {
  82. price += Number(rs.price) * Number(rs.quantity)
  83. originalPrice += Number(rs.originalPrice) * Number(rs.quantity)
  84. })
  85. return {
  86. price,
  87. originalPrice
  88. }
  89. },
  90. allNumb() {
  91. let allNumber = 0
  92. this.goodsCateList.map(rs => {
  93. allNumber += Number(rs.quantity)
  94. })
  95. return allNumber
  96. }
  97. },
  98. methods: {
  99. // 点击打开pop
  100. handlerOpenPop() {
  101. if (!this.goodsCateList.length) {
  102. uni.showToast({
  103. title: '购物车商品为空',
  104. icon: 'none'
  105. })
  106. return
  107. } else {
  108. this.pop_show = true
  109. }
  110. },
  111. // 结算按钮
  112. handlerSettleBtn() {
  113. if (this.goodsCateList.length == 0) {
  114. uni.showToast({
  115. title: '请添加购物车',
  116. icon: 'none'
  117. })
  118. return
  119. } else {
  120. uni.navigateTo({
  121. url: `/pages/client/clientPackage/uptickOrder?ids=${this.ids}`
  122. })
  123. }
  124. },
  125. // 修改商品数量
  126. valChange(item, e) {
  127. editGoodsNumb(item.id, {
  128. quantity: e.value
  129. }).then(res => {
  130. console.log('@@@2res', res)
  131. })
  132. },
  133. // 点击删除按钮
  134. handlerService(item, e) {
  135. deleteCartItem(item.id).then(res => {
  136. if (res.code === 'OK') {
  137. uni.showToast({
  138. title: '删除成功',
  139. icon: 'none'
  140. })
  141. this.$emit("handlerDeleteGoods")
  142. } else {
  143. uni.showToast({
  144. title: res.message,
  145. icon: 'none'
  146. })
  147. return
  148. }
  149. })
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .container {
  156. .item-box {
  157. width: 90%;
  158. height: 80rpx;
  159. margin: 0 auto;
  160. display: flex;
  161. .item-left {
  162. background-color: #222426;
  163. width: 80%;
  164. border-radius: 40rpx 0 0 40rpx;
  165. display: flex;
  166. align-items: center;
  167. position: relative;
  168. .img {
  169. position: absolute;
  170. width: 130rpx;
  171. height: 130rpx;
  172. left: 9%;
  173. top: -70%;
  174. }
  175. .edge-box {
  176. position: absolute;
  177. left: 25%;
  178. top: -55%;
  179. }
  180. .left-price {
  181. margin-left: 30%;
  182. .price {
  183. color: #fff;
  184. font-size: 28rpx;
  185. font-weight: bold;
  186. .price-symbal {
  187. font-size: 28rpx;
  188. }
  189. .price-text1 {
  190. font-size: 34rpx;
  191. }
  192. .price-text2 {
  193. font-size: 24rpx;
  194. color: #999999;
  195. font-style: italic;
  196. text-decoration: line-through;
  197. }
  198. }
  199. }
  200. }
  201. .item-right {
  202. background-color: #FFE339;
  203. width: 20%;
  204. border-radius: 0 40rpx 40rpx 0;
  205. color: #000;
  206. font-size: 30rpx;
  207. font-weight: bold;
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. }
  212. }
  213. .pop {
  214. max-height: 700rpx;
  215. overflow-y: auto;
  216. }
  217. .pop-box {
  218. padding: 20rpx;
  219. .pop-item {
  220. padding: 20rpx;
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. margin-bottom: 20rpx;
  225. box-shadow: 0 5rpx 12rpx 0rpx rgba(0, 0, 0, 0.2);
  226. box-sizing: border-box;
  227. height: 100%;
  228. .left {
  229. display: flex;
  230. }
  231. .item-left {
  232. .left-img {
  233. width: 160rpx;
  234. height: 160rpx;
  235. border-radius: 20rpx;
  236. }
  237. }
  238. .item-right {
  239. margin-left: 20rpx;
  240. display: flex;
  241. flex-direction: column;
  242. justify-content: space-around;
  243. .right-name {
  244. font-size: 32rpx;
  245. font-weight: bold;
  246. }
  247. .right-price {
  248. color: #ff4b04;
  249. font-size: 30rpx;
  250. font-weight: bold;
  251. span {
  252. font-size: 24rpx;
  253. }
  254. }
  255. }
  256. .right {
  257. display: flex;
  258. flex-direction: column;
  259. justify-content: space-between;
  260. .btn {
  261. font-size: 26rpx;
  262. border-radius: 40rpx;
  263. border: 2rpx solid #ec5729;
  264. color: #ec5729;
  265. background-color: #fff;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. </style>