obligation.vue 9.4 KB

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