index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="requestList">
  3. <!-- header -->
  4. <cu-custom custom bgColor="bg-gradual-blue"><view slot="content">购物车</view></cu-custom>
  5. <view class="setting">
  6. <view class="setting-content flex align-center justify-center padding-sm bg-white">
  7. <view @click="addressListFunc" class="left text-cut text-grey"><text class="cuIcon-locationfill text-green"></text>配送至河南省郑州市高新区大学科技园配送至河南省郑州市高新区大学科技园</view>
  8. <view @click="status = !status" class="right margin-left">{{ status ? '完成' : '管理' }}</view>
  9. </view>
  10. </view>
  11. <!-- section -->
  12. <cu-scrollView @refresherpulling="refresherpulling" @scroll="scroll" :height="height">
  13. <view class="section">
  14. <checkbox-group :value="group" @change="chooseShop">
  15. <view v-for="(item, index) in ListValue" :key="index" class="item flex align-center bg-white radius padding">
  16. <checkbox :value="item.id" :checked="group.some(it=>it==item.id)" style="transform: scale(0.6);" />
  17. <view class="right flex margin-left">
  18. <view
  19. @click="detailFunc(item.commodity_details)"
  20. :style="{ backgroundImage: 'url(' + item.image + ')' }"
  21. class="image radius margin-right-sm"
  22. ></view>
  23. <view class="right-right">
  24. <view class="text-black">{{ item.name }}</view>
  25. <view class="flex justify-between margin-top-xs margin-bottom-sm">
  26. <view class="text-red text-price">
  27. <cu-price :value="item.price"/>
  28. </view>
  29. <view>{{item.point_price}}积分</view>
  30. </view>
  31. <view style="float: right;"><cu-stepper @change="val=>changeNum(index,val)" :value="item.quantity" /></view>
  32. </view>
  33. </view>
  34. </view>
  35. </checkbox-group>
  36. <!-- 状态管理 -->
  37. <view class="cu-load" :class="{ loading: currentPage <= totalPage, over: currentPage > totalPage }"></view>
  38. </view>
  39. </cu-scrollView>
  40. <!-- footer -->
  41. <view class="tool">
  42. <!-- 结算 -->
  43. <view v-if="!status" class="bg-white tool-contentA flex align-center justify-center padding-lr padding-tb-sm">
  44. <view class="left flex align-center">
  45. <checkbox-group @change="totalFunc('total_lockA')" class="margin-right flex align-center">
  46. <checkbox :checked="total_lockA" style="transform: scale(0.6);" />
  47. <text class="text-lg margin-left-sm">全选</text>
  48. </checkbox-group>
  49. <view class="text-red margin-left">
  50. 合计:
  51. <cu-price :value="price" size="52" />
  52. <text class="margin-left-sm text-grey left">{{point_price}}积分</text>
  53. </view>
  54. </view>
  55. <view class="right"><button :disabled="bind!=1" @click="payFunc" class="cu-btn bg-red round shadow-blur">结算</button></view>
  56. </view>
  57. <!-- 管理 -->
  58. <view v-else class="bg-white tool-contentA flex align-center justify-center padding-lr padding-tb-sm">
  59. <view class="left flex ">
  60. <checkbox-group @change="totalFunc('total_lockB')" class="margin-right flex align-center">
  61. <checkbox :checked="total_lockB" style="transform: scale(0.6);" />
  62. <text class="text-lg margin-left-sm">全选</text>
  63. </checkbox-group>
  64. </view>
  65. <view class="right">
  66. <button :disabled="bind!=1" class="cu-btn bg-red round shadow-blur margin-right">删除</button>
  67. <button :disabled="bind!=1" class="cu-btn bg-green round shadow-blur">移入收藏</button>
  68. </view>
  69. </view>
  70. </view>
  71. <cu-bar active="3" />
  72. </view>
  73. </template>
  74. <script>
  75. import { CustomBarHeight } from '@/common/device/index.js';
  76. import { mapState, mapActions ,mapMutations} from 'vuex';
  77. import api from "./api.js";
  78. export default {
  79. data() {
  80. return {
  81. status: false, // false 结算 true 管理
  82. total_lockA: false, //购买 全选
  83. total_lockB: false, //管理 全选
  84. price: 0, //合计
  85. point_price:0,//积分
  86. group: []
  87. };
  88. },
  89. computed: {
  90. ...mapState(['bind']),
  91. ...mapState('requestList', ['ListValue', 'currentPage', 'totalPage']),
  92. height() {
  93. return `calc(100vh - 280rpx - ${CustomBarHeight}px)`;
  94. }
  95. },
  96. onLoad() {},
  97. async onShow() {
  98. await this.reset();
  99. await this.requestFunc({ method: 'get', url: `/customer/order/cart/`, data: { limit: 10 } });
  100. },
  101. methods: {
  102. ...mapMutations('requestList',['changeValue']),
  103. ...mapActions('requestList', ['reset','requestFunc']),
  104. totalFunc(type){
  105. let totalStutas=!this[type];
  106. let group=[];
  107. if(totalStutas) this.ListValue.forEach(item=>group.push(item.id));
  108. this.group=group;
  109. this[type]=totalStutas;
  110. },
  111. addressListFunc(){
  112. uni.navigateTo({
  113. url:"/loginPages/addressList/index"
  114. })
  115. },
  116. //合计
  117. computer(){
  118. let point_price=0,price=0;
  119. if(!this.status && this.group.length>0) this.ListValue.forEach(item=>{
  120. if(this.group.findIndex(it=>it==item.id)!=-1){
  121. point_price+=item.point_price*1*item.quantity;
  122. price+=item.price*1*item.quantity;
  123. }
  124. })
  125. this.point_price=point_price;
  126. this.price=price;
  127. },
  128. detailFunc(id){
  129. uni.navigateTo({
  130. url:`/pages/detail/index?id=${id}`
  131. })
  132. },
  133. chooseShop(e) {
  134. let {value}=e.detail;
  135. if(value.length==this.ListValue.length) {
  136. if(this.status){
  137. this.total_lockB=true;
  138. }else{
  139. this.total_lockA=true;
  140. }
  141. }else{
  142. if(this.status){
  143. this.total_lockB=false;
  144. }else{
  145. this.total_lockA=false;
  146. }
  147. }
  148. this.group=value;
  149. },
  150. // 更改商品数量
  151. async changeNum(index,val){
  152. let ListValue=JSON.parse(JSON.stringify(this.ListValue));
  153. let {id}=ListValue[index];
  154. var result =await api.quantity({id,quantity:val});
  155. if(result.code===0){
  156. ListValue[index]['quantity']=val;
  157. this.changeValue(ListValue);
  158. this.computer();
  159. }
  160. },
  161. // 下拉刷新
  162. async refresherpulling() {
  163. await this.reset();
  164. await this.requestFunc({ method: 'get', url: `/customer/order/cart/`, data: { limit: 10 } });
  165. },
  166. // 上拉加载
  167. async scroll() {
  168. await this.requestFunc({ method: 'get', url: `/customer/order/cart/`, data: { limit: 10 } });
  169. },
  170. payFunc() {
  171. uni.navigateTo({
  172. url: '/indexPages/pay/index'
  173. });
  174. }
  175. },
  176. watch: {
  177. group:{
  178. handler(newVal,oldVal){
  179. this.computer();
  180. },
  181. deep:true
  182. },
  183. status: {
  184. handler(newVal, oldVal) {
  185. this.group=[];
  186. this.total_lockA=false;
  187. this.total_lockB=false;
  188. },
  189. deep: true
  190. }
  191. },
  192. onShareAppMessage() {
  193. return {};
  194. },
  195. onShareTimeline() {
  196. return {};
  197. },
  198. // 下拉刷新
  199. async onPullDownRefresh() {
  200. // await this.$store.requestList.dispatch('requestFunc',true);
  201. uni.stopPullDownRefresh({});
  202. }
  203. };
  204. </script>
  205. <style lang="scss" scoped>
  206. .requestList {
  207. .section {
  208. .item {
  209. position: relative;
  210. .image {
  211. width: 160upx;
  212. min-width: 160upx;
  213. height: 160upx;
  214. background-size: cover;
  215. background-position: center;
  216. }
  217. .right {
  218. flex: auto;
  219. .right-right {
  220. flex: auto;
  221. }
  222. }
  223. &::after {
  224. content: '';
  225. border-bottom: 1upx solid #eee;
  226. position: absolute;
  227. left: 0;
  228. bottom: 0;
  229. transform: scale(1, 0.5);
  230. width: 100%;
  231. }
  232. }
  233. }
  234. .setting {
  235. height: 80upx;
  236. .setting-content {
  237. position: fixed;
  238. left: 0;
  239. z-index: 9998;
  240. width: 100%;
  241. .left {
  242. flex: auto;
  243. }
  244. .right {
  245. min-width: 60upx;
  246. }
  247. }
  248. }
  249. .tool {
  250. height: 100rpx;
  251. .tool-contentA {
  252. position: fixed;
  253. bottom: calc(100rpx + env(safe-area-inset-bottom));
  254. left: 0;
  255. z-index: 9998;
  256. width: 100%;
  257. .left {
  258. flex: auto;
  259. }
  260. &::before {
  261. content: '';
  262. border-top: 1upx solid #aaa;
  263. position: absolute;
  264. left: 0;
  265. top: 0;
  266. transform: scale(1, 0.5);
  267. width: 100%;
  268. }
  269. }
  270. }
  271. }
  272. </style>