shop-car.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="shop-car">
  3. <custom-nav ref="ltm" :title="title" />
  4. <view class="content">
  5. <view v-if="shopcar.length" class="list">
  6. <view class="shopcar-item" v-for="(item, index) in shopcarList" :key="index">
  7. <view class="info item" @tap="tapGood(index)">
  8. <text v-if="item.choosed" class="cuIcon-roundcheckfill"></text>
  9. <text v-else class="cuIcon-round"></text>
  10. <image :src="item.img" mode=""></image>
  11. <view class="name ellipsis">{{ item.name }}</view>
  12. <text class="cuIcon-delete" @tap.stop="delGood(index)"></text>
  13. </view>
  14. <view class="type" v-for="(tyepItem, typeIndex) in item.typeList" :key="typeIndex">
  15. <view class="item type-size-counter"
  16. v-for="(value, key) in tyepItem.size" :key="key"
  17. v-if="shopcarList[index].typeList[typeIndex].size[key]"
  18. >
  19. <text v-if="shopcarList[index].typeList[typeIndex].choosed[key]" class="cuIcon-roundcheckfill" @tap="tapType(index, typeIndex, key)"></text>
  20. <text v-else class="cuIcon-round" @tap="tapType(index, typeIndex, key)"></text>
  21. <view class="type-size" @tap="tapType(index, typeIndex, key)">
  22. <text>款式:{{ tyepItem.name }} 尺码: {{ key }}</text>
  23. <text class="cost">¥{{ item.price * value }}.00</text>
  24. </view>
  25. <custom-counter zeroWarn :value="shopcarList[index].typeList[typeIndex].size[key]"
  26. :args="[index, typeIndex, key]" @change="counterChange" @zero="isZero"
  27. />
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view v-else class="none">
  33. <image src="../../static/icon/emptyshopcar.png"></image>
  34. <view class="big-btn" @tap="goToBuy">去下单</view>
  35. </view>
  36. </view>
  37. <view class="buy">
  38. <view class="all" @tap="chooseAll">
  39. <text v-if="choosedAll" class="cuIcon-roundcheckfill"></text>
  40. <text v-else class="cuIcon-round"></text>
  41. <text>全选</text>
  42. </view>
  43. <view class="total">总计: <text>{{ '¥ ' + choosedPrice + '.00' }}</text></view>
  44. <view class="pay" @tap="confirm">结算({{ ' ' + choosedNum + ' ' }})</view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import customCounter from '../../components/public/custom-counter.vue'
  50. export default {
  51. components: { customCounter },
  52. data() {
  53. return {
  54. title: '购物车',
  55. shopcarList: []
  56. }
  57. },
  58. computed: {
  59. shopcar() { return this.$store.state.shopcar.list },
  60. choosedNum() { return this.$store.getters['shopcar/choosedNum'] },
  61. choosedAll() { return this.$store.getters['shopcar/choosedAll'] },
  62. choosedList() { return this.$store.getters['shopcar/choosedList'] },
  63. choosedPrice() { return this.$store.getters['shopcar/choosedPrice'] }
  64. },
  65. created() {
  66. this.shopcarList = this.shopcar
  67. },
  68. methods: {
  69. delGood(index) { // 删除商品
  70. this.$refs.ltm.modal('提示', ['确定删除这种商品?']).then(() => {
  71. this.$store.commit('shopcar/DEL', index)
  72. this.$refs.ltm.toast('删除成功')
  73. }).catch(() => {
  74. this.$refs.ltm.toast('取消删除')
  75. })
  76. },
  77. chooseAll() { // 点击全选
  78. this.$store.commit('shopcar/CHOOSEDCHANGE', [])
  79. },
  80. tapGood(index) { // 点击商品
  81. this.$store.commit('shopcar/CHOOSEDCHANGE', [index])
  82. },
  83. tapType(index, typeIndex, key) { // 点击类型
  84. this.$store.commit('shopcar/CHOOSEDCHANGE', [index, typeIndex, key])
  85. },
  86. counterChange(value, index, typeIndex, key) { // 类型数量变化
  87. this.$store.commit('shopcar/COUNTCHANGE', [index, typeIndex, key, value])
  88. },
  89. isZero(eventBUS, ...args) { // 当类型数量变为 0 时
  90. this.$refs.ltm.modal('提示', ['确定删除这个尺码', `款式:${ this.shopcar[args[0]].typeList[args[1]].name }`, `尺码: ${ args[2] }`]).then(() => {
  91. eventBUS.$emit('beZero')
  92. }).catch(() => {
  93. eventBUS.$emit('beOne')
  94. })
  95. },
  96. confirm() { // 点击结算
  97. if (this.choosedNum) {
  98. uni.navigateTo({ url: `../confirm-order/confirm-order?from=shopcar&order=${JSON.stringify(this.choosedList)}` })
  99. }
  100. },
  101. goToBuy() { // 点击去下单
  102. uni.navigateBack({ delta: 2 })
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss">
  108. .shop-car {
  109. @include page();
  110. .content {
  111. overflow: auto;
  112. border-bottom: 98rpx solid #FFFFFF;
  113. .shopcar-item {
  114. margin-bottom: 10rpx;
  115. .item {
  116. @include flex();
  117. height: 100rpx;
  118. font-size: 26rpx;
  119. padding-right: 30rpx;
  120. margin-bottom: 2rpx;
  121. background: #FFFFFF;
  122. box-sizing: border-box;
  123. justify-content: flex-start;
  124. &.info {
  125. height: 180rpx;
  126. image {
  127. width: 140rpx;
  128. height: 140rpx;
  129. margin-right: 30rpx;
  130. }
  131. .name {
  132. flex: 1;
  133. }
  134. .cuIcon-delete{
  135. @include flex();
  136. width: 140rpx;
  137. height: 140rpx;
  138. font-size: 56rpx;
  139. color: $app-sec-text-color;
  140. }
  141. }
  142. &.type-size-counter {
  143. .type-size {
  144. @include flex(column);
  145. flex: 1;
  146. height: 100%;
  147. margin-right: 30rpx;
  148. text {
  149. @include flex();
  150. flex: 1;
  151. width: 100%;
  152. justify-content: space-between;
  153. &.cost {
  154. color: $app-base-color;
  155. }
  156. }
  157. }
  158. }
  159. .cuIcon-round, .cuIcon-roundcheckfill {
  160. @include flex();
  161. width: 90rpx;
  162. height: 100%;
  163. font-size: 32rpx;
  164. &.cuIcon-roundcheckfill {
  165. color: $app-base-color;
  166. }
  167. }
  168. }
  169. }
  170. .none {
  171. @include flex(column);
  172. height: 100%;
  173. image {
  174. width: 305rpx;
  175. height: 417rpx;
  176. }
  177. .big-btn {
  178. width: 280rpx;
  179. height: 80rpx;
  180. margin-top: 123rpx;
  181. border-radius: 40rpx;
  182. }
  183. }
  184. }
  185. .buy {
  186. @include flex();
  187. position: fixed;
  188. left: 0;
  189. right: 0;
  190. bottom: 0;
  191. z-index: 1;
  192. height: 98rpx;
  193. font-size: 32rpx;
  194. background: #FFFFFF;
  195. justify-content: space-between;
  196. box-shadow: 0rpx -1rpx 0rpx 0rpx rgba(178,178,178,1);
  197. view {
  198. @include flex();
  199. height: 100%;
  200. &.all {
  201. font-size: 32rpx;
  202. text {
  203. margin-left: 30rpx;
  204. &.cuIcon-roundcheckfill {
  205. color: $app-base-color;
  206. }
  207. }
  208. }
  209. &.total {
  210. flex: 1;
  211. margin-right: 30rpx;
  212. justify-content: flex-end;
  213. text {
  214. color: $app-base-color;
  215. }
  216. }
  217. &.pay {
  218. width: 220rpx;
  219. color: #FFFFFF;
  220. background: $app-base-color;
  221. }
  222. }
  223. }
  224. }
  225. </style>