obligation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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.goodsFilesList[0].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" :key="inds" :text="ites.goodsName" size="24rpx" lines="2"></u--text>
  31. <view class="price" v-for="(ites,inds) in ite.orderItemsList" :key="inds">
  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" style="padding-bottom: env(safe-area-inset-bottom);">
  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. paramserviceDetail
  75. } from '@/api/tabBar/shoppingCart.js'
  76. import { registerRuntimeCompiler } from "vue"
  77. import { logo } from '../../../common/setting'
  78. export default {
  79. data() {
  80. return {
  81. editDel: false,
  82. radiovalue: [],
  83. companyValue: [],
  84. dataList: [],
  85. companyValueLength: 0,
  86. selectedProduct: [],
  87. totalPrice: 0.00,
  88. totalFreight: 0.00,
  89. addres: {},
  90. isLoading: true
  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. // if (this.companyValue.length > 0) {
  103. // console.log(21321324);
  104. // // if (this.companyValue.length == this.companyValueLength) {
  105. // // this.radiovalue = ["全选"]
  106. // // } else {
  107. // // this.radiovalue = []
  108. // // }
  109. // }
  110. this.statistics()
  111. }
  112. },
  113. onShow() {
  114. this.editDel = false
  115. this.companyValue = []
  116. this.isLoading = true
  117. obligationList().then(res => {
  118. console.log(res);
  119. this.dataList = res.data
  120. this.companyValueLength = this.dataList.length
  121. this.isLoading = false // 添加这一行
  122. })
  123. getCorpsAddr().then(res => {
  124. this.addres = res.data
  125. })
  126. },
  127. methods: {
  128. deleteGoods(val) {
  129. console.log(val);
  130. uni.showLoading({
  131. title: '加载中',
  132. mask: true
  133. });
  134. update(val).then(res => {
  135. uni.showToast({
  136. title: "删除成功",
  137. icon: 'none'
  138. });
  139. uni.showLoading({
  140. title: '加载中',
  141. mask: true
  142. });
  143. this.editDel = false
  144. this.companyValue = []
  145. obligationList().then(res => {
  146. this.dataList = res.data
  147. this.companyValueLength = this.dataList.length
  148. uni.hideLoading();
  149. }).catch(err => {
  150. uni.hideLoading();
  151. })
  152. uni.hideLoading();
  153. }).catch(err => {
  154. uni.hideLoading();
  155. })
  156. },
  157. deleteShopping() {
  158. let data = []
  159. for (let item of this.companyValue) {
  160. for (let ite of this.dataList) {
  161. if (item == ite.name) {
  162. for (let it of ite.list) {
  163. data.push(it.id)
  164. }
  165. }
  166. }
  167. };
  168. console.log(data.join(","));
  169. uni.showLoading({
  170. title: '加载中',
  171. mask: true
  172. });
  173. update(data.join(",")).then(res => {
  174. uni.showToast({
  175. title: "删除成功",
  176. icon: 'none'
  177. });
  178. uni.hideLoading();
  179. uni.showLoading({
  180. title: '加载中',
  181. mask: true
  182. });
  183. this.editDel = false
  184. this.companyValue = []
  185. obligationList().then(res => {
  186. this.dataList = res.data
  187. this.companyValueLength = this.dataList.length
  188. uni.hideLoading();
  189. }).catch(err => {
  190. uni.hideLoading();
  191. })
  192. }).catch(err => {
  193. uni.hideLoading();
  194. })
  195. },
  196. submit() {
  197. if (this.companyValue.length > 0) {
  198. let data = []
  199. for (let item of this.companyValue) {
  200. for (let ite of this.dataList) {
  201. if (item == ite.name) {
  202. data.push({
  203. name: item,
  204. })
  205. }
  206. }
  207. }
  208. console.log('data',data);
  209. uni.showLoading({
  210. title: '加载中',
  211. mask: true
  212. });
  213. payPrepay({srcOrderNo:data[0].name}).then(res => {
  214. let generateOrderData = res.data
  215. paramserviceDetail({
  216. paramKey:'cashier.payment'
  217. }).then(res=>{
  218. let paramservice = res.data
  219. // 判断是调支付台的接口还是微信支付的接口
  220. if (paramservice.paramValue == '1') {
  221. wx.openEmbeddedMiniProgram({
  222. appId: 'wxef277996acc166c3',
  223. extraData: {
  224. cusid: generateOrderData.cusid,
  225. appid: generateOrderData.appid,
  226. orgid: generateOrderData.orgid,
  227. version: generateOrderData.version,
  228. trxamt: generateOrderData.trxamt,
  229. reqsn: generateOrderData.reqsn,
  230. notify_url: generateOrderData.notify_url,
  231. body: generateOrderData.body,
  232. remark: generateOrderData.remark,
  233. validtime: generateOrderData.validtime,
  234. limit_pay: generateOrderData.limit_pay,
  235. randomstr: generateOrderData.randomstr,
  236. paytype: generateOrderData.paytype,
  237. signtype:generateOrderData.signtype,
  238. sign: generateOrderData.sign,
  239. },
  240. success:(a)=>{
  241. uni.hideLoading();
  242. },
  243. fail:(err)=>{
  244. uni.hideLoading();
  245. }
  246. })
  247. }else {
  248. uni.requestPayment({
  249. provider: "wxpay",
  250. appId:generateOrderData.appId,
  251. timeStamp: generateOrderData.timeStamp,
  252. nonceStr: generateOrderData.nonceStr,
  253. package: generateOrderData.package,
  254. signType: generateOrderData.signType,
  255. paySign: generateOrderData.paySign,
  256. success(res) {
  257. uni.showToast({
  258. title: '支付成功',
  259. mask: true,
  260. duration: 2000
  261. });
  262. setTimeout(function() {
  263. uni.hideLoading();
  264. // this_.refresh(res.data.data.id)
  265. }, 1000);
  266. },
  267. fail(e) {
  268. console.log(e);
  269. uni.showToast({
  270. title: "支付失败",
  271. icon: 'none',
  272. mask: true
  273. });
  274. setTimeout(function() {
  275. uni.hideLoading();
  276. // this_.refresh(res.data.id)
  277. }, 1000);
  278. }
  279. })
  280. }
  281. })
  282. // uni.showToast({
  283. // title: "提交成功",
  284. // icon: 'none'
  285. // });
  286. // uni.hideLoading();
  287. // uni.showLoading({
  288. // title: '加载中',
  289. // mask: true
  290. // });
  291. // this.editDel = false
  292. // this.companyValue = []
  293. // shoppingCartList().then(res => {
  294. // this.dataList = res.data
  295. // this.companyValueLength = this.dataList.length
  296. // uni.hideLoading();
  297. // }).catch(err => {
  298. // uni.hideLoading();
  299. // })
  300. }).catch(err => {
  301. uni.hideLoading();
  302. })
  303. }
  304. },
  305. radioGroupChange(e) {
  306. this.radiovalue = e
  307. if (e.length == 0) {
  308. this.companyValue = []
  309. } else {
  310. for (let li of this.dataList) {
  311. if (!this.companyValue.includes(li.name)) {
  312. this.companyValue.push(li.name)
  313. }
  314. }
  315. }
  316. this.statistics()
  317. },
  318. statistics(val, index, ind) {
  319. if (val) {
  320. this.dataList[index].list[ind].goodsNum = val.value
  321. }
  322. let data = []
  323. for (let item of this.companyValue) {
  324. for (let ite of this.dataList) {
  325. if (item == ite.name) {
  326. for (let it of ite.list) {
  327. data.push(it)
  328. }
  329. }
  330. }
  331. }
  332. console.log(data);
  333. this.totalPrice = 0
  334. this.totalFreight = 0
  335. for (let item of data) {
  336. for(let orderItem of item.orderItemsList){
  337. this.totalPrice += Number(orderItem.price) * Number(orderItem.goodsNum)
  338. console.log(orderItem.goodsNum);
  339. if (Number(orderItem.goodsNum) == 1) {
  340. this.totalFreight += 5
  341. }
  342. }
  343. }
  344. this.totalFreight = this.totalFreight.toFixed(2)
  345. this.totalPrice = this.totalPrice.toFixed(2)
  346. this.selectedProduct = data
  347. },
  348. companyChange(n) {
  349. this.companyValue = n
  350. }
  351. }
  352. }
  353. </script>
  354. <style lang="scss" scoped>
  355. .collection {
  356. background-color: #fff;
  357. padding: 20rpx;
  358. border-radius: 20rpx;
  359. margin-top: 20rpx;
  360. }
  361. .goods {
  362. width: 100%;
  363. margin-left: 20rpx;
  364. height: 200rpx;
  365. display: grid;
  366. align-content: space-between;
  367. .price {
  368. display: flex;
  369. justify-content: space-between !important;
  370. margin-top: 20rpx;
  371. align-items: center;
  372. view:nth-child(1) {
  373. color: #FD4B09;
  374. font-size: 40rpx;
  375. }
  376. }
  377. }
  378. .submitBar {
  379. position: fixed;
  380. bottom: 0;
  381. background-color: #fff;
  382. width: 100%;
  383. z-index: 10;
  384. .bar_view {
  385. display: flex;
  386. justify-content: space-between;
  387. align-items: center;
  388. padding: 10rpx;
  389. }
  390. }
  391. </style>