cart.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="warpbox">
  3. <!-- 搜索 -->
  4. <view class="searbox">
  5. <view class="censear">
  6. <image src="/static/img/search.png" class="searimg" mode=""></image>
  7. <input type="text" :placeholder="i18n['请输入关键词搜索']" @input="queryData" class="lself">
  8. </view>
  9. <image src="/static/img/delete.png" class="deleimg" @click="del" mode=""></image>
  10. </view>
  11. <scroll-view class="scrollbox" scroll-y @scrolltolower="loadMorePart">
  12. <view class="part_warp">
  13. <view class="part_item" v-for="(item,index) in list" :key="index" @tap.stop="selectPart(index)">
  14. <radio value="r1" color="#7FC2FF" :checked="item.select" />
  15. <view class="item_infor">
  16. <image :src="item.parts.img" class="partimg" mode=""></image>
  17. <view class="info">
  18. <view class="info_box">
  19. <view class="title">{{item.parts.name}}</view>
  20. <view class="desc">{{i18n['规格']}}:{{item.parts.unit}}</view>
  21. </view>
  22. <view class="info_bot" @tap.stop.prevent>
  23. <view class="partmoney">¥{{item.parts.price}}</view>
  24. <uni-number-box v-model="item.num" @change="(e)=>{changeNum(e,index)}"></uni-number-box>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <view class="botbox">
  32. <view class="botleft">
  33. <image src="/static/img/cart.png" class="carimg"></image>
  34. <view class="left_te">
  35. <view class="num" >{{i18n['已选']}}{{selectList.length}}{{i18n['件']}}</view>
  36. <view class="totalmoney">¥{{totalMoney}}</view>
  37. </view>
  38. </view>
  39. <!-- <view class="botright" @click="subOrder">{{i18n['提交订单']}}</view> -->
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { netCartListnum, netChangePartNum, netDelCartNum } from '@/api/api.js'
  45. export default{
  46. data(){
  47. return{
  48. list:[],
  49. name:'',
  50. page:1,
  51. totalPage:1,
  52. totalMoney:0,
  53. selectList:[]
  54. }
  55. },
  56. computed:{
  57. i18n() {
  58. return this.$t("shopmall")
  59. }
  60. },
  61. onShow() {
  62. uni.setNavigationBarTitle({
  63. title: this.i18n['购物车']
  64. })
  65. this.list = []
  66. this.page = 1
  67. //购物车 列表
  68. this.getList()
  69. },
  70. methods:{
  71. queryData(e) {
  72. this.name = e.detail.value
  73. this.list = []
  74. this.page = 1
  75. setTimeout(()=>{
  76. this.getList()
  77. },200)
  78. },
  79. loadMorePart() {
  80. if(this.page < this.totalPage){
  81. this.page ++
  82. this.getList()
  83. }
  84. },
  85. getList() {
  86. let params = {
  87. page:this.page,
  88. name: this.name
  89. }
  90. netCartListnum(params).then(res=>{
  91. let data = res.data.data
  92. data.forEach(ele=>{
  93. ele.select = false
  94. })
  95. this.list = this.list.concat(data)
  96. this.totalPage = res.data.last_page
  97. })
  98. },
  99. selectPart(index) {
  100. let obj = this.list[index]
  101. obj.select = !obj.select
  102. this.$set(this.list,index,obj)
  103. //重新计算 money
  104. this.handleMoney()
  105. //筛选 已选择的数据
  106. this.handleSelected()
  107. },
  108. handleSelected() {
  109. let data = this.list
  110. let arr = []
  111. data.forEach(ele=>{
  112. if(ele.select) {
  113. arr.push(ele.id)
  114. }
  115. })
  116. this.selectList = arr
  117. },
  118. changeNum(e,index) {
  119. let num = e
  120. let obj = this.list[index]
  121. obj.num = num
  122. this.$set(this.list,index,obj)
  123. //修改数量
  124. this.changeCartnum(num,obj)
  125. //重新计算 money
  126. this.handleMoney()
  127. },
  128. changeCartnum(num,obj) {
  129. let params = {
  130. id: obj.id,
  131. num
  132. }
  133. netChangePartNum(params).then(res=>{})
  134. },
  135. handleMoney(){
  136. let data = this.list
  137. let money = 0
  138. data.forEach(ele=>{
  139. if(ele.select) {
  140. money += ele.num * Number(ele.parts.price)
  141. }
  142. })
  143. this.totalMoney = money
  144. },
  145. del(){
  146. let arr = this.selectList
  147. if(arr.length == 0){
  148. uni.showToast({
  149. title:'请选择需要删除的配件',
  150. icon:'none'
  151. })
  152. return
  153. }
  154. netDelCartNum({ids:arr.join(',')}).then(res=>{
  155. uni.showToast({
  156. title:res.msg,
  157. icon:'none'
  158. })
  159. setTimeout(()=>{
  160. this.list = []
  161. this.page = 1
  162. this.getList()
  163. this.totalMoney = 0
  164. this.selectList = []
  165. },2000)
  166. })
  167. },
  168. subOrder() {
  169. if(this.selectList.length == 0) {
  170. uni.showToast({
  171. title:'请选择要下单的配件',
  172. icon:'none'
  173. })
  174. return
  175. }
  176. let ids = this.selectList.join(',')
  177. uni.navigateTo({
  178. url:'/pages/serviceMall/orderDetail?ids='+ids
  179. })
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .searbox{
  186. padding:10rpx 0 20rpx 0;
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. .censear{
  191. display: flex;
  192. justify-content: flex-start;
  193. align-items: center;
  194. padding:0 24rpx;
  195. border-radius: 34rpx;
  196. background:#FFFFFF;
  197. width:564rpx;
  198. height:68rpx;
  199. border:1rpx solid #7FC2FF;
  200. .searimg{
  201. width:48rpx;
  202. height:48rpx;
  203. }
  204. .lself{
  205. width:420rpx;
  206. font-size:26rpx;
  207. color:rgba(2, 135, 255, 1);
  208. }
  209. }
  210. .deleimg{
  211. width:44rpx;
  212. height:44rpx;
  213. margin-left:35rpx;
  214. }
  215. }
  216. .scrollbox{
  217. width:750rpx;
  218. height:calc(100vh - 300rpx);
  219. .part_warp{
  220. .part_item{
  221. width:690rpx;
  222. margin:0 auto 24rpx;
  223. background:#fff;
  224. border-radius: 20rpx;
  225. padding:30rpx;
  226. display: flex;
  227. justify-content: flex-start;
  228. align-items: center;
  229. radio{
  230. transform: scale(0.7);
  231. flex-shrink: 0;
  232. }
  233. .item_infor{
  234. margin-left:24rpx;
  235. display: flex;
  236. justify-content: flex-start;
  237. align-items: center;
  238. .partimg{
  239. width: 130rpx;
  240. height: 130rpx;
  241. border-radius: 10rpx;
  242. margin-right:24rpx;
  243. flex-shrink: 0;
  244. }
  245. .info{
  246. width:380rpx;
  247. .info_box{
  248. .title{
  249. font-size:30rpx;
  250. color:#333333;
  251. }
  252. .desc{
  253. font-size:26rpx;
  254. color:#999999;
  255. margin-top:15rpx;
  256. }
  257. }
  258. .info_bot{
  259. width:100%;
  260. display: flex;
  261. justify-content: space-between;
  262. align-items: center;
  263. margin-top:15rpx;
  264. .partmoney{
  265. font-size:26rpx;
  266. color:#7FC2FF;
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. .botbox{
  275. width:690rpx;
  276. background:#fff;
  277. margin:24rpx auto;
  278. border-radius: 20rpx;
  279. padding:24rpx;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. .botleft{
  284. display: flex;
  285. justify-content: flex-start;
  286. align-items: center;
  287. .carimg{
  288. width:48rpx;
  289. height:41rpx;
  290. margin-right:15rpx;
  291. }
  292. .left_te{
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. .totalmoney{
  297. color:#7FC2FF;
  298. font-size:24rpx;
  299. margin-left:24rpx;
  300. }
  301. .num{
  302. font-size:24rpx;
  303. color:#999;
  304. }
  305. }
  306. }
  307. .botright{
  308. width:360rpx;
  309. height:88rpx;
  310. border-radius: 45rpx;
  311. background:#7FC2FF;
  312. font-size:30rpx;
  313. color:#fff;
  314. text-align: center;
  315. line-height: 88rpx;
  316. }
  317. }
  318. </style>