shopCar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <template>
  2. <view class="common-car">
  3. <view class="empty-shop-car" v-if="isEmpty">
  4. <image src="../../static/empty_shop_car.png" class="empty-shop-car-image" mode=""></image>
  5. <text>当前列表是空的</text>
  6. <view class="empty-shop-car-btn">
  7. <text>去逛逛</text>
  8. </view>
  9. </view>
  10. <view class="shop-car" v-else>
  11. <view class="store-box" v-for="(item,index) in datas" :key="index">
  12. <view class="goodsInfo">
  13. <!-- <image src="../../static/select.png" v-if="itemw.checked == 2" class="checked-image"
  14. mode="" @tap="goodsCheck(indexq,indexw,itemw.checked)"></image>
  15. <image src="../../static/not_select.png" v-else class="checked-image" mode=""
  16. @tap="goodsCheck(indexq,indexw,itemw.checked)"></image>-->
  17. <view class="goodsInfo-right">
  18. <image v-if="item.image" :src="$BaseTool.UserUtil.getFileUrl(item.image)" class="goods-image" mode=""></image>
  19. <image v-else :src="spare_default" class="goods-image" mode=""></image>
  20. <view class="goodsInfo-box">
  21. <view class="goods-box">
  22. <text class="goods-price">{{item.name}}</text>
  23. <view class="">
  24. <button class="mini-btn" @click="deleteSpare(index)" type="default" size="mini">删除</button>
  25. </view>
  26. </view>
  27. <text class="spe">规格:{{item.remark}}</text>
  28. <view class="goods-box">
  29. <text class="goods-price">¥{{item.price}}</text>
  30. <view class="goods-num-box">
  31. <view class="goods-image" @tap="sub(index,item.num)">
  32. <text>-</text>
  33. </view>
  34. <view class="goods-num">
  35. <input type="digit" v-model="item.num" />
  36. </view>
  37. <view class="goods-image" @tap="add(index,item.num)">
  38. <text>+</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="statistics-box">
  47. <view class="statistics">
  48. <!-- <view class="statistics-left" v-if="statisticsIndex" @tap="allCheck">
  49. <image src="../../static/select.png" class="checked-image" mode="" >
  50. </image>
  51. <text>全选</text>
  52. </view>
  53. <view class="statistics-left" v-else @tap="allCheck">
  54. <image src="../../static/not_select.png" class="checked-image" mode="" >
  55. </image>
  56. <text>全选</text>
  57. </view>-->
  58. <view class="statistics-right" v-if="isCut" @tap="accounts">
  59. <text>总计:</text><text class="text-color">¥{{total}}</text>
  60. <view class="btn">
  61. <text>提交</text>
  62. </view>
  63. </view>
  64. <view class="statistics-right" v-else @tap="delect">
  65. <view class="btn">
  66. <text>删除</text>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="gap"></view>
  71. </view>
  72. </view>
  73. <slot></slot>
  74. </view>
  75. </template>
  76. <script>
  77. export default {
  78. name: 'commonCar',
  79. data() {
  80. return {
  81. isEmpty: true,
  82. iPhoneX: false,
  83. datas: [],
  84. spare_default: '/static/images/spare_default.png',
  85. statisticsIndex: false,
  86. total: 0,
  87. isCut: true
  88. }
  89. },
  90. mounted() {
  91. this.statistics()
  92. },
  93. watch: {
  94. datas: {
  95. //普通的watch监听
  96. handler(val, oldVal) {
  97. console.log('watch: ')
  98. console.log('val: ' + val)
  99. console.log('oldVal: ' + oldVal)
  100. this.isEmpty = false
  101. this.statistics()
  102. },
  103. immediate: true,
  104. deep: true //true 深度监听
  105. }
  106. },
  107. props: {
  108. list: {
  109. type: [Object, Array],
  110. default: () => []
  111. }
  112. },
  113. created() {
  114. this.datas = this.list
  115. if (this.datas.length == 0) {
  116. this.isEmpty = true
  117. return
  118. }
  119. this.isEmpty = false
  120. // this.statistics()
  121. console.log('created: ')
  122. },
  123. methods: {
  124. //备件选择
  125. goodsCheck(storeIndex, goodsIndex, goodsChecked) {
  126. if (goodsChecked == 1) {
  127. this.datas[storeIndex].goods[goodsIndex].checked = 2
  128. } else {
  129. this.datas[storeIndex].goods[goodsIndex].checked = 1
  130. }
  131. //判断是否该店铺全选
  132. let storeChecked = true
  133. this.datas[storeIndex].goods.map((item, index) => {
  134. if (item.checked == 1) {
  135. storeChecked = false
  136. }
  137. })
  138. if (storeChecked == false) {
  139. this.datas[storeIndex].checked = 1
  140. } else {
  141. this.datas[storeIndex].checked = 2
  142. }
  143. //判断是否全选
  144. let statisticsIndex = true
  145. this.datas.find((item, index) => {
  146. if (item.checked == 1) {
  147. statisticsIndex = false
  148. }
  149. })
  150. if (statisticsIndex == false) {
  151. this.statisticsIndex = false
  152. } else {
  153. this.statisticsIndex = true
  154. }
  155. this.statistics()
  156. },
  157. //店铺选择
  158. storeCheck(storeIndex, storeCheck) {
  159. if (storeCheck == 1) {
  160. this.datas[storeIndex].checked = 2
  161. this.datas[storeIndex].goods.find((item, index) => {
  162. item.checked = 2
  163. })
  164. } else {
  165. this.datas[storeIndex].checked = 1
  166. this.datas[storeIndex].goods.find((item, index) => {
  167. item.checked = 1
  168. })
  169. }
  170. //判断是否全选
  171. let statisticsIndex = true
  172. this.datas.find((item, index) => {
  173. if (item.checked == 1) {
  174. statisticsIndex = false
  175. }
  176. })
  177. if (statisticsIndex == false) {
  178. this.statisticsIndex = false
  179. } else {
  180. this.statisticsIndex = true
  181. }
  182. this.statistics()
  183. },
  184. // 删除备件
  185. deleteSpare(goodsIndex) {
  186. this.datas.splice(goodsIndex, 1)
  187. },
  188. //减少
  189. sub(goodsIndex, goodsnum) {
  190. if (goodsnum == 0) {
  191. return
  192. } else {
  193. this.datas[goodsIndex].num--
  194. this.datas[goodsIndex].num = this.datas[goodsIndex].num.toFixed(2)
  195. }
  196. this.statistics()
  197. },
  198. //增加
  199. add(goodsIndex, goodsnum) {
  200. this.datas[goodsIndex].num++
  201. this.datas[goodsIndex].num = this.datas[goodsIndex].num.toFixed(2)
  202. this.statistics()
  203. },
  204. //全选
  205. allCheck() {
  206. if (this.statisticsIndex) {
  207. this.datas.find((item, index) => {
  208. item.checked = 1
  209. })
  210. this.statisticsIndex = false
  211. } else {
  212. this.datas.find((item, index) => {
  213. item.checked = 2
  214. })
  215. this.statisticsIndex = true
  216. }
  217. this.statistics()
  218. },
  219. //更新数据
  220. setDatas(datas) {
  221. this.datas = datas
  222. },
  223. //统计
  224. statistics() {
  225. let total = 0
  226. this.datas.find((item, index) => {
  227. if (item.checked == 2) {
  228. total = total + item.price * item.num
  229. }
  230. })
  231. this.total = total.toFixed(2)
  232. },
  233. cut() {
  234. this.isCut = !this.isCut
  235. this.statisticsIndex = true
  236. this.allCheck()
  237. },
  238. accounts() {
  239. let judge = this.judgeSelect()
  240. if (judge) {
  241. this.$emit('accounts', this.datas)
  242. } else {
  243. uni.showToast({
  244. title: '您当前未选择任何备件,提交失败',
  245. icon: 'none'
  246. })
  247. }
  248. },
  249. delect() {
  250. let judge = this.judgeSelect()
  251. if (judge) {
  252. this.$emit('delect', this.datas)
  253. } else {
  254. uni.showToast({
  255. title: '您当前未选择任何备件,删除失败',
  256. icon: 'none'
  257. })
  258. }
  259. },
  260. judgeSelect() {
  261. let judge = false
  262. this.datas.find((item, index) => {
  263. if (item.checked == 2) {
  264. judge = true
  265. }
  266. })
  267. return judge
  268. }
  269. }
  270. }
  271. </script>
  272. <style lang="scss" scoped>
  273. .common-car {
  274. width: 750rpx;
  275. min-height: 100vh;
  276. display: flex;
  277. flex-direction: column;
  278. align-items: center;
  279. background: #f5f5f5;
  280. }
  281. .empty-shop-car {
  282. //width: 750rpx;
  283. min-height: 680rpx;
  284. display: flex;
  285. flex-direction: column;
  286. align-items: center;
  287. .empty-shop-car-image {
  288. width: 340rpx;
  289. height: 278rpx;
  290. margin-top: 102rpx;
  291. }
  292. text {
  293. margin-top: 40rpx;
  294. font-size: 28rpx;
  295. font-weight: 400;
  296. color: #666666;
  297. }
  298. .empty-shop-car-btn {
  299. width: 240rpx;
  300. height: 90rpx;
  301. background: #fbbc02;
  302. border-radius: 200rpx;
  303. margin-top: 40rpx;
  304. text-align: center;
  305. line-height: 90rpx;
  306. font-size: 30rpx;
  307. font-weight: 400;
  308. color: #313133;
  309. }
  310. }
  311. .shop-car {
  312. display: flex;
  313. flex-direction: column;
  314. align-items: center;
  315. .shop-car-header {
  316. width: 690rpx;
  317. height: 80rpx;
  318. display: flex;
  319. flex-direction: row;
  320. align-items: center;
  321. justify-content: flex-end;
  322. text {
  323. font-size: 28rpx;
  324. font-weight: 400;
  325. color: #313133;
  326. }
  327. }
  328. .store-box {
  329. margin-bottom: 20rpx;
  330. display: flex;
  331. flex-direction: column;
  332. align-items: center;
  333. background-color: #ffffff;
  334. .store-header {
  335. width: 690rpx;
  336. height: 78rpx;
  337. padding: 0 30rpx;
  338. display: flex;
  339. flex-direction: row;
  340. align-items: center;
  341. font-size: 28rpx;
  342. font-weight: 400;
  343. color: #313133;
  344. .checked-image {
  345. width: 36rpx;
  346. height: 36rpx;
  347. }
  348. text {
  349. font-size: 28rpx;
  350. font-weight: 400;
  351. color: #313133;
  352. margin-left: 20rpx;
  353. }
  354. .label {
  355. width: 14rpx;
  356. height: 24rpx;
  357. margin-left: 10rpx;
  358. margin-top: 5rpx;
  359. }
  360. }
  361. .goodsInfo {
  362. height: 246rpx;
  363. display: flex;
  364. flex-direction: row;
  365. align-items: center;
  366. border-bottom: 2rpx solid #ededed;
  367. &:nth-last-child(1) {
  368. border: none;
  369. }
  370. .checked-image {
  371. width: 36rpx;
  372. height: 36rpx;
  373. }
  374. .goodsInfo-right {
  375. height: 246rpx;
  376. display: flex;
  377. flex-direction: row;
  378. align-items: center;
  379. border-radius: 11px;
  380. .goods-image {
  381. width: 160rpx;
  382. height: 160rpx;
  383. padding-left: 20rpx;
  384. }
  385. .goodsInfo-box {
  386. width: 500rpx;
  387. margin-left: 24rpx;
  388. display: flex;
  389. flex-direction: column;
  390. align-items: center;
  391. .goods-name {
  392. width: 428rpx;
  393. font-size: 26rpx;
  394. font-weight: 400;
  395. color: #313133;
  396. }
  397. .spe {
  398. width: 480rpx;
  399. margin-top: 10rpx;
  400. font-size: 30rpx;
  401. font-weight: 400;
  402. color: #919298;
  403. }
  404. .goods-box {
  405. width: 480rpx;
  406. margin-top: 18rpx;
  407. display: flex;
  408. flex-direction: row;
  409. align-items: center;
  410. justify-content: space-between;
  411. .goods-price {
  412. font-size: 36rpx;
  413. font-weight: 400;
  414. color: #313133;
  415. }
  416. .goods-num-box {
  417. width: 240rpx;
  418. height: 46rpx;
  419. display: flex;
  420. flex-direction: row;
  421. align-items: center;
  422. .goods-image {
  423. height: 24px;
  424. text-align: center;
  425. line-height: 44rpx;
  426. border: 1rpx solid #cfcfcf;
  427. font-size: 18px;
  428. }
  429. .goods-num {
  430. text-align: center;
  431. line-height: 44rpx;
  432. font-size: 33rpx;
  433. font-weight: 400;
  434. color: #666666;
  435. border-top: 1px solid #cfcfcf;
  436. border-bottom: 1px solid #cfcfcf;
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. }
  444. .statistics-box {
  445. width: 750rpx;
  446. display: flex;
  447. flex-direction: column;
  448. align-items: center;
  449. background-color: #ffffff;
  450. position: fixed;
  451. bottom: 0;
  452. .statistics {
  453. width: 720rpx;
  454. padding: 0 0 0 30rpx;
  455. height: 98rpx;
  456. display: flex;
  457. flex-direction: row;
  458. align-items: center;
  459. justify-content: space-between;
  460. .statistics-left {
  461. width: 120rpx;
  462. display: flex;
  463. flex-direction: row;
  464. align-items: center;
  465. justify-content: space-between;
  466. image {
  467. width: 36rpx;
  468. height: 36rpx;
  469. }
  470. text {
  471. font-size: 30rpx;
  472. font-weight: 400;
  473. color: #313133;
  474. }
  475. }
  476. .statistics-right {
  477. width: 600rpx;
  478. display: flex;
  479. flex-direction: row;
  480. align-items: center;
  481. justify-content: flex-end;
  482. .btn {
  483. width: 218rpx;
  484. height: 98rpx;
  485. background: #fbbc02;
  486. text-align: center;
  487. line-height: 98rpx;
  488. font-size: 30rpx;
  489. font-weight: 400;
  490. color: #313133;
  491. margin-left: 40rpx;
  492. }
  493. text {
  494. font-size: 30rpx;
  495. font-weight: 400;
  496. color: #313133;
  497. }
  498. .text-color {
  499. color: rgba(242, 18, 18, 1);
  500. }
  501. }
  502. }
  503. .gap {
  504. width: 750rpx;
  505. height: 40rpx;
  506. }
  507. }
  508. }
  509. </style>