index.vue 9.7 KB

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