obligation.vue 15 KB

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