obligation.vue 7.9 KB

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