obligation.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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.goodsNum" 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 v-if="!editDel" style="margin-left: 300rpx;">
  37. <view>总计:¥<text>{{totalPrice}}</text></view>
  38. <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
  39. </view>
  40. <view style="width: 200rpx;">
  41. <u-button shape="circle" size="small" text="立即支付" v-if="!editDel"
  42. :disabled="this.selectedProduct.length == 0"
  43. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
  44. <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
  45. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button>
  46. </view>
  47. </view>
  48. </view>
  49. <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
  50. v-if="dataList.length == 0 && !isLoading" mode="car" text="待付款为空" icon="http://cdn.uviewui.com/uview/empty/car.png" />
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. obligationList,
  56. generateOrder,
  57. payPrepay,
  58. shoppingCartUpdate,
  59. getCorpsAddr
  60. } from '@/api/tabBar/shoppingCart.js'
  61. import { registerRuntimeCompiler } from "vue"
  62. import { logo } from '../../../common/setting'
  63. export default {
  64. data() {
  65. return {
  66. editDel: false,
  67. radiovalue: [],
  68. companyValue: [],
  69. dataList: [],
  70. companyValueLength: 0,
  71. selectedProduct: [],
  72. totalPrice: 0.00,
  73. totalFreight: 0.00,
  74. addres: {},
  75. isLoading: true
  76. }
  77. },
  78. watch: {
  79. companyValue() {
  80. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  81. if (this.companyValue.length == this.companyValueLength) {
  82. this.radiovalue = ["全选"]
  83. } else {
  84. this.radiovalue = []
  85. }
  86. }
  87. // if (this.companyValue.length > 0) {
  88. // console.log(21321324);
  89. // // if (this.companyValue.length == this.companyValueLength) {
  90. // // this.radiovalue = ["全选"]
  91. // // } else {
  92. // // this.radiovalue = []
  93. // // }
  94. // }
  95. this.statistics()
  96. }
  97. },
  98. onShow() {
  99. this.editDel = false
  100. this.companyValue = []
  101. this.isLoading = true
  102. obligationList().then(res => {
  103. console.log(res);
  104. this.dataList = res.data
  105. this.companyValueLength = this.dataList.length
  106. this.isLoading = false // 添加这一行
  107. })
  108. getCorpsAddr().then(res => {
  109. this.addres = res.data
  110. })
  111. },
  112. methods: {
  113. deleteGoods(val) {
  114. uni.showLoading({
  115. title: '加载中',
  116. mask: true
  117. });
  118. shoppingCartUpdate({
  119. ids: val
  120. }).then(res => {
  121. uni.showToast({
  122. title: "删除成功",
  123. icon: 'none'
  124. });
  125. uni.showLoading({
  126. title: '加载中',
  127. mask: true
  128. });
  129. this.editDel = false
  130. this.companyValue = []
  131. obligationList().then(res => {
  132. this.dataList = res.data
  133. this.companyValueLength = this.dataList.length
  134. uni.hideLoading();
  135. }).catch(err => {
  136. uni.hideLoading();
  137. })
  138. uni.hideLoading();
  139. }).catch(err => {
  140. uni.hideLoading();
  141. })
  142. },
  143. deleteShopping() {
  144. let data = []
  145. for (let item of this.companyValue) {
  146. for (let ite of this.dataList) {
  147. if (item == ite.name) {
  148. for (let it of ite.list) {
  149. data.push(it.id)
  150. }
  151. }
  152. }
  153. }
  154. uni.showLoading({
  155. title: '加载中',
  156. mask: true
  157. });
  158. shoppingCartUpdate({
  159. ids: data.join(',')
  160. }).then(res => {
  161. uni.showToast({
  162. title: "删除成功",
  163. icon: 'none'
  164. });
  165. uni.hideLoading();
  166. uni.showLoading({
  167. title: '加载中',
  168. mask: true
  169. });
  170. this.editDel = false
  171. this.companyValue = []
  172. obligationList().then(res => {
  173. this.dataList = res.data
  174. this.companyValueLength = this.dataList.length
  175. uni.hideLoading();
  176. }).catch(err => {
  177. uni.hideLoading();
  178. })
  179. }).catch(err => {
  180. uni.hideLoading();
  181. })
  182. },
  183. submit() {
  184. if (this.companyValue.length > 0) {
  185. let data = []
  186. for (let item of this.companyValue) {
  187. for (let ite of this.dataList) {
  188. if (item == ite.name) {
  189. data.push({
  190. name: item,
  191. })
  192. }
  193. }
  194. }
  195. console.log('data',data);
  196. uni.showLoading({
  197. title: '加载中',
  198. mask: true
  199. });
  200. payPrepay({srcOrderNo:data[0].name}).then(res => {
  201. console.log(res);
  202. uni.requestPayment({
  203. provider: "wxpay",
  204. appId:res.data.appId,
  205. timeStamp: res.data.timeStamp,
  206. nonceStr: res.data.nonceStr,
  207. package: res.data.package,
  208. signType: res.data.signType,
  209. paySign: res.data.paySign,
  210. success(res) {
  211. uni.showToast({
  212. title: '支付成功',
  213. mask: true,
  214. duration: 2000
  215. });
  216. setTimeout(function() {
  217. uni.hideLoading();
  218. // this_.refresh(res.data.data.id)
  219. }, 1000);
  220. },
  221. fail(e) {
  222. console.log(e);
  223. uni.showToast({
  224. title: "支付失败",
  225. icon: 'none',
  226. mask: true
  227. });
  228. setTimeout(function() {
  229. uni.hideLoading();
  230. // this_.refresh(res.data.id)
  231. }, 1000);
  232. }
  233. })
  234. uni.showToast({
  235. title: "提交成功",
  236. icon: 'none'
  237. });
  238. uni.hideLoading();
  239. uni.showLoading({
  240. title: '加载中',
  241. mask: true
  242. });
  243. this.editDel = false
  244. this.companyValue = []
  245. shoppingCartList().then(res => {
  246. this.dataList = res.data
  247. this.companyValueLength = this.dataList.length
  248. uni.hideLoading();
  249. }).catch(err => {
  250. uni.hideLoading();
  251. })
  252. }).catch(err => {
  253. uni.hideLoading();
  254. })
  255. }
  256. },
  257. radioGroupChange(e) {
  258. this.radiovalue = e
  259. if (e.length == 0) {
  260. this.companyValue = []
  261. } else {
  262. for (let li of this.dataList) {
  263. if (!this.companyValue.includes(li.name)) {
  264. this.companyValue.push(li.name)
  265. }
  266. }
  267. }
  268. this.statistics()
  269. },
  270. statistics(val, index, ind) {
  271. if (val) {
  272. this.dataList[index].list[ind].goodsNum = val.value
  273. }
  274. let data = []
  275. for (let item of this.companyValue) {
  276. for (let ite of this.dataList) {
  277. if (item == ite.name) {
  278. for (let it of ite.list) {
  279. data.push(it)
  280. }
  281. }
  282. }
  283. }
  284. console.log(data);
  285. this.totalPrice = 0
  286. this.totalFreight = 0
  287. for (let item of data) {
  288. for(let orderItem of item.orderItemsList){
  289. this.totalPrice += Number(orderItem.price) * Number(orderItem.goodsNum)
  290. console.log(orderItem.goodsNum);
  291. if (Number(orderItem.goodsNum) == 1) {
  292. this.totalFreight += 5
  293. }
  294. }
  295. }
  296. this.totalFreight = this.totalFreight.toFixed(2)
  297. this.totalPrice = this.totalPrice.toFixed(2)
  298. this.selectedProduct = data
  299. },
  300. companyChange(n) {
  301. this.companyValue = n
  302. }
  303. }
  304. }
  305. </script>
  306. <style lang="scss" scoped>
  307. .collection {
  308. background-color: #fff;
  309. padding: 20rpx;
  310. border-radius: 20rpx;
  311. margin-top: 20rpx;
  312. }
  313. .goods {
  314. width: 100%;
  315. margin-left: 20rpx;
  316. height: 200rpx;
  317. display: grid;
  318. align-content: space-between;
  319. .price {
  320. display: flex;
  321. justify-content: space-between !important;
  322. margin-top: 20rpx;
  323. align-items: center;
  324. view:nth-child(1) {
  325. color: #FD4B09;
  326. font-size: 40rpx;
  327. }
  328. }
  329. }
  330. .submitBar {
  331. position: fixed;
  332. bottom: 0;
  333. background-color: #fff;
  334. width: 100%;
  335. z-index: 10;
  336. .bar_view {
  337. display: flex;
  338. justify-content: space-between;
  339. align-items: center;
  340. padding: 10rpx;
  341. }
  342. }
  343. </style>