obligation.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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 class="dingbox">
  25. <view v-if="ite.payType && ite.payType.indexOf('01') != -1">扫码支付</view>
  26. <view v-else>微信支付</view>
  27. </view>
  28. <view>
  29. <image v-for="(li,inde) in ite.orderItemsList" :key="inde" :src="li.goodsFilesList[0].url"
  30. style="width: 200rpx;height: 200rpx;border-radius: 20rpx;">
  31. </image>
  32. </view>
  33. <view class="goods" >
  34. <u--text v-for="(ites,inds) in ite.orderItemsList" :key="inds" :text="ites.goodsName" size="24rpx" lines="2"></u--text>
  35. <view class="price" v-for="(ites,inds) in ite.orderItemsList" :key="inds">
  36. <view>¥{{ites.price}}</view>
  37. <view v-if="!editDel">
  38. <u-number-box v-model="ites.goodsNum" :min="1" :max="ites.goodsNum" buttonSize="40rpx"
  39. @change="(val)=>{statistics(val,index,ind)}"></u-number-box>
  40. </view>
  41. </view>
  42. </view>
  43. <view v-if="editDel">
  44. <u-icon name="minus-circle-fill" color="#ff0000" size="52rpx"
  45. @click="deleteGoods(ite.id)"></u-icon>
  46. </view>
  47. </view>
  48. </view>
  49. </u-checkbox-group>
  50. <view style="height: 100rpx;"></view>
  51. <view class="submitBar" style="padding-bottom: env(safe-area-inset-bottom);">
  52. <view class="bar_view">
  53. <view v-if="!editDel" style="margin-left: 20rpx;">
  54. <view>总计:¥<text>{{totalPrice}}</text></view>
  55. <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
  56. </view>
  57. <view style="height: 120rpx;display: flex;color: #fff;">
  58. <!-- <view v-if="!editDel" class="lvbutton" @click="submit('W01')">他人代付</view> -->
  59. <view v-if="!editDel" class="redbutton" @click="submit()">立即支付</view>
  60. <view v-else class="redbutton" @click="deleteShopping">删除</view>
  61. </view>
  62. <!-- <view style="width: 200rpx;">
  63. <u-button shape="circle" size="small" text="立即支付" v-if="!editDel"
  64. :disabled="this.selectedProduct.length == 0"
  65. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
  66. <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
  67. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button>
  68. </view> -->
  69. </view>
  70. </view>
  71. <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
  72. v-if="dataList.length == 0 && !isLoading" mode="car" text="待付款为空" icon="http://cdn.uviewui.com/uview/empty/car.png" />
  73. <u-popup :show="qrcodeshow" mode="center" :closeable="true" @close="qrcodeclose" >
  74. <view style="padding: 20rpx;">
  75. <view style="font-size: 26rpx;">截屏二维码支付</view>
  76. <view>
  77. <uqrcode ref="uqrcode" canvas-id="qrcode" size="600" sizeUnit="rpx"
  78. :value="qrcodeurl"
  79. :options="{ margin: 5 }"></uqrcode>
  80. <!-- options 配置项 https://uqrcode.cn/doc/document/native.html#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95 -->
  81. </view>
  82. <view>
  83. <!-- {{qrcodeData.contacts}} -->
  84. <view style="font-size: 34rpx;font-weight: 500;">{{qrcodeData.salesCompanyName}}</view>
  85. <view style="color: #9a9a9a;font-size: 26rpx;">
  86. <text>金额:</text>
  87. <text style="color: #FD4B09;font-size: 30rpx;">¥{{qrcodeData.salesAmount}}</text>
  88. </view>
  89. <view style="color: #9a9a9a;font-size: 26rpx;">二维码有效期: {{qrcodeData.businesDate}}</view>
  90. </view>
  91. </view>
  92. </u-popup>
  93. </view>
  94. </template>
  95. <script>
  96. import {
  97. obligationList,
  98. generateOrder,
  99. payPrepay,
  100. shoppingCartUpdate,
  101. getCorpsAddr,
  102. update,
  103. paramserviceDetail
  104. } from '@/api/tabBar/shoppingCart.js'
  105. import { registerRuntimeCompiler } from "vue"
  106. import { logo } from '../../../common/setting'
  107. import {appDetail} from'@/api/views/salesSlip/index.js'
  108. import {dateFormat} from '@/common/dateFormat.js'
  109. export default {
  110. data() {
  111. return {
  112. qrcodeshow:false, // 二维码弹窗
  113. qrcodeData:[], // 二维码数据
  114. qrcodeurl:'', // 二维码参数
  115. editDel: false,
  116. radiovalue: [],
  117. companyValue: [],
  118. dataList: [],
  119. companyValueLength: 0,
  120. selectedProduct: [],
  121. totalPrice: 0.00,
  122. totalFreight: 0.00,
  123. addres: {},
  124. isLoading: true
  125. }
  126. },
  127. watch: {
  128. companyValue() {
  129. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  130. if (this.companyValue.length == this.companyValueLength) {
  131. this.radiovalue = ["全选"]
  132. } else {
  133. this.radiovalue = []
  134. }
  135. }
  136. // if (this.companyValue.length > 0) {
  137. // console.log(21321324);
  138. // // if (this.companyValue.length == this.companyValueLength) {
  139. // // this.radiovalue = ["全选"]
  140. // // } else {
  141. // // this.radiovalue = []
  142. // // }
  143. // }
  144. this.statistics()
  145. }
  146. },
  147. onLoad() {
  148. console.log(Date.parse('2023-11-22 00:00:00') + 60 * 60 * 1000);
  149. console.log(dateFormat(new Date(Date.parse('2023-11-22 00:00:00') + 60 * 60 * 1000)),155);
  150. },
  151. onShow() {
  152. this.editDel = false
  153. this.companyValue = []
  154. this.isLoading = true
  155. obligationList().then(res => {
  156. console.log(res);
  157. this.dataList = res.data
  158. this.companyValueLength = this.dataList.length
  159. this.isLoading = false // 添加这一行
  160. })
  161. getCorpsAddr().then(res => {
  162. this.addres = res.data
  163. })
  164. },
  165. methods: {
  166. // 弹窗关闭
  167. qrcodeclose(){
  168. this.qrcodeshow = false
  169. },
  170. deleteGoods(val) {
  171. console.log(val);
  172. uni.showLoading({
  173. title: '加载中',
  174. mask: true
  175. });
  176. update(val).then(res => {
  177. uni.showToast({
  178. title: "删除成功",
  179. icon: 'none'
  180. });
  181. uni.showLoading({
  182. title: '加载中',
  183. mask: true
  184. });
  185. this.editDel = false
  186. this.companyValue = []
  187. obligationList().then(res => {
  188. this.dataList = res.data
  189. this.companyValueLength = this.dataList.length
  190. uni.hideLoading();
  191. }).catch(err => {
  192. uni.hideLoading();
  193. })
  194. uni.hideLoading();
  195. }).catch(err => {
  196. uni.hideLoading();
  197. })
  198. },
  199. deleteShopping() {
  200. if (this.selectedProduct.length == 0) {
  201. uni.showToast({
  202. title: "请先选择要支付的商品",
  203. icon: 'none'
  204. });
  205. return
  206. }
  207. let data = []
  208. for (let item of this.companyValue) {
  209. for (let ite of this.dataList) {
  210. if (item == ite.name) {
  211. for (let it of ite.list) {
  212. data.push(it.id)
  213. }
  214. }
  215. }
  216. };
  217. console.log(data.join(","));
  218. uni.showLoading({
  219. title: '加载中',
  220. mask: true
  221. });
  222. update(data.join(",")).then(res => {
  223. uni.showToast({
  224. title: "删除成功",
  225. icon: 'none'
  226. });
  227. uni.hideLoading();
  228. uni.showLoading({
  229. title: '加载中',
  230. mask: true
  231. });
  232. this.editDel = false
  233. this.companyValue = []
  234. obligationList().then(res => {
  235. this.dataList = res.data
  236. this.companyValueLength = this.dataList.length
  237. uni.hideLoading();
  238. }).catch(err => {
  239. uni.hideLoading();
  240. })
  241. }).catch(err => {
  242. uni.hideLoading();
  243. })
  244. },
  245. submit(payType) {
  246. if (this.selectedProduct.length == 0) {
  247. uni.showToast({
  248. title: "请先选择要支付的商品",
  249. icon: 'none'
  250. });
  251. return
  252. }
  253. for(let item of this.selectedProduct) {
  254. if (!item.payType) return uni.showToast({title: "当前订单支付方式异常,请重新购买",icon: 'none',duration: 2500});
  255. if (item.payType && item.payType == 'W06') {
  256. // 微信支付
  257. }else {
  258. // 扫码支付
  259. let i = 0
  260. let j = 0
  261. this.selectedProduct.forEach((item,index)=>{
  262. if (item.payType && item.payType.indexOf('01') != -1) {
  263. i++
  264. }else {
  265. j++
  266. }
  267. })
  268. if (j != 0) {
  269. uni.showToast({
  270. title: "请选择相同的支付方式",
  271. icon: 'none'
  272. });
  273. return
  274. }
  275. if(i > 1) {
  276. uni.showToast({
  277. title: "扫码支付只能选择一个",
  278. icon: 'none'
  279. });
  280. return
  281. }
  282. }
  283. }
  284. if (this.companyValue.length > 0) {
  285. let data = []
  286. for (let item of this.companyValue) {
  287. for (let ite of this.dataList) {
  288. if (item == ite.name) {
  289. data.push({
  290. name: item,
  291. })
  292. }
  293. }
  294. }
  295. console.log('data',data);
  296. uni.showLoading({
  297. title: '加载中',
  298. mask: true
  299. });
  300. payPrepay({srcOrderNo:data[0].name}).then(res => {
  301. let generateOrderData = res.data
  302. paramserviceDetail({
  303. paramKey:'cashier.payment'
  304. }).then(res=>{
  305. let paramservice = res.data
  306. // 判断是调支付台的接口还是微信支付的接口
  307. if (paramservice && paramservice.paramValue == '1') {
  308. wx.openEmbeddedMiniProgram({
  309. appId: 'wxef277996acc166c3',
  310. extraData: {
  311. cusid: generateOrderData.cusid,
  312. appid: generateOrderData.appid,
  313. orgid: generateOrderData.orgid,
  314. version: generateOrderData.version,
  315. trxamt: generateOrderData.trxamt,
  316. reqsn: generateOrderData.reqsn,
  317. notify_url: generateOrderData.notify_url,
  318. body: generateOrderData.body,
  319. remark: generateOrderData.remark,
  320. validtime: generateOrderData.validtime,
  321. limit_pay: generateOrderData.limit_pay,
  322. randomstr: generateOrderData.randomstr,
  323. paytype: generateOrderData.paytype,
  324. signtype:generateOrderData.signtype,
  325. sign: generateOrderData.sign,
  326. },
  327. success:(a)=>{
  328. uni.hideLoading();
  329. },
  330. fail:(err)=>{
  331. uni.hideLoading();
  332. }
  333. })
  334. }else {
  335. if (this.selectedProduct[0].payType &&
  336. (this.selectedProduct[0].payType == 'W01' || this.selectedProduct[0].payType == 'U01' || this.selectedProduct[0].payType == 'A01' || this.selectedProduct[0].payType == 'S01')) {
  337. this.qrcodeurl = this.selectedProduct[0].payUrl
  338. appDetail({id:this.selectedProduct[0].id}).then(res=>{
  339. uni.hideLoading();
  340. this.qrcodeshow = true
  341. this.qrcodeData = res.data
  342. // 往后延长一小时
  343. this.qrcodeData.businesDate = dateFormat(new Date(Date.parse(this.qrcodeData.businesDate) + 60 * 60 * 1000))
  344. })
  345. }else {
  346. uni.requestPayment({
  347. provider: "wxpay",
  348. appId:generateOrderData.appId,
  349. timeStamp: generateOrderData.timeStamp,
  350. nonceStr: generateOrderData.nonceStr,
  351. package: generateOrderData.package,
  352. signType: generateOrderData.signType,
  353. paySign: generateOrderData.paySign,
  354. success(res) {
  355. uni.showToast({
  356. title: '支付成功',
  357. mask: true,
  358. duration: 2000
  359. });
  360. setTimeout(function() {
  361. uni.hideLoading();
  362. // this_.refresh(res.data.data.id)
  363. }, 1000);
  364. },
  365. fail(e) {
  366. console.log(e);
  367. uni.showToast({
  368. title: "支付失败",
  369. icon: 'none',
  370. mask: true
  371. });
  372. setTimeout(function() {
  373. uni.hideLoading();
  374. // this_.refresh(res.data.id)
  375. }, 1000);
  376. }
  377. })
  378. }
  379. }
  380. })
  381. // uni.showToast({
  382. // title: "提交成功",
  383. // icon: 'none'
  384. // });
  385. // uni.hideLoading();
  386. // uni.showLoading({
  387. // title: '加载中',
  388. // mask: true
  389. // });
  390. // this.editDel = false
  391. // this.companyValue = []
  392. // shoppingCartList().then(res => {
  393. // this.dataList = res.data
  394. // this.companyValueLength = this.dataList.length
  395. // uni.hideLoading();
  396. // }).catch(err => {
  397. // uni.hideLoading();
  398. // })
  399. }).catch(err => {
  400. uni.hideLoading();
  401. })
  402. }
  403. },
  404. radioGroupChange(e) {
  405. this.radiovalue = e
  406. if (e.length == 0) {
  407. this.companyValue = []
  408. } else {
  409. for (let li of this.dataList) {
  410. if (!this.companyValue.includes(li.name)) {
  411. this.companyValue.push(li.name)
  412. }
  413. }
  414. }
  415. this.statistics()
  416. },
  417. statistics(val, index, ind) {
  418. if (val) {
  419. this.dataList[index].list[ind].goodsNum = val.value
  420. }
  421. let data = []
  422. for (let item of this.companyValue) {
  423. for (let ite of this.dataList) {
  424. if (item == ite.name) {
  425. for (let it of ite.list) {
  426. data.push(it)
  427. }
  428. }
  429. }
  430. }
  431. console.log(data);
  432. this.totalPrice = 0
  433. this.totalFreight = 0
  434. for (let item of data) {
  435. for(let orderItem of item.orderItemsList){
  436. this.totalPrice += Number(orderItem.price) * Number(orderItem.goodsNum)
  437. console.log(orderItem.goodsNum);
  438. if (Number(orderItem.goodsNum) == 1) {
  439. this.totalFreight += 5
  440. }
  441. }
  442. }
  443. this.totalFreight = this.totalFreight.toFixed(2)
  444. this.totalPrice = this.totalPrice.toFixed(2)
  445. this.selectedProduct = data
  446. },
  447. companyChange(n) {
  448. this.companyValue = n
  449. }
  450. }
  451. }
  452. </script>
  453. <style lang="scss" scoped>
  454. .collection {
  455. background-color: #fff;
  456. padding: 20rpx;
  457. border-radius: 20rpx;
  458. margin-top: 20rpx;
  459. position: relative;
  460. .dingbox {
  461. position: absolute;
  462. top: 20rpx;
  463. right: 20rpx;
  464. font-size: 26rpx;
  465. color: #FD4B09;
  466. }
  467. }
  468. .goods {
  469. width: 100%;
  470. margin-left: 20rpx;
  471. height: 200rpx;
  472. display: grid;
  473. align-content: space-between;
  474. .price {
  475. display: flex;
  476. justify-content: space-between !important;
  477. margin-top: 20rpx;
  478. align-items: center;
  479. view:nth-child(1) {
  480. color: #FD4B09;
  481. font-size: 40rpx;
  482. }
  483. }
  484. }
  485. .submitBar {
  486. position: fixed;
  487. bottom: 0;
  488. background-color: #fff;
  489. width: 100%;
  490. z-index: 10;
  491. .bar_view {
  492. display: flex;
  493. justify-content: space-between;
  494. align-items: center;
  495. // padding: 10rpx;
  496. }
  497. }
  498. .redbutton {
  499. background-color: #FD4B09;
  500. height: 120rpx;
  501. line-height: 120rpx;
  502. width: 200rpx;
  503. text-align: center;
  504. }
  505. .lvbutton {
  506. background-color: #4c9e44;
  507. height: 120rpx;
  508. line-height: 120rpx;
  509. width: 200rpx;
  510. text-align: center;
  511. }
  512. </style>