obligation.vue 13 KB

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