shoppingCart.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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: 100rpx;"></view>
  48. <view class="submitBar">
  49. <view class="bar_view">
  50. <view>
  51. <u-checkbox-group v-model="radiovalue" placement="column" @change="radioGroupChange">
  52. <u-checkbox label="全选" name="全选" activeColor="#FD4B09" shape="circle"></u-checkbox>
  53. </u-checkbox-group>
  54. </view>
  55. <view v-if="!editDel">
  56. <view>总计:¥<text>{{totalPrice}}</text></view>
  57. <view style="font-size: 22rpx;color: #FD4B09;">运费:¥{{totalFreight}}</view>
  58. </view>
  59. <view style="width: 200rpx;">
  60. <u-button shape="circle" size="small" text="立即支付" v-if="!editDel"
  61. :disabled="this.selectedProduct.length == 0"
  62. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="submit"></u-button>
  63. <u-button shape="circle" size="small" text="删除" v-else :disabled="this.selectedProduct.length == 0"
  64. color="linear-gradient(0deg, #FD5003 0%, #FBA680 100%)" @click="deleteShopping"></u-button>
  65. </view>
  66. </view>
  67. </view>
  68. <u-empty style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)"
  69. v-if="dataList.length == 0" mode="car" icon="http://cdn.uviewui.com/uview/empty/car.png" />
  70. </view>
  71. </template>
  72. <script>
  73. import {
  74. shoppingCartList,
  75. generateOrder,
  76. shoppingCartUpdate,
  77. getCorpsAddr,
  78. paramserviceDetail
  79. } from '@/api/tabBar/shoppingCart.js'
  80. import { registerRuntimeCompiler } from "vue"
  81. import { details } from '@/api/views/personalInformation/index.js'
  82. export default {
  83. data() {
  84. return {
  85. editDel: false,
  86. radiovalue: [],
  87. companyValue: [],
  88. dataList: [],
  89. companyValueLength: 0,
  90. selectedProduct: [],
  91. totalPrice: 0.00,
  92. totalFreight: 0.00,
  93. addres: {},
  94. checkStatus:null,
  95. }
  96. },
  97. watch: {
  98. companyValue() {
  99. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  100. if (this.companyValue.length == this.companyValueLength) {
  101. this.radiovalue = ["全选"]
  102. } else {
  103. this.radiovalue = []
  104. }
  105. }
  106. this.statistics()
  107. }
  108. },
  109. onShow() {
  110. // 获取审核状态
  111. details().then(res => {
  112. this.checkStatus = res.data.checkStatus
  113. uni.setStorageSync('checkStatus', res.data.checkStatus);
  114. if (this.checkStatus != '通过') {
  115. // uni.showToast({
  116. // title: "当前用户未授权,请联系客服",
  117. // icon: "none",
  118. // mask:true
  119. // });
  120. uni.switchTab({
  121. url:'/pages/tabBar/home'
  122. })
  123. return
  124. }
  125. })
  126. this.editDel = false
  127. this.companyValue = []
  128. shoppingCartList().then(res => {
  129. this.dataList = res.data
  130. this.companyValueLength = this.dataList.length
  131. })
  132. getCorpsAddr().then(res => {
  133. this.addres = res.data
  134. })
  135. // 支付成功之后的回调
  136. let options = wx.getEnterOptionsSync();
  137. if (options.scene == '1038' && options.referrerInfo.appId=='wxef277996acc166c3') {
  138. // 代表从收银台小程序返回
  139. let extraData = options.referrerInfo.extraData;
  140. if (!extraData) {
  141. // "当前通过物理按键返回,未接收到返参,建议自行查询交易结果";
  142. console.log('当前通过物理按键返回,未接收到返参,建议自行查询交易结果');
  143. } else {
  144. if (extraData.code == 'success') {
  145. // "支付成功";
  146. } else if (extraData.code == 'cancel') {
  147. // "支付已取消";
  148. console.log(extraData,'支付已取消');
  149. } else {
  150. console.log(extraData,'失败');
  151. // "支付失败:" + extraData.errmsg;
  152. }
  153. }
  154. }
  155. },
  156. methods: {
  157. clickAddress() {
  158. this.$u.route('/pages/views/personalInformation/addressManagement');
  159. },
  160. deleteGoods(val) {
  161. uni.showLoading({
  162. title: '加载中',
  163. mask: true
  164. });
  165. shoppingCartUpdate({
  166. ids: val
  167. }).then(res => {
  168. uni.showToast({
  169. title: "删除成功",
  170. icon: 'none'
  171. });
  172. uni.showLoading({
  173. title: '加载中',
  174. mask: true
  175. });
  176. this.editDel = false
  177. this.companyValue = []
  178. shoppingCartList().then(res => {
  179. this.dataList = res.data
  180. this.companyValueLength = this.dataList.length
  181. uni.hideLoading();
  182. }).catch(err => {
  183. uni.hideLoading();
  184. })
  185. uni.hideLoading();
  186. }).catch(err => {
  187. uni.hideLoading();
  188. })
  189. },
  190. deleteShopping() {
  191. let data = []
  192. for (let item of this.companyValue) {
  193. for (let ite of this.dataList) {
  194. if (item == ite.name) {
  195. for (let it of ite.list) {
  196. data.push(it.id)
  197. }
  198. }
  199. }
  200. }
  201. uni.showLoading({
  202. title: '加载中',
  203. mask: true
  204. });
  205. shoppingCartUpdate({
  206. ids: data.join(',')
  207. }).then(res => {
  208. uni.showToast({
  209. title: "删除成功",
  210. icon: 'none'
  211. });
  212. uni.hideLoading();
  213. uni.showLoading({
  214. title: '加载中',
  215. mask: true
  216. });
  217. this.editDel = false
  218. this.companyValue = []
  219. shoppingCartList().then(res => {
  220. this.dataList = res.data
  221. this.companyValueLength = this.dataList.length
  222. uni.hideLoading();
  223. }).catch(err => {
  224. uni.hideLoading();
  225. })
  226. }).catch(err => {
  227. uni.hideLoading();
  228. })
  229. },
  230. // 立即支付
  231. submit() {
  232. if (this.companyValue.length > 0) {
  233. let data = []
  234. for (let item of this.companyValue) {
  235. for (let ite of this.dataList) {
  236. if (item == ite.name) {
  237. data.push({
  238. name: item,
  239. list: ite.list
  240. })
  241. }
  242. }
  243. }
  244. uni.showLoading({
  245. title: '加载中',
  246. mask: true
  247. });
  248. generateOrder({
  249. address: this.addres.belongtoarea + this.addres.detailedAddress,
  250. list: data,
  251. }).then(res => {
  252. let generateOrderData = res.data
  253. paramserviceDetail({
  254. paramKey:'cashier.payment'
  255. }).then(res=>{
  256. let paramservice = res.data
  257. // 判断是调支付台的接口还是微信支付的接口
  258. if (paramservice.paramValue == '1') {
  259. // uni.hideLoading();
  260. let obj = {
  261. appId: 'wxef277996acc166c3',
  262. extraData: {
  263. cusid: generateOrderData.cusid,
  264. appid: generateOrderData.appid,
  265. orgid: generateOrderData.orgid,
  266. version: generateOrderData.version,
  267. trxamt: generateOrderData.trxamt,
  268. reqsn: generateOrderData.reqsn,
  269. notify_url: generateOrderData.notify_url,
  270. body: generateOrderData.body,
  271. remark: generateOrderData.remark,
  272. validtime: generateOrderData.validtime,
  273. limit_pay: generateOrderData.limit_pay,
  274. randomstr: generateOrderData.randomstr,
  275. paytype: generateOrderData.paytype,
  276. signtype:generateOrderData.signtype,
  277. sign: generateOrderData.sign,
  278. },
  279. }
  280. console.log(obj);
  281. wx.openEmbeddedMiniProgram({
  282. appId: 'wxef277996acc166c3',
  283. extraData: {
  284. cusid: generateOrderData.cusid,
  285. appid: generateOrderData.appid,
  286. orgid: generateOrderData.orgid,
  287. version: generateOrderData.version,
  288. trxamt: generateOrderData.trxamt,
  289. reqsn: generateOrderData.reqsn,
  290. notify_url: generateOrderData.notify_url,
  291. body: generateOrderData.body,
  292. remark: generateOrderData.remark,
  293. validtime: generateOrderData.validtime,
  294. // limit_pay: generateOrderData.limit_pay,
  295. limit_pay:"",
  296. randomstr: generateOrderData.randomstr,
  297. paytype: generateOrderData.paytype,
  298. signtype:generateOrderData.signtype,
  299. sign: generateOrderData.sign,
  300. },
  301. success:(a)=>{
  302. uni.hideLoading();
  303. },
  304. fail:(err)=>{
  305. uni.hideLoading();
  306. }
  307. })
  308. }else {
  309. uni.requestPayment({
  310. provider: "wxpay",
  311. appId:generateOrderData.appId,
  312. timeStamp: generateOrderData.timeStamp,
  313. nonceStr: generateOrderData.nonceStr,
  314. package: generateOrderData.package,
  315. signType: generateOrderData.signType,
  316. paySign: generateOrderData.paySign,
  317. success(res) {
  318. uni.showToast({
  319. title: '支付成功',
  320. mask: true,
  321. duration: 2000
  322. });
  323. setTimeout(function() {
  324. uni.hideLoading();
  325. // this_.refresh(res.data.data.id)
  326. }, 1000);
  327. },
  328. fail(e) {
  329. console.log(e);
  330. uni.showToast({
  331. title: "支付失败",
  332. icon: 'none',
  333. mask: true
  334. });
  335. setTimeout(function() {
  336. uni.hideLoading();
  337. // this_.refresh(res.data.id)
  338. }, 1000);
  339. }
  340. })
  341. }
  342. })
  343. // uni.showToast({
  344. // title: "提交成功",
  345. // icon: 'none'
  346. // });
  347. // uni.hideLoading();
  348. // uni.showLoading({
  349. // title: '加载中',
  350. // mask: true
  351. // });
  352. // this.editDel = false
  353. // this.companyValue = []
  354. // shoppingCartList().then(res => {
  355. // this.dataList = res.data
  356. // this.companyValueLength = this.dataList.length
  357. // uni.hideLoading();
  358. // }).catch(err => {
  359. // uni.hideLoading();
  360. // })
  361. }).catch(err => {
  362. uni.hideLoading();
  363. })
  364. }
  365. },
  366. radioGroupChange(e) {
  367. this.radiovalue = e
  368. if (e.length == 0) {
  369. this.companyValue = []
  370. } else {
  371. for (let li of this.dataList) {
  372. if (!this.companyValue.includes(li.name)) {
  373. this.companyValue.push(li.name)
  374. }
  375. }
  376. }
  377. this.statistics()
  378. },
  379. statistics(val, index, ind) {
  380. if (val) {
  381. this.dataList[index].list[ind].goodsNum = val.value
  382. }
  383. let data = []
  384. // for (let item of this.companyValue) {
  385. // for (let ite of this.dataList) {
  386. // if (item == ite.name) {
  387. // for (let it of ite.list) {
  388. // data.push(it)
  389. // }
  390. // }
  391. // }
  392. // }、
  393. for (let item of this.companyValue) {
  394. for (let ite of this.dataList) {
  395. if (item == ite.name) {
  396. data.push({
  397. name: item,
  398. list: ite.list
  399. })
  400. }
  401. }
  402. }
  403. this.totalPrice = 0
  404. this.totalFreight = 0
  405. let num = 0
  406. for (let item of data) {
  407. let num1 = 0
  408. for (let items of item.list) {
  409. this.totalPrice += Number(items.price) * Number(items.goodsNum)
  410. num += Number(items.goodsNum)
  411. num1 += Number(items.goodsNum)
  412. }
  413. if (num1 == 1) {
  414. this.totalFreight += 5
  415. }
  416. }
  417. /* if(num>1){
  418. this.totalFreight = 0
  419. } */
  420. this.totalFreight = this.totalFreight.toFixed(2)
  421. this.totalPrice = this.totalPrice.toFixed(2)
  422. this.selectedProduct = data
  423. },
  424. companyChange(n) {
  425. this.companyValue = n
  426. }
  427. }
  428. }
  429. </script>
  430. <style lang="scss" scoped>
  431. .collection {
  432. background-color: #fff;
  433. padding: 20rpx;
  434. border-radius: 20rpx;
  435. margin-top: 20rpx;
  436. }
  437. .goods {
  438. width: 100%;
  439. margin-left: 20rpx;
  440. height: 200rpx;
  441. display: grid;
  442. align-content: space-between;
  443. .price {
  444. display: flex;
  445. justify-content: space-between !important;
  446. margin-top: 20rpx;
  447. align-items: center;
  448. view:nth-child(1) {
  449. color: #FD4B09;
  450. font-size: 40rpx;
  451. }
  452. }
  453. }
  454. .submitBar {
  455. position: fixed;
  456. bottom: 0;
  457. background-color: #fff;
  458. width: 100%;
  459. z-index: 10;
  460. .bar_view {
  461. display: flex;
  462. justify-content: space-between;
  463. align-items: center;
  464. padding: 10rpx;
  465. }
  466. }
  467. </style>