shoppingCart.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <template>
  2. <view>
  3. <view style="background-color: #fff;padding: 20rpx;border-radius: 20rpx;">
  4. <view style="display: flex;justify-content: space-between;">
  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;">
  12. <view style="margin-right: 40rpx;">|</view>
  13. <view @click="editDel = !editDel">{{editDel?'取消':'编辑'}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <u-checkbox-group v-model="companyValue" placement="column" @change="companyChange">
  18. <view class="collection" v-for="(item,index) in dataList" :key="index">
  19. <view>
  20. <u-checkbox activeColor="#FD4B09" shape="circle" :customStyle="{marginBottom: '8px'}"
  21. :label="item.name" :name="item.name" labelSize="28rpx"></u-checkbox>
  22. </view>
  23. <view style="margin-left: 20rpx;display: flex;align-items: center;" v-for="(ite,ind) in item.list"
  24. :key="ind">
  25. <view>
  26. <image v-for="(li,inde) in ite.filesList" :key="inde" v-if="li.version === '0'" :src="li.url"
  27. style="width: 200rpx;height: 200rpx;border-radius: 20rpx;">
  28. </image>
  29. </view>
  30. <view class="goods">
  31. <u--text :text="ite.goodsName" size="24rpx" lines="2"></u--text>
  32. <view class="price">
  33. <view>¥{{ite.price}}</view>
  34. <view v-if="!editDel">
  35. <u-number-box v-model="ite.goodsNum" :min="1" :max="ite.inventory" buttonSize="40rpx"
  36. @change="(val)=>{statistics(val,index,ind)}"></u-number-box>
  37. </view>
  38. </view>
  39. </view>
  40. <view v-if="editDel">
  41. <u-icon name="minus-circle-fill" color="#ff0000" size="52rpx"
  42. @click="deleteGoods(ite.id)"></u-icon>
  43. </view>
  44. </view>
  45. </view>
  46. </u-checkbox-group>
  47. <view style="height: 120rpx;"></view>
  48. <view class="submitBar">
  49. <view class="bar_view">
  50. <view style="display: flex;align-items: center;">
  51. <view>
  52. <u-checkbox-group v-model="radiovalue" placement="column" @change="radioGroupChange">
  53. <u-checkbox label="全选" name="全选" activeColor="#FD4B09" shape="circle"></u-checkbox>
  54. </u-checkbox-group>
  55. </view>
  56. <view v-if="!editDel" style="margin-left: 20rpx;">
  57. <view>总计:¥<text>{{totalPrice}}</text></view>
  58. <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
  59. </view>
  60. </view>
  61. <view style="height: 120rpx;display: flex;color: #fff;">
  62. <view v-if="!editDel" class="lvbutton" @click="submit('W01')">他人代付</view>
  63. <view v-if="!editDel" class="redbutton" @click="submit('W06')">立即支付</view>
  64. <view v-else class="redbutton" @click="deleteShopping">删除</view>
  65. <!-- <u-button shape="circle" size="small" text="立即支付" v-if="!editDel"
  66. :disabled="this.selectedProduct.length == 0"
  67. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
  68. <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
  69. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button> -->
  70. </view>
  71. </view>
  72. </view>
  73. <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
  74. v-if="dataList.length == 0" mode="car" 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"
  80. :value="qrcodeurl"
  81. :options="{ margin: 5 }"></uqrcode>
  82. <!-- options 配置项 https://uqrcode.cn/doc/document/native.html#%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95 -->
  83. </view>
  84. <view>
  85. <!-- {{qrcodeData.contacts}} -->
  86. <view style="font-size: 34rpx;font-weight: 500;">{{qrcodeData.salesCompanyName}}</view>
  87. <view style="color: #9a9a9a;font-size: 26rpx;">
  88. <text>金额:</text>
  89. <text style="color: #FD4B09;font-size: 30rpx;">¥{{qrcodeData.salesAmount}}</text>
  90. </view>
  91. <view style="color: #9a9a9a;font-size: 26rpx;">二维码有效期: {{qrcodeData.businesDate}}</view>
  92. </view>
  93. </view>
  94. </u-popup>
  95. <!-- 提取去登录 -->
  96. <u-modal :show="adminShow" :showCancelButton="true" content='当前还未登录请先登录!!'
  97. @confirm="adminConfirm"
  98. @cancel="adminCancel" ></u-modal>
  99. <u-modal :show="inventoryShow" title="库存不足" :content='inventoryContent'
  100. @confirm="inventoryShow=false;inventoryContent='';companyValue=[]"></u-modal>
  101. </view>
  102. </template>
  103. <script>
  104. import {
  105. shoppingCartList,
  106. generateOrder,
  107. generateOrderLimit,
  108. shoppingCartUpdate,
  109. getCorpsAddr,
  110. paramserviceDetail
  111. } from '@/api/tabBar/shoppingCart.js'
  112. import { registerRuntimeCompiler } from "vue"
  113. import { details } from '@/api/views/personalInformation/index.js'
  114. import {appDetail} from'@/api/views/salesSlip/index.js'
  115. export default {
  116. data() {
  117. return {
  118. qrcodeshow:false, // 二维码弹窗
  119. qrcodeData:[], // 二维码数据
  120. qrcodeurl:'', // 二维码参数
  121. editDel: false,
  122. radiovalue: [],
  123. companyValue: [],
  124. dataList: [],
  125. companyValueLength: 0,
  126. selectedProduct: [],
  127. totalPrice: 0.00,
  128. totalFreight: 0.00,
  129. addres: {},
  130. checkStatus:null,
  131. adminShow:false,
  132. inventoryShow:false,
  133. inventoryContent:''
  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. this.statistics()
  146. }
  147. },
  148. onShow() {
  149. if(uni.getStorageSync('userInfo').tenant_id == '000000') {
  150. this.adminShow = true
  151. return
  152. }
  153. // 获取审核状态
  154. details().then(res => {
  155. this.checkStatus = res.data.checkStatus
  156. uni.setStorageSync('checkStatus', res.data.checkStatus);
  157. if (this.checkStatus != '通过') {
  158. // uni.showToast({
  159. // title: "当前用户未授权,请联系客服",
  160. // icon: "none",
  161. // mask:true
  162. // });
  163. uni.switchTab({
  164. url:'/pages/tabBar/home'
  165. })
  166. return
  167. }
  168. })
  169. this.editDel = false
  170. this.companyValue = []
  171. shoppingCartList().then(res => {
  172. this.dataList = res.data
  173. this.companyValueLength = this.dataList.length
  174. this.inventoryfun(res.data)
  175. })
  176. getCorpsAddr().then(res => {
  177. this.addres = res.data
  178. })
  179. // 支付成功之后的回调
  180. let options = wx.getEnterOptionsSync();
  181. if (options.scene == '1038' && options.referrerInfo.appId=='wxef277996acc166c3') {
  182. // 代表从收银台小程序返回
  183. let extraData = options.referrerInfo.extraData;
  184. if (!extraData) {
  185. // "当前通过物理按键返回,未接收到返参,建议自行查询交易结果";
  186. console.log('当前通过物理按键返回,未接收到返参,建议自行查询交易结果');
  187. } else {
  188. if (extraData.code == 'success') {
  189. // "支付成功";
  190. } else if (extraData.code == 'cancel') {
  191. // "支付已取消";
  192. console.log(extraData,'支付已取消');
  193. } else {
  194. console.log(extraData,'失败');
  195. // "支付失败:" + extraData.errmsg;
  196. }
  197. }
  198. }
  199. },
  200. methods: {
  201. // 库存弹窗
  202. inventoryfun(arr){
  203. let sum = ''
  204. arr.map((item,index)=>{
  205. item.list.map(ite=>{
  206. if (Number(ite.goodsNum) > Number(ite.inventory)) {
  207. sum += `${ite.goodsName}的库存数量为${ite.inventory},请修正数量后重新结算`
  208. }
  209. return ite
  210. })
  211. return item
  212. })
  213. if(sum != '') {
  214. this.inventoryContent = sum
  215. this.inventoryShow = true
  216. }
  217. },
  218. // admin确认
  219. adminConfirm(){
  220. uni.clearStorageSync();
  221. uni.redirectTo({
  222. url: '/pages/login/login'
  223. })
  224. },
  225. // admin取消
  226. adminCancel(){
  227. uni.switchTab({
  228. url: '/pages/tabBar/home'
  229. })
  230. },
  231. // 弹窗关闭
  232. qrcodeclose(){
  233. this.qrcodeshow = false
  234. uni.showLoading({
  235. title: '加载中',
  236. mask: true
  237. });
  238. // 详情调用
  239. shoppingCartList().then(res => {
  240. this.dataList = res.data
  241. this.companyValueLength = this.dataList.length
  242. uni.hideLoading();
  243. }).catch(err => {
  244. uni.hideLoading();
  245. })
  246. },
  247. clickAddress() {
  248. this.$u.route('/pages/views/personalInformation/addressManagement');
  249. },
  250. deleteGoods(val) {
  251. uni.showLoading({
  252. title: '加载中',
  253. mask: true
  254. });
  255. shoppingCartUpdate({
  256. ids: val
  257. }).then(res => {
  258. uni.showToast({
  259. title: "删除成功",
  260. icon: 'none'
  261. });
  262. uni.showLoading({
  263. title: '加载中',
  264. mask: true
  265. });
  266. this.editDel = false
  267. this.companyValue = []
  268. shoppingCartList().then(res => {
  269. this.dataList = res.data
  270. this.companyValueLength = this.dataList.length
  271. uni.hideLoading();
  272. }).catch(err => {
  273. uni.hideLoading();
  274. })
  275. uni.hideLoading();
  276. }).catch(err => {
  277. uni.hideLoading();
  278. })
  279. },
  280. deleteShopping() {
  281. if (this.selectedProduct.length == 0) {
  282. uni.showToast({
  283. title: "请先选择要支付的商品",
  284. icon: 'none'
  285. });
  286. return
  287. }
  288. let data = []
  289. for (let item of this.companyValue) {
  290. for (let ite of this.dataList) {
  291. if (item == ite.name) {
  292. for (let it of ite.list) {
  293. data.push(it.id)
  294. }
  295. }
  296. }
  297. }
  298. uni.showLoading({
  299. title: '加载中',
  300. mask: true
  301. });
  302. shoppingCartUpdate({
  303. ids: data.join(',')
  304. }).then(res => {
  305. uni.showToast({
  306. title: "删除成功",
  307. icon: 'none'
  308. });
  309. uni.hideLoading();
  310. uni.showLoading({
  311. title: '加载中',
  312. mask: true
  313. });
  314. this.editDel = false
  315. this.companyValue = []
  316. shoppingCartList().then(res => {
  317. this.dataList = res.data
  318. this.companyValueLength = this.dataList.length
  319. uni.hideLoading();
  320. }).catch(err => {
  321. uni.hideLoading();
  322. })
  323. }).catch(err => {
  324. uni.hideLoading();
  325. })
  326. },
  327. // 立即支付
  328. async submit(payType) {
  329. if (this.selectedProduct.length == 0) {
  330. uni.showToast({
  331. title: "请先选择要支付的商品",
  332. icon: 'none'
  333. });
  334. return
  335. }
  336. if (this.companyValue.length > 0) {
  337. let data = []
  338. for (let item of this.companyValue) {
  339. for (let ite of this.dataList) {
  340. if (item == ite.name) {
  341. data.push({
  342. name: item,
  343. list: ite.list
  344. })
  345. }
  346. }
  347. }
  348. uni.showLoading({
  349. title: '加载中',
  350. mask: true
  351. });
  352. // 判断是否用额度支付
  353. const personRef = await details()
  354. console.log(personRef.data,349);
  355. const totalPrice = Number(this.totalPrice) + Number(this.totalFreight)
  356. // 是否开通额度
  357. if (personRef.data.ifLimitAmount == 1) {
  358. // 额度是否够用
  359. if (Number(personRef.data.limitAmount >= totalPrice)) {
  360. // 额度
  361. generateOrderLimit({
  362. payType:payType,
  363. address: this.addres.belongtoarea + this.addres.detailedAddress,
  364. list: data,
  365. }).then(res=>{
  366. uni.hideLoading();
  367. uni.showToast({
  368. title: '支付成功',
  369. mask: true,
  370. duration: 2000
  371. });
  372. setTimeout(function() {
  373. uni.hideLoading();
  374. }, 1000);
  375. // 详情调用
  376. shoppingCartList().then(res => {
  377. this.dataList = res.data
  378. this.companyValueLength = this.dataList.length
  379. }).catch(err => {})
  380. })
  381. return
  382. }
  383. }
  384. // 正常支付
  385. generateOrder({
  386. payType:payType,
  387. address: this.addres.belongtoarea + this.addres.detailedAddress,
  388. list: data,
  389. }).then(res => {
  390. let generateOrderData = res.data
  391. paramserviceDetail({
  392. paramKey:'cashier.payment'
  393. }).then(res=>{
  394. let paramservice = res.data
  395. // 判断是调支付台的接口还是微信支付的接口
  396. if (paramservice && paramservice.paramValue == '1') {
  397. // uni.hideLoading();
  398. let obj = {
  399. appId: 'wxef277996acc166c3',
  400. extraData: {
  401. cusid: generateOrderData.cusid,
  402. appid: generateOrderData.appid,
  403. orgid: generateOrderData.orgid,
  404. version: generateOrderData.version,
  405. trxamt: generateOrderData.trxamt,
  406. reqsn: generateOrderData.reqsn,
  407. notify_url: generateOrderData.notify_url,
  408. body: generateOrderData.body,
  409. remark: generateOrderData.remark,
  410. validtime: generateOrderData.validtime,
  411. limit_pay: generateOrderData.limit_pay,
  412. randomstr: generateOrderData.randomstr,
  413. paytype: generateOrderData.paytype,
  414. signtype:generateOrderData.signtype,
  415. sign: generateOrderData.sign,
  416. },
  417. }
  418. console.log(obj);
  419. if (!generateOrderData.reqsn) {
  420. uni.showToast({
  421. title: '当前订单号为空,请联系供应商!!!',
  422. icon:'none',
  423. mask: true,
  424. duration: 2000
  425. });
  426. // 详情调用
  427. shoppingCartList().then(res => {
  428. this.dataList = res.data
  429. this.companyValueLength = this.dataList.length
  430. }).catch(err => {})
  431. return
  432. }
  433. wx.openEmbeddedMiniProgram({
  434. appId: 'wxef277996acc166c3',
  435. extraData: {
  436. cusid: generateOrderData.cusid,
  437. appid: generateOrderData.appid,
  438. orgid: generateOrderData.orgid,
  439. version: generateOrderData.version,
  440. trxamt: generateOrderData.trxamt,
  441. reqsn: generateOrderData.reqsn,
  442. notify_url: generateOrderData.notify_url,
  443. body: generateOrderData.body,
  444. remark: generateOrderData.remark,
  445. validtime: generateOrderData.validtime,
  446. // limit_pay: generateOrderData.limit_pay,
  447. limit_pay:"",
  448. randomstr: generateOrderData.randomstr,
  449. paytype: generateOrderData.paytype,
  450. signtype:generateOrderData.signtype,
  451. sign: generateOrderData.sign,
  452. },
  453. success:(a)=>{
  454. uni.hideLoading();
  455. },
  456. fail:(err)=>{
  457. uni.hideLoading();
  458. }
  459. })
  460. }else {
  461. if (payType && (payType == 'W01' || payType == 'U01' || payType == 'A01' || payType == 'S01')) {
  462. console.log(generateOrderData,321);
  463. // 订单详情接口
  464. this.qrcodeurl = generateOrderData.url
  465. appDetail({id:generateOrderData.id}).then(res=>{
  466. uni.hideLoading();
  467. this.qrcodeshow = true
  468. this.qrcodeData = res.data
  469. console.log(res.data);
  470. })
  471. }else {
  472. uni.requestPayment({
  473. provider: "wxpay",
  474. appId:generateOrderData.appId,
  475. timeStamp: generateOrderData.timeStamp,
  476. nonceStr: generateOrderData.nonceStr,
  477. package: generateOrderData.package,
  478. signType: generateOrderData.signType,
  479. paySign: generateOrderData.paySign,
  480. success(res) {
  481. uni.showToast({
  482. title: '支付成功',
  483. mask: true,
  484. duration: 2000
  485. });
  486. setTimeout(function() {
  487. uni.hideLoading();
  488. // this_.refresh(res.data.data.id)
  489. }, 1000);
  490. },
  491. fail(e) {
  492. console.log(e);
  493. uni.showToast({
  494. title: "支付失败",
  495. icon: 'none',
  496. mask: true
  497. });
  498. setTimeout(function() {
  499. uni.hideLoading();
  500. // this_.refresh(res.data.id)
  501. }, 1000);
  502. }
  503. })
  504. }
  505. }
  506. })
  507. }).catch(err => {
  508. uni.hideLoading();
  509. })
  510. }
  511. },
  512. radioGroupChange(e) {
  513. this.radiovalue = e
  514. if (e.length == 0) {
  515. this.companyValue = []
  516. } else {
  517. for (let li of this.dataList) {
  518. if (!this.companyValue.includes(li.name)) {
  519. this.companyValue.push(li.name)
  520. }
  521. }
  522. }
  523. this.inventoryfun(this.dataList)
  524. this.statistics()
  525. },
  526. statistics(val, index, ind) {
  527. if (val) {
  528. this.dataList[index].list[ind].goodsNum = val.value
  529. }
  530. let data = []
  531. // for (let item of this.companyValue) {
  532. // for (let ite of this.dataList) {
  533. // if (item == ite.name) {
  534. // for (let it of ite.list) {
  535. // data.push(it)
  536. // }
  537. // }
  538. // }
  539. // }、
  540. for (let item of this.companyValue) {
  541. for (let ite of this.dataList) {
  542. if (item == ite.name) {
  543. data.push({
  544. name: item,
  545. list: ite.list
  546. })
  547. }
  548. }
  549. }
  550. this.totalPrice = 0
  551. this.totalFreight = 0
  552. let num = 0
  553. for (let item of data) {
  554. let num1 = 0
  555. for (let items of item.list) {
  556. this.totalPrice += Number(items.price) * Number(items.goodsNum)
  557. num += Number(items.goodsNum)
  558. num1 += Number(items.goodsNum)
  559. }
  560. if (num1 == 1) {
  561. this.totalFreight += 5
  562. }
  563. }
  564. /* if(num>1){
  565. this.totalFreight = 0
  566. } */
  567. this.totalFreight = this.totalFreight.toFixed(2)
  568. this.totalPrice = this.totalPrice.toFixed(2)
  569. this.selectedProduct = data
  570. },
  571. companyChange(n) {
  572. this.companyValue = n
  573. this.inventoryfun(this.dataList)
  574. }
  575. }
  576. }
  577. </script>
  578. <style lang="scss" scoped>
  579. .collection {
  580. background-color: #fff;
  581. padding: 20rpx;
  582. border-radius: 20rpx;
  583. margin-top: 20rpx;
  584. }
  585. .goods {
  586. width: 100%;
  587. margin-left: 20rpx;
  588. height: 200rpx;
  589. display: grid;
  590. align-content: space-between;
  591. .price {
  592. display: flex;
  593. justify-content: space-between !important;
  594. margin-top: 20rpx;
  595. align-items: center;
  596. view:nth-child(1) {
  597. color: #FD4B09;
  598. font-size: 40rpx;
  599. }
  600. }
  601. }
  602. .submitBar {
  603. position: fixed;
  604. bottom: 0;
  605. background-color: #fff;
  606. width: 100%;
  607. z-index: 10;
  608. .bar_view {
  609. display: flex;
  610. justify-content: space-between;
  611. align-items: center;
  612. // padding: 10rpx;
  613. }
  614. }
  615. .redbutton {
  616. background-color: #FD4B09;
  617. height: 120rpx;
  618. line-height: 120rpx;
  619. width: 200rpx;
  620. text-align: center;
  621. }
  622. .lvbutton {
  623. background-color: #4c9e44;
  624. height: 120rpx;
  625. line-height: 120rpx;
  626. width: 200rpx;
  627. text-align: center;
  628. }
  629. </style>