index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view>
  3. <view>
  4. <view class="store-list y-p-30">
  5. <view class="bg-white store-single y-p-30 y-m-b-30 y-radius-30" v-for="(storeItem, storeIndex) in shoppingCart" :key="storeIndex">
  6. <view @click="storeSelBtn(storeIndex)" class="store-header y-flex y-align-center">
  7. <view class="sel-btn y-p-t-5">
  8. <u-icon v-if="(storeItem.isBuySelect && !isEdit) || (storeItem.isDelSelect && isEdit)" name="checkmark-circle-fill" color="#04BE02" size="40rpx"></u-icon>
  9. <view v-else class="no-select"></view>
  10. </view>
  11. <span class="y-font-size-30 y-m-l-13 y-m-r-10">{{storeItem.shopName}}</span>
  12. <u-icon name="arrow-right"></u-icon>
  13. </view>
  14. <view class="goods-list y-p-l-20">
  15. <view class="goods-item y-flex y-p-t-20" v-for="(goodsItem, goodsIndex) in storeItem.orderGoodsList" :key="goodsIndex">
  16. <view @click="goodsSelBtn(storeIndex, goodsIndex)" class="y-flex y-align-center">
  17. <view class="sel-btn">
  18. <u-icon v-if="(goodsItem.isBuySelect && !isEdit) || (goodsItem.isDelSelect && isEdit)" name="checkmark-circle-fill" color="#04BE02" size="40rpx"></u-icon>
  19. <view v-else class="no-select"></view>
  20. </view>
  21. </view>
  22. <view class="y-m-l-15">
  23. <u-image :src="goodsItem.goodsPicture[0]" radius="10rpx" width="162rpx" height="162rpx"></u-image>
  24. </view>
  25. <view class="y-m-l-28 y-flex y-flex-1 y-flex-column">
  26. <view class="y-flex-1">
  27. <view class="goods-name y-font-size-28"> {{goodsItem.goodsName}} </view>
  28. <view class="goods-attr y-flex y-m-t-15">
  29. {{goodsItem.skuMessage}}
  30. <!-- <u-tag v-if="goodsItem.skuMessage.length > 0" :text="goodsItem.skuMessage.join(';')" plain size="mini" type="warning"></u-tag> -->
  31. <!-- <u-tag v-else text="默认规格" plain size="mini" type="warning"></u-tag> -->
  32. </view>
  33. </view>
  34. <view class="goods-price y-flex y-align-end y-flex-1">
  35. <view class="y-flex-1 y-font-size-30 y-weight-bold color-price"> ¥ {{goodsItem.goodsPrice}} </view>
  36. <view class="flex align-center">
  37. <image @click="updataNum(storeItem,goodsItem,2)" src="../static/shoppingCar/jian.png" style="width: 54rpx;height: 54rpx;" mode=""></image>
  38. <view class="padding-lr-sm">{{goodsItem.goodsNum}}</view>
  39. <image @click="updataNum(storeItem,goodsItem,1)" src="../static/shoppingCar/add.png" style="width: 49rpx;height: 49rpx;" mode=""></image>
  40. <!-- <u-number-box size="18" v-model="goodsItem.goodsNum" @change="countChange(storeIndex, goodsIndex)"></u-number-box> -->
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <view style="height: 120rpx;"></view>
  49. </view>
  50. <view class="y-position-fixed y-bottom-0 y-left-0 y-right-0 y-p-y-20 y-p-x-30 bg-white y-flex">
  51. <view class="y-flex y-flex-1 y-align-center">
  52. <view @click="allSelBtn()" class="store-header y-flex y-align-center">
  53. <view class="sel-btn y-p-t-5">
  54. <u-icon v-if="allSelState" name="checkmark-circle-fill" color="#04BE02" size="40rpx"></u-icon>
  55. <view v-else class="no-select"></view>
  56. </view>
  57. <span class="y-font-size-28 y-m-l-10">全选</span>
  58. </view>
  59. </view>
  60. <view class="y-flex y-align-center y-font-size-28">
  61. <view v-if="!isEdit" class="y-font-size-33"> 总计: <span class="color-price y-weight-bold y-m-l-8">¥ {{totalPrice}} </span> </view>
  62. <view class="y-flex y-m-l-25">
  63. <u-button v-if="!isEdit" shape="circle" :hairline="false" :customStyle="submitBtnStyle"> 结算( {{totalSelCount}} ) </u-button>
  64. <u-button v-else shape="circle" :hairline="false" :customStyle="submitBtnStyle"> 删除( {{totalSelCount}} ) </u-button>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. export default {
  72. data() {
  73. return {
  74. isEdit: false, //是否编辑(购物/编辑)
  75. shoppingCart: [],//购物车数据
  76. submitBtnStyle: {
  77. background: '#FD7026',
  78. color: '#ffffff',
  79. border: 'none'
  80. },//结算、删除按钮的样式
  81. page: 1,
  82. limit: 10,
  83. }
  84. },
  85. computed:{
  86. //是否已经全部选中
  87. allSelState(){
  88. let buyAllSelect = true // 购物全选
  89. let delAllSelect = true // 编辑全选
  90. this.shoppingCart.forEach(sitem=>{
  91. sitem.orderGoodsList.forEach(gitem=>{
  92. if(!gitem.isBuySelect) buyAllSelect = false;
  93. if(!gitem.isDelSelect) delAllSelect = false;
  94. })
  95. })
  96. if(!this.isEdit) return buyAllSelect;
  97. else return delAllSelect;
  98. },
  99. //总价格
  100. totalPrice(){
  101. let totalPrice = 0
  102. this.shoppingCart.forEach(sitem=>{
  103. sitem.orderGoodsList.forEach(gitem=>{
  104. if(gitem.isBuySelect){
  105. totalPrice = totalPrice*1 + gitem.goodsPrice*gitem.goodsNum
  106. }
  107. })
  108. })
  109. return totalPrice
  110. },
  111. //当前操作下选中的数量
  112. totalSelCount(){
  113. let buyCount = 0 // 购物全选
  114. let delCount = 0 // 编辑全选
  115. this.shoppingCart.forEach(sitem=>{
  116. sitem.orderGoodsList.forEach(gitem=>{
  117. if(gitem.isBuySelect){
  118. buyCount = buyCount*1 + gitem.goodsNum
  119. }
  120. if(gitem.isDelSelect){
  121. delCount = delCount*1 + 1
  122. }
  123. })
  124. })
  125. if(!this.isEdit){
  126. return buyCount
  127. } else{
  128. return delCount
  129. }
  130. }
  131. },
  132. onLoad() {
  133. this.getData()
  134. },
  135. methods: {
  136. // 结算
  137. goConfirm() {
  138. if (this.shoppingCart && this.goodsList.orderGoodsList[0].length > 0) {
  139. uni.navigateTo({
  140. url: '/pages/diancan/confirmOrder?shopId=' + this.shop.shopId + '&orderType=' + this
  141. .orderType
  142. })
  143. } else {
  144. uni.showToast({
  145. title: '请先添加商品',
  146. icon: "none"
  147. })
  148. }
  149. },
  150. //获取购物车列表
  151. getData(){
  152. let data = {
  153. // page: 1,
  154. // limit: 10
  155. }
  156. this.$Request.get("/app/order/selectShoppingTrolley", data).then(res => {
  157. if (res.code == 0&&res.data) {
  158. res.data.forEach(res=>{
  159. res.isDelSelect = false
  160. res.isBuySelect = false
  161. res.orderGoodsList.forEach(ret=>{
  162. ret.goodsPicture = ret.goodsPicture.split(',')
  163. ret.isDelSelect = false
  164. ret.isBuySelect = false
  165. })
  166. })
  167. if(this.page == 1) {
  168. this.shoppingCart = res.data
  169. } else {
  170. this.shoppingCart = [...this.shoppingCart, ...res.data]
  171. }
  172. }
  173. });
  174. },
  175. //商家的选中与否
  176. storeSelBtn(storeIndex){
  177. if(!this.isEdit){ //购物
  178. this.shoppingCart[storeIndex].isBuySelect = !this.shoppingCart[storeIndex].isBuySelect
  179. this.shoppingCart[storeIndex].orderGoodsList.forEach(item=>{
  180. item.isBuySelect = this.shoppingCart[storeIndex].isBuySelect
  181. })
  182. }else{//编辑
  183. this.shoppingCart[storeIndex].isDelSelect = !this.shoppingCart[storeIndex].isDelSelect
  184. this.shoppingCart[storeIndex].orderGoodsList.forEach(item=>{
  185. item.isDelSelect = this.shoppingCart[storeIndex].isDelSelect
  186. })
  187. }
  188. },
  189. //商品的选中与否
  190. goodsSelBtn(storeIndex, goodsIndex){
  191. if(!this.isEdit){ //购物
  192. this.shoppingCart[storeIndex].orderGoodsList[goodsIndex].isBuySelect = !this.shoppingCart[storeIndex].orderGoodsList[goodsIndex].isBuySelect
  193. let allIsSel = true //是否已经全部选中
  194. this.shoppingCart[storeIndex].orderGoodsList.forEach(item=>{
  195. if(!item.isBuySelect){
  196. allIsSel = false
  197. }
  198. })
  199. this.shoppingCart[storeIndex].isBuySelect = allIsSel
  200. }else{//编辑
  201. this.shoppingCart[storeIndex].orderGoodsList[goodsIndex].isDelSelect = !this.shoppingCart[storeIndex].orderGoodsList[goodsIndex].isDelSelect
  202. let allIsSel = true //是否已经全部选中
  203. this.shoppingCart[storeIndex].orderGoodsList.forEach(item=>{
  204. if(!item.isDelSelect){
  205. allIsSel = false
  206. }
  207. })
  208. this.shoppingCart[storeIndex].isDelSelect = allIsSel
  209. }
  210. },
  211. //全选
  212. allSelBtn(){
  213. let toState = !this.allSelState
  214. if(!this.isEdit){//购物
  215. this.shoppingCart.forEach(sitem=>{
  216. sitem.isBuySelect = toState
  217. sitem.orderGoodsList.forEach(gitem=>{
  218. gitem.isBuySelect = toState
  219. })
  220. })
  221. }else{//编辑
  222. this.shoppingCart.forEach(sitem=>{
  223. sitem.isDelSelect = toState
  224. sitem.orderGoodsList.forEach(gitem=>{
  225. gitem.isDelSelect = toState
  226. })
  227. })
  228. }
  229. },
  230. //商品的数量增减
  231. countChange(storeIndex, goodsIndex){
  232. //请求后台改变购物车商品的数量。。。storeIndex, goodsIndex
  233. },
  234. updataNum(storeItem,goodsItem,type) {
  235. let data = {
  236. orderGoodsId: goodsItem.id,
  237. type: type,
  238. num: 1,
  239. shopId: storeItem.shopId
  240. }
  241. this.$Request.get("/app/order/updateGoodsNum", data).then(res => {
  242. if (res.code == 0) {
  243. this.getData()
  244. }
  245. });
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .w-90{
  252. width: 90rpx;
  253. }
  254. .sel-btn{
  255. width: 45rpx;
  256. height: 45rpx;
  257. }
  258. .no-select{
  259. width: 39rpx;
  260. height: 39rpx;
  261. border-radius: 50%;
  262. border: 1px solid rgb(235, 236, 238);
  263. }
  264. .y-position-fixed{
  265. position: fixed;
  266. }
  267. .y-top-0{
  268. top: 0;
  269. }
  270. .y-bottom-0{
  271. bottom: 0;
  272. }
  273. .y-left-0{
  274. left: 0;
  275. }
  276. .y-right-0{
  277. right: 0;
  278. }
  279. .y-flex-column{
  280. flex-direction: column !important;
  281. }
  282. .y-w-100{
  283. width: 100%;
  284. }
  285. /*系统状态栏高度*/
  286. .y-system-height{
  287. height: var(--status-bar-height);
  288. }
  289. /* 圆角大小例:radius-1 ,radius-10... */
  290. @for $i from 1 through 50 {
  291. .y-radius-#{$i} { border-radius: $i*1rpx;}
  292. /* margin */
  293. .y-m-t-#{$i} { margin-top: $i*1rpx; }
  294. .y-m-b-#{$i} { margin-bottom: $i*1rpx; }
  295. .y-m-l-#{$i} { margin-left: $i*1rpx; }
  296. .y-m-r-#{$i} { margin-right: $i*1rpx; }
  297. .y-m-x-#{$i} { margin-left: $i*1rpx; margin-right: $i*1rpx; }
  298. .y-m-y-#{$i} { margin-top: $i*1rpx; margin-bottom: $i*1rpx; }
  299. .y-m-#{$i} { margin: $i*1rpx; }
  300. /* padding */
  301. .y-p-t-#{$i} { padding-top: $i*1rpx; }
  302. .y-p-b-#{$i} { padding-bottom: $i*1rpx; }
  303. .y-p-l-#{$i} { padding-left: $i*1rpx; }
  304. .y-p-r-#{$i} { padding-right: $i*1rpx; }
  305. .y-p-x-#{$i} { padding-left: $i*1rpx; padding-right: $i*1rpx; }
  306. .y-p-y-#{$i} { padding-top: $i*1rpx; padding-bottom: $i*1rpx; }
  307. .y-p-#{$i} { padding: $i*1rpx; }
  308. /* font-size */
  309. .y-font-size-#{$i} { font-size: $i*1rpx; }
  310. }
  311. /* 自体加粗例:weight-100 ,weight-150 ,weight-600... */
  312. @for $i from 1 through 9 {
  313. .y-weight-#{$i*100} { font-weight: $i*100;}
  314. .y-weight-#{$i*100 + 50} { font-weight: 50 + $i*100;}
  315. }
  316. .y-justify-end{
  317. justify-content: flex-end;
  318. }
  319. .y-align-center{
  320. align-items: center;
  321. }
  322. .y-align-start{
  323. align-items: flex-start;
  324. }
  325. .y-align-end{
  326. align-items: flex-end;
  327. }
  328. .y-flex{
  329. display: flex;
  330. }
  331. .y-flex-column{
  332. flex-direction: column;
  333. }
  334. .y-flex-1{
  335. flex: 1;
  336. }
  337. .y-justify-start{
  338. justify-content: flex-start;
  339. }
  340. .y-justify-end{
  341. justify-content: flex-end;
  342. }
  343. .y-justify-around{
  344. justify-content: space-around;
  345. }
  346. .y-justify-between{
  347. justify-content: space-between;
  348. }
  349. .y-weight-bold{
  350. font-weight: bold;
  351. }
  352. .y-border-bottom {
  353. border-bottom: 1rpx solid rgba($color: #707070, $alpha: 0.12);
  354. }
  355. .color-price{
  356. color: #C8222A;
  357. }
  358. </style>