shoppingCart.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. import { registerRuntimeCompiler } from "vue"
  80. export default {
  81. data() {
  82. return {
  83. editDel: false,
  84. radiovalue: [],
  85. companyValue: [],
  86. dataList: [],
  87. companyValueLength: 0,
  88. selectedProduct: [],
  89. totalPrice: 0.00,
  90. totalFreight: 0.00,
  91. addres: {}
  92. }
  93. },
  94. watch: {
  95. companyValue() {
  96. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  97. if (this.companyValue.length == this.companyValueLength) {
  98. this.radiovalue = ["全选"]
  99. } else {
  100. this.radiovalue = []
  101. }
  102. }
  103. this.statistics()
  104. }
  105. },
  106. onShow() {
  107. this.editDel = false
  108. this.companyValue = []
  109. shoppingCartList().then(res => {
  110. this.dataList = res.data
  111. this.companyValueLength = this.dataList.length
  112. })
  113. getCorpsAddr().then(res => {
  114. this.addres = res.data
  115. })
  116. },
  117. methods: {
  118. clickAddress() {
  119. this.$u.route('/pages/views/personalInformation/addressManagement');
  120. },
  121. deleteGoods(val) {
  122. uni.showLoading({
  123. title: '加载中',
  124. mask: true
  125. });
  126. shoppingCartUpdate({
  127. ids: val
  128. }).then(res => {
  129. uni.showToast({
  130. title: "删除成功",
  131. icon: 'none'
  132. });
  133. uni.showLoading({
  134. title: '加载中',
  135. mask: true
  136. });
  137. this.editDel = false
  138. this.companyValue = []
  139. shoppingCartList().then(res => {
  140. this.dataList = res.data
  141. this.companyValueLength = this.dataList.length
  142. uni.hideLoading();
  143. }).catch(err => {
  144. uni.hideLoading();
  145. })
  146. uni.hideLoading();
  147. }).catch(err => {
  148. uni.hideLoading();
  149. })
  150. },
  151. deleteShopping() {
  152. let data = []
  153. for (let item of this.companyValue) {
  154. for (let ite of this.dataList) {
  155. if (item == ite.name) {
  156. for (let it of ite.list) {
  157. data.push(it.id)
  158. }
  159. }
  160. }
  161. }
  162. uni.showLoading({
  163. title: '加载中',
  164. mask: true
  165. });
  166. shoppingCartUpdate({
  167. ids: data.join(',')
  168. }).then(res => {
  169. uni.showToast({
  170. title: "删除成功",
  171. icon: 'none'
  172. });
  173. uni.hideLoading();
  174. uni.showLoading({
  175. title: '加载中',
  176. mask: true
  177. });
  178. this.editDel = false
  179. this.companyValue = []
  180. shoppingCartList().then(res => {
  181. this.dataList = res.data
  182. this.companyValueLength = this.dataList.length
  183. uni.hideLoading();
  184. }).catch(err => {
  185. uni.hideLoading();
  186. })
  187. }).catch(err => {
  188. uni.hideLoading();
  189. })
  190. },
  191. submit() {
  192. if (this.companyValue.length > 0) {
  193. let data = []
  194. for (let item of this.companyValue) {
  195. for (let ite of this.dataList) {
  196. if (item == ite.name) {
  197. data.push({
  198. name: item,
  199. list: ite.list
  200. })
  201. }
  202. }
  203. }
  204. uni.showLoading({
  205. title: '加载中',
  206. mask: true
  207. });
  208. generateOrder({
  209. address: this.addres.belongtoarea + this.addres.detailedAddress,
  210. list: data,
  211. }).then(res => {
  212. console.log(res);
  213. return
  214. uni.showToast({
  215. title: "提交成功",
  216. icon: 'none'
  217. });
  218. uni.hideLoading();
  219. uni.showLoading({
  220. title: '加载中',
  221. mask: true
  222. });
  223. this.editDel = false
  224. this.companyValue = []
  225. shoppingCartList().then(res => {
  226. this.dataList = res.data
  227. this.companyValueLength = this.dataList.length
  228. uni.hideLoading();
  229. }).catch(err => {
  230. uni.hideLoading();
  231. })
  232. }).catch(err => {
  233. uni.hideLoading();
  234. })
  235. }
  236. },
  237. radioGroupChange(e) {
  238. this.radiovalue = e
  239. if (e.length == 0) {
  240. this.companyValue = []
  241. } else {
  242. for (let li of this.dataList) {
  243. if (!this.companyValue.includes(li.name)) {
  244. this.companyValue.push(li.name)
  245. }
  246. }
  247. }
  248. this.statistics()
  249. },
  250. statistics(val, index, ind) {
  251. if (val) {
  252. this.dataList[index].list[ind].goodsNum = val.value
  253. }
  254. let data = []
  255. for (let item of this.companyValue) {
  256. for (let ite of this.dataList) {
  257. if (item == ite.name) {
  258. for (let it of ite.list) {
  259. data.push(it)
  260. }
  261. }
  262. }
  263. }
  264. this.totalPrice = 0
  265. this.totalFreight = 0
  266. for (let item of data) {
  267. this.totalPrice += Number(item.price) * Number(item.goodsNum)
  268. if (Number(item.goodsNum) == 1) {
  269. this.totalFreight += 5
  270. }
  271. }
  272. this.totalFreight = this.totalFreight.toFixed(2)
  273. this.totalPrice = this.totalPrice.toFixed(2)
  274. this.selectedProduct = data
  275. },
  276. companyChange(n) {
  277. this.companyValue = n
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .collection {
  284. background-color: #fff;
  285. padding: 20rpx;
  286. border-radius: 20rpx;
  287. margin-top: 20rpx;
  288. }
  289. .goods {
  290. width: 100%;
  291. margin-left: 20rpx;
  292. height: 200rpx;
  293. display: grid;
  294. align-content: space-between;
  295. .price {
  296. display: flex;
  297. justify-content: space-between !important;
  298. margin-top: 20rpx;
  299. align-items: center;
  300. view:nth-child(1) {
  301. color: #FD4B09;
  302. font-size: 40rpx;
  303. }
  304. }
  305. }
  306. .submitBar {
  307. position: fixed;
  308. bottom: 0;
  309. background-color: #fff;
  310. width: 100%;
  311. z-index: 10;
  312. .bar_view {
  313. display: flex;
  314. justify-content: space-between;
  315. align-items: center;
  316. padding: 10rpx;
  317. }
  318. }
  319. </style>