shoppingCart.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view>
  3. <view style="background-color: #fff;padding: 20rpx;border-radius: 20rpx;">
  4. <view style="display: flex;justify-content: space-between;">
  5. <view>
  6. <view style="display: flex;width: 580rpx;" v-if="!editDel" @click="clickAddress">
  7. <u-icon name="map"></u-icon>
  8. <u--text :text="addres.belongtoarea + addres.detailedAddress" size="28rpx" lines="1"></u--text>
  9. </view>
  10. </view>
  11. <view style="display: flex;">
  12. <view style="margin-right: 40rpx;">|</view>
  13. <view @click="editDel = !editDel">{{editDel?'取消':'编辑'}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <u-checkbox-group v-model="companyValue" placement="column" @change="companyChange">
  18. <view class="collection" v-for="(item,index) in dataList" :key="index">
  19. <view>
  20. <u-checkbox activeColor="#FD4B09" shape="circle" :customStyle="{marginBottom: '8px'}"
  21. :label="item.name" :name="item.name" labelSize="28rpx"></u-checkbox>
  22. </view>
  23. <view style="margin-left: 20rpx;display: flex;align-items: center;" v-for="(ite,ind) in item.list"
  24. :key="ind">
  25. <view>
  26. <image v-for="(li,inde) in ite.filesList" :key="inde" v-if="li.version === '0'" :src="li.url"
  27. style="width: 200rpx;height: 200rpx;border-radius: 20rpx;">
  28. </image>
  29. </view>
  30. <view class="goods">
  31. <u--text :text="ite.goodsName" size="24rpx" lines="2"></u--text>
  32. <view class="price">
  33. <view>¥{{ite.price}}</view>
  34. <view v-if="!editDel">
  35. <u-number-box v-model="ite.goodsNum" :min="1" :max="ite.inventory" buttonSize="40rpx"
  36. @change="(val)=>{statistics(val,index,ind)}"></u-number-box>
  37. </view>
  38. </view>
  39. </view>
  40. <view v-if="editDel">
  41. <u-icon name="minus-circle-fill" color="#ff0000" size="52rpx"
  42. @click="deleteGoods(ite.id)"></u-icon>
  43. </view>
  44. </view>
  45. </view>
  46. </u-checkbox-group>
  47. <view style="height: 100rpx;"></view>
  48. <view class="submitBar">
  49. <view class="bar_view">
  50. <view>
  51. <u-checkbox-group v-model="radiovalue" placement="column" @change="radioGroupChange">
  52. <u-checkbox label="全选" name="全选" activeColor="#FD4B09" shape="circle"></u-checkbox>
  53. </u-checkbox-group>
  54. </view>
  55. <view v-if="!editDel">
  56. <view>总计:¥<text>{{totalPrice}}</text></view>
  57. <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
  58. </view>
  59. <view style="width: 200rpx;">
  60. <u-button shape="circle" size="small" text="提交订单" v-if="!editDel"
  61. :disabled="this.selectedProduct.length == 0"
  62. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
  63. <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
  64. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button>
  65. </view>
  66. </view>
  67. </view>
  68. <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
  69. v-if="dataList.length == 0" mode="car" icon="http://cdn.uviewui.com/uview/empty/car.png" />
  70. </view>
  71. </template>
  72. <script>
  73. import {
  74. shoppingCartList,
  75. generateOrder,
  76. shoppingCartUpdate,
  77. getCorpsAddr
  78. } from '@/api/tabBar/shoppingCart.js'
  79. export default {
  80. data() {
  81. return {
  82. editDel: false,
  83. radiovalue: [],
  84. companyValue: [],
  85. dataList: [],
  86. companyValueLength: 0,
  87. selectedProduct: [],
  88. totalPrice: 0.00,
  89. totalFreight: 0.00,
  90. addres: {}
  91. }
  92. },
  93. watch: {
  94. companyValue() {
  95. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  96. if (this.companyValue.length == this.companyValueLength) {
  97. this.radiovalue = ["全选"]
  98. } else {
  99. this.radiovalue = []
  100. }
  101. }
  102. this.statistics()
  103. }
  104. },
  105. onShow() {
  106. this.editDel = false
  107. this.companyValue = []
  108. shoppingCartList().then(res => {
  109. this.dataList = res.data
  110. this.companyValueLength = this.dataList.length
  111. })
  112. getCorpsAddr().then(res => {
  113. this.addres = res.data
  114. })
  115. },
  116. methods: {
  117. clickAddress() {
  118. this.$u.route('/pages/views/personalInformation/addressManagement');
  119. },
  120. deleteGoods(val) {
  121. uni.showLoading({
  122. title: '加载中',
  123. mask: true
  124. });
  125. shoppingCartUpdate({
  126. ids: val
  127. }).then(res => {
  128. uni.showToast({
  129. title: "删除成功",
  130. icon: 'none'
  131. });
  132. uni.showLoading({
  133. title: '加载中',
  134. mask: true
  135. });
  136. this.editDel = false
  137. this.companyValue = []
  138. shoppingCartList().then(res => {
  139. this.dataList = res.data
  140. this.companyValueLength = this.dataList.length
  141. uni.hideLoading();
  142. }).catch(err => {
  143. uni.hideLoading();
  144. })
  145. uni.hideLoading();
  146. }).catch(err => {
  147. uni.hideLoading();
  148. })
  149. },
  150. deleteShopping() {
  151. let data = []
  152. for (let item of this.companyValue) {
  153. for (let ite of this.dataList) {
  154. if (item == ite.name) {
  155. for (let it of ite.list) {
  156. data.push(it.id)
  157. }
  158. }
  159. }
  160. }
  161. uni.showLoading({
  162. title: '加载中',
  163. mask: true
  164. });
  165. shoppingCartUpdate({
  166. ids: data.join(',')
  167. }).then(res => {
  168. uni.showToast({
  169. title: "删除成功",
  170. icon: 'none'
  171. });
  172. uni.hideLoading();
  173. uni.showLoading({
  174. title: '加载中',
  175. mask: true
  176. });
  177. this.editDel = false
  178. this.companyValue = []
  179. shoppingCartList().then(res => {
  180. this.dataList = res.data
  181. this.companyValueLength = this.dataList.length
  182. uni.hideLoading();
  183. }).catch(err => {
  184. uni.hideLoading();
  185. })
  186. }).catch(err => {
  187. uni.hideLoading();
  188. })
  189. },
  190. submit() {
  191. if (this.companyValue.length > 0) {
  192. let data = []
  193. for (let item of this.companyValue) {
  194. for (let ite of this.dataList) {
  195. if (item == ite.name) {
  196. data.push({
  197. name: item,
  198. list: ite.list
  199. })
  200. }
  201. }
  202. }
  203. uni.showLoading({
  204. title: '加载中',
  205. mask: true
  206. });
  207. generateOrder({
  208. address: this.addres.belongtoarea + this.addres.detailedAddress,
  209. list: data
  210. }).then(res => {
  211. uni.showToast({
  212. title: "提交成功",
  213. icon: 'none'
  214. });
  215. uni.hideLoading();
  216. uni.showLoading({
  217. title: '加载中',
  218. mask: true
  219. });
  220. this.editDel = false
  221. this.companyValue = []
  222. shoppingCartList().then(res => {
  223. this.dataList = res.data
  224. this.companyValueLength = this.dataList.length
  225. uni.hideLoading();
  226. }).catch(err => {
  227. uni.hideLoading();
  228. })
  229. }).catch(err => {
  230. uni.hideLoading();
  231. })
  232. }
  233. },
  234. radioGroupChange(e) {
  235. this.radiovalue = e
  236. if (e.length == 0) {
  237. this.companyValue = []
  238. } else {
  239. for (let li of this.dataList) {
  240. if (!this.companyValue.includes(li.name)) {
  241. this.companyValue.push(li.name)
  242. }
  243. }
  244. }
  245. this.statistics()
  246. },
  247. statistics(val, index, ind) {
  248. if (val) {
  249. this.dataList[index].list[ind].goodsNum = val.value
  250. }
  251. let data = []
  252. for (let item of this.companyValue) {
  253. for (let ite of this.dataList) {
  254. if (item == ite.name) {
  255. for (let it of ite.list) {
  256. data.push(it)
  257. }
  258. }
  259. }
  260. }
  261. this.totalPrice = 0
  262. this.totalFreight = 0
  263. for (let item of data) {
  264. this.totalPrice += Number(item.price) * Number(item.goodsNum)
  265. if (Number(item.goodsNum) == 1) {
  266. this.totalFreight += 5
  267. }
  268. }
  269. this.totalFreight = this.totalFreight.toFixed(2)
  270. this.totalPrice = this.totalPrice.toFixed(2)
  271. this.selectedProduct = data
  272. },
  273. companyChange(n) {
  274. this.companyValue = n
  275. }
  276. }
  277. }
  278. </script>
  279. <style lang="scss" scoped>
  280. .collection {
  281. background-color: #fff;
  282. padding: 20rpx;
  283. border-radius: 20rpx;
  284. margin-top: 20rpx;
  285. }
  286. .goods {
  287. width: 100%;
  288. margin-left: 20rpx;
  289. height: 200rpx;
  290. display: grid;
  291. align-content: space-between;
  292. .price {
  293. display: flex;
  294. justify-content: space-between !important;
  295. margin-top: 20rpx;
  296. align-items: center;
  297. view:nth-child(1) {
  298. color: #FD4B09;
  299. font-size: 40rpx;
  300. }
  301. }
  302. }
  303. .submitBar {
  304. position: fixed;
  305. bottom: 0;
  306. background-color: #fff;
  307. width: 100%;
  308. z-index: 10;
  309. .bar_view {
  310. display: flex;
  311. justify-content: space-between;
  312. align-items: center;
  313. padding: 10rpx;
  314. }
  315. }
  316. </style>