index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <template>
  2. <view class="container" v-if="checkStatus == '审核通过'">
  3. <view style="width: 100%;height: 155rpx;background: #FFFFFF;display: flex;align-items: center;"
  4. @click="clickAddress" v-if="addres.length">
  5. <view>
  6. <view style="font-size: 28rpx;color: #3B3B3B;font-weight: 400;display: flex;align-items: center;">
  7. <image src="/static/images/shoppingCart/1061@2x.png"
  8. style="width: 25rpx;height: 30rpx;margin-left: 34rpx;margin-right: 2rpx;" mode="scaleToFill">
  9. <text>{{addres.contacts}}</text>
  10. <text style="margin-left: 35rpx;">{{addres.tel}}</text>
  11. </image>
  12. </view>
  13. <view style="font-size: 26rpx;color:#989898;font-weight: 400;margin-top: 22rpx;margin-left: 61rpx;">
  14. <text>{{addres.detailedAddress}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. <z-paging ref="paging" v-model="dataList" @query="getList" :fixed="false" :auto-show-back-to-top="true"
  19. empty-view-text="暂无购物车" :hide-empty-view="false" :auto-show-system-loading="true"
  20. :loading-more-enabled="false" :hide-no-more="true">
  21. <u-checkbox-group v-model="companyValue" placement="column" @change="companyChange" :size='15'>
  22. <view class="card" v-for="(item,index) in dataList" :key="index">
  23. <view>
  24. <u-checkbox activeColor="#03803B" shape="circle" :customStyle="{marginBottom: '16rpx'}"
  25. :label="item.goodsName" :name="item.goodsName" labelSize="32rpx"
  26. labelColor='#3B3B3B'></u-checkbox>
  27. </view>
  28. <view style="background: #FCF7F5;padding: 20rpx;display: flex;">
  29. <view>
  30. <image :src="item.picture" style="width: 120rpx;height: 120rpx;border-radius: 10rpx;">
  31. </image>
  32. </view>
  33. <view style="width: 100%;margin-left: 8rpx ;">
  34. <view style="display: flex;justify-content: space-between;">
  35. <u--text :text="item.goodsName" size="24rpx" color='#797979' lines="2"></u--text>
  36. <u-icon name="trash" size="40rpx" color='#C9C9C9'
  37. @click="deleteGoods(item.id)"></u-icon>
  38. </view>
  39. <view
  40. style="display: flex;justify-content: space-between;align-items: flex-end;margin-top: 20rpx;">
  41. <view style="color: #03803B;font-size: 32rpx;">¥{{item.price}}</view>
  42. <view>
  43. <u-number-box v-model="item.goodsNum" :min="1" :max='item.inventory'
  44. buttonSize="53rpx" color="#414141" bgColor="#FCF7F5" iconStyle="color:#A4A4A4"
  45. @change="(val)=>{statistics(val,index,item)}"></u-number-box>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </u-checkbox-group>
  52. <view class="dynamic-bottom">
  53. </view>
  54. </z-paging>
  55. <view class="submitBar" :style="{ bottom: tabbarHeight + 'px' }">
  56. <view style="padding:0rpx 40rpx;">
  57. <!-- 第二行:全选和合计 -->
  58. <view class="top-row">
  59. <view class="select-all">
  60. <u-checkbox-group v-model="radiovalue" placement="column" @change="radioGroupChange" :size='15'>
  61. <u-checkbox label="全选" name="全选" activeColor="#03803B" shape="circle" labelSize="28rpx"
  62. labelColor='#3B3B3B'></u-checkbox>
  63. </u-checkbox-group>
  64. </view>
  65. <view class="total-price">
  66. <text style="font-size: 24rpx;">合计:</text>
  67. <text style="color: #03803B;">¥</text>
  68. <text style="font-size: 42rpx;color: #03803B;">{{totalPrice}}</text>
  69. </view>
  70. </view>
  71. <!-- 分隔线 -->
  72. <view style="height: 2rpx;width: 100%;background: #EEEEEE;"></view>
  73. <!-- 第三行:运费和支付按钮 -->
  74. <view style="display: flex;justify-content:flex-end;align-items: center;padding: 10rpx;">
  75. <view style="display: flex;">
  76. <!-- <view class="left-btn" @click="submit('W01')">
  77. <text style="line-height: 27rpx;">
  78. 他人代付
  79. </text>
  80. </view> -->
  81. <view class="right-btn" @click="submit()">
  82. <text style="line-height: 27rpx;">
  83. 去结算
  84. </text>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. import {
  94. shoppingCartList,
  95. generateOrder,
  96. generateOrderLimit,
  97. shoppingCartUpdate,
  98. getCorpsAddr,
  99. paramserviceDetail,
  100. getParamservice,
  101. isProcurement,
  102. generateOrderShare,
  103. updateNumber
  104. } from '@/api/shoppingCart/index.js'
  105. import {
  106. details
  107. } from '@/api/personalInformation/index.js'
  108. import {
  109. appDetail
  110. } from '@/api/home/index.js'
  111. import {
  112. activityList
  113. } from '@/api/activity/index.js'
  114. export default {
  115. data() {
  116. return {
  117. tabbarHeight: 0, // 默认tabbar高度
  118. qrcodeshow: false, // 二维码弹窗
  119. qrcodeData: [], // 二维码数据
  120. qrcodeurl: '', // 二维码参数
  121. radiovalue: [],
  122. companyValue: [],
  123. dataList: [],
  124. companyValueLength: 0,
  125. selecteList: [],
  126. totalPrice: 0.00,
  127. addres: {},
  128. checkStatus: null,
  129. adminShow: false,
  130. inventoryShow: false,
  131. inventoryContent: '',
  132. freight: 5,
  133. recoveredBalance: 0,
  134. checkRecoveredBalance: [],
  135. firstLoad: false
  136. }
  137. },
  138. watch: {
  139. companyValue() {
  140. if (this.companyValue.length != 0 || this.companyValueLength != 0) {
  141. if (this.companyValue.length == this.companyValueLength) {
  142. this.radiovalue = ["全选"]
  143. } else {
  144. this.radiovalue = []
  145. }
  146. }
  147. this.cartTotal()
  148. },
  149. getUserInfo() {
  150. details().then(res => {
  151. this.recoveredBalance = res.data.recoveredBalance
  152. })
  153. }
  154. },
  155. onLoad() {
  156. // 获取tabbar高度(需要根据实际tabbar高度调整)
  157. this.getTabbarHeight()
  158. },
  159. onShow() {
  160. this.getUpdate()
  161. // activityList({
  162. // current: 1,
  163. // size: 10,
  164. // status: 1
  165. // }).then(res => {
  166. // uni.setTabBarBadge({
  167. // index: 1, // tabIndex,tabBar的哪一项,从0开始
  168. // text: res.data.total.toString() // 显示的文本,超过 99 显示成 “…”
  169. // })
  170. // })
  171. // 获取审核状态
  172. details().then(res => {
  173. this.checkStatus = res.data.checkStatus
  174. this.recoveredBalance = res.data.recoveredBalance
  175. uni.setStorageSync('checkStatus', res.data.checkStatus);
  176. if (this.checkStatus != '审核通过') {
  177. uni.showToast({
  178. title: "当前用户未授权,请联系客服",
  179. icon: "none",
  180. mask: true
  181. });
  182. }
  183. })
  184. this.companyValue = []
  185. if (this.firstLoad) {
  186. this.$refs.paging.reload()
  187. }
  188. },
  189. methods: {
  190. getTabbarHeight() {
  191. // 可以通过uni.getSystemInfo获取系统信息
  192. // #ifdef H5
  193. uni.getSystemInfo({
  194. success: (res) => {
  195. // 根据设备类型设置不同的tabbar高度
  196. this.tabbarHeight = res.platform === 'ios' ? 50 : 48
  197. }
  198. })
  199. // #endif
  200. },
  201. getUpdate() {
  202. const updateManager = uni.getUpdateManager();
  203. updateManager.onCheckForUpdate(function(res) {
  204. // 请求完新版本信息的回调
  205. if (res.hasUpdate) {
  206. updateManager.onUpdateReady(function() {
  207. uni.showModal({
  208. title: '更新提示',
  209. content: '新版本已经准备好,是否重启应用?',
  210. success: function(res) {
  211. if (res.confirm) {
  212. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  213. updateManager.applyUpdate();
  214. }
  215. }
  216. });
  217. });
  218. updateManager.onUpdateFailed(function() {
  219. // 新的版本下载失败
  220. uni.showModal({
  221. title: '已经有新版本了哟~',
  222. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  223. });
  224. });
  225. }
  226. });
  227. },
  228. // 库存弹窗
  229. inventoryfun(arr) {
  230. let sum = ''
  231. arr.map((item, index) => {
  232. if (Number(item.goodsNum) > Number(item.inventory)) {
  233. sum += `${item.goodsName} 的库存数量为${item.inventory}<br>`
  234. }
  235. return item
  236. })
  237. if (sum != '') {
  238. this.inventoryContent = sum + '请修正数量后重新结算'
  239. this.inventoryShow = true
  240. return true
  241. }
  242. return false
  243. },
  244. clickAddress() {
  245. this.$u.route('/pages/views/personalInformation/addressManagement');
  246. },
  247. async getList() {
  248. try {
  249. this.companyValue = []
  250. this.radiovalue = []
  251. const res = await shoppingCartList()
  252. this.companyValueLength = res.data.length
  253. uni.setTabBarBadge({
  254. index: 3, // tabIndex,tabBar的哪一项,从0开始
  255. text: this.companyValueLength.toString() // 显示的文本,超过 99 显示成 “…”
  256. })
  257. this.$refs.paging.complete(res.data)
  258. } catch (e) {
  259. this.$refs.paging.complete(false)
  260. uni.showToast({
  261. title: '加载失败',
  262. icon: 'none'
  263. })
  264. }
  265. this.firstLoad = true
  266. },
  267. deleteGoods(val) {
  268. let _this = this
  269. uni.showModal({
  270. title: '提示',
  271. content: '是否删除?',
  272. success: function(res) {
  273. if (res.confirm) {
  274. uni.showLoading({
  275. title: '加载中',
  276. mask: true
  277. });
  278. shoppingCartUpdate({
  279. ids: val
  280. }).then(res => {
  281. uni.showToast({
  282. title: "删除成功",
  283. icon: 'none'
  284. });
  285. _this.getList()
  286. _this.companyValue = []
  287. }).catch(err => {
  288. uni.hideLoading();
  289. })
  290. }
  291. }
  292. });
  293. },
  294. // 立即支付
  295. submit() {
  296. if (this.selecteList.length == 0) {
  297. uni.showToast({
  298. title: "请先选择要支付的商品",
  299. icon: 'none'
  300. });
  301. return
  302. }
  303. if (this.inventoryfun(this.dataList)) {
  304. uni.showToast({
  305. title: '当前下单数量超出库存数量,请修改下单数量',
  306. icon: 'none',
  307. mask: true,
  308. duration: 2000
  309. });
  310. return
  311. }
  312. let obj = {
  313. address: null,
  314. payType: null,
  315. useRecoveredBalance: false,
  316. shoppingCartList: this.selecteList
  317. }
  318. let _this = this
  319. uni.showModal({
  320. title: '提示',
  321. content: '是否生成订单?',
  322. success: function(res) {
  323. if (res.confirm) {
  324. uni.showLoading({
  325. title: '加载中',
  326. mask: true
  327. });
  328. generateOrder(obj).then(res => {
  329. uni.showToast({
  330. title: '下单成功',
  331. icon: 'none',
  332. duration: 2000
  333. });
  334. // _this.$refs.paging.reload();
  335. // uni.navigateTo({
  336. // url: '/pages/settlement/index'
  337. // })
  338. })
  339. .finally(() => {
  340. uni.hideLoading()
  341. });
  342. }
  343. }
  344. });
  345. },
  346. radioGroupChange(e) {
  347. console.log(e)
  348. this.radiovalue = e
  349. if (e.length == 0) {
  350. this.companyValue = []
  351. } else {
  352. for (let li of this.dataList) {
  353. if (!this.companyValue.includes(li.goodsName)) {
  354. this.companyValue.push(li.goodsName)
  355. }
  356. }
  357. }
  358. this.inventoryfun(this.dataList)
  359. this.cartTotal()
  360. },
  361. checkRecovered(e) {
  362. this.checkRecoveredBalance = e
  363. },
  364. statistics(val, index, row) {
  365. if (val) {
  366. this.dataList[index].goodsNum = val.value
  367. console.log(row)
  368. let obj = {
  369. id: row.id,
  370. goodsNum: val.value
  371. }
  372. updateNumber(obj)
  373. }
  374. this.cartTotal()
  375. },
  376. cartTotal() {
  377. let data = []
  378. for (let item of this.companyValue) {
  379. for (let ite of this.dataList) {
  380. if (item == ite.goodsName) {
  381. data.push(ite)
  382. }
  383. }
  384. }
  385. this.selecteList = data
  386. this.totalPrice = 0
  387. let num = 0
  388. for (let item of data) {
  389. this.totalPrice += Number(item.price) * Number(item.goodsNum)
  390. }
  391. this.totalPrice = this.totalPrice.toFixed(2)
  392. },
  393. companyChange(n) {
  394. this.companyValue = n
  395. this.inventoryfun(this.dataList)
  396. }
  397. }
  398. }
  399. </script>
  400. <style lang="scss" scoped>
  401. .dynamic-bottom {
  402. padding-bottom: 40rpx;
  403. }
  404. .container {
  405. // #ifdef H5
  406. height: calc(100vh - var(--nav-bar, 44px) - var(--tab-bar, 50px) - 124px);
  407. // #endif
  408. // #ifdef APP-PLUS
  409. height: calc(100vh - 105px);;
  410. // #endif
  411. display: flex;
  412. flex-direction: column;
  413. }
  414. .card {
  415. background: #FFFFFF;
  416. padding: 32rpx;
  417. margin: 10rpx 0;
  418. ::v-deep .u-checkbox__icon-wrap {
  419. border-color: #03803B !important;
  420. }
  421. ::v-deep .u-number-box {
  422. border: 2rpx #E1E1E1 solid;
  423. border-radius: 8rpx;
  424. }
  425. ::v-deep .u-number-box__minus {
  426. border-right: 2rpx #E1E1E1 solid;
  427. }
  428. ::v-deep .u-number-box__plus {
  429. border-left: 2rpx #E1E1E1 solid;
  430. }
  431. }
  432. .submitBar {
  433. position: fixed;
  434. // bottom: 0;
  435. background-color: #fff;
  436. width: 100%;
  437. z-index: 10;
  438. .balance-row {
  439. display: flex;
  440. justify-content: space-between;
  441. align-items: flex-start;
  442. /* 改为flex-start使内容顶部对齐 */
  443. padding: 20rpx 0;
  444. .balance-info {
  445. text-align: right;
  446. display: flex;
  447. flex-direction: column;
  448. }
  449. }
  450. .top-row {
  451. display: flex;
  452. justify-content: space-between;
  453. align-items: center;
  454. padding: 20rpx 0;
  455. .select-all {
  456. flex: 1;
  457. }
  458. .total-price {
  459. flex: 1;
  460. text-align: right;
  461. }
  462. }
  463. .left-btn {
  464. background-color: #FFEEE9;
  465. color: #03803B;
  466. font-size: 26rpx;
  467. width: 160rpx;
  468. height: 65rpx;
  469. display: flex;
  470. justify-content: center;
  471. align-items: center;
  472. border-top-left-radius: 33rpx;
  473. border-bottom-left-radius: 33rpx;
  474. }
  475. .right-btn {
  476. background-color: #03803B;
  477. color: #fff;
  478. font-size: 26rpx;
  479. width: 160rpx;
  480. height: 65rpx;
  481. display: flex;
  482. justify-content: center;
  483. align-items: center;
  484. // border-top-right-radius: 33rpx;
  485. // border-bottom-right-radius: 33rpx;
  486. border-radius: 33rpx;
  487. }
  488. }
  489. </style>