index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. // 获取审核状态
  161. details().then(res => {
  162. this.checkStatus = res.data.checkStatus
  163. this.recoveredBalance = res.data.recoveredBalance
  164. uni.setStorageSync('checkStatus', res.data.checkStatus);
  165. if (this.checkStatus != '审核通过') {
  166. uni.showToast({
  167. title: "当前用户未授权,请联系客服",
  168. icon: "none",
  169. mask: true
  170. });
  171. }
  172. })
  173. this.companyValue = []
  174. if (this.firstLoad) {
  175. this.$refs.paging.reload()
  176. }
  177. },
  178. methods: {
  179. getTabbarHeight() {
  180. // 可以通过uni.getSystemInfo获取系统信息
  181. // #ifdef H5
  182. uni.getSystemInfo({
  183. success: (res) => {
  184. // 根据设备类型设置不同的tabbar高度
  185. this.tabbarHeight = res.platform === 'ios' ? 50 : 48
  186. }
  187. })
  188. // #endif
  189. },
  190. // 库存弹窗
  191. inventoryfun(arr) {
  192. let sum = ''
  193. arr.map((item, index) => {
  194. if (Number(item.goodsNum) > Number(item.inventory)) {
  195. sum += `${item.goodsName} 的库存数量为${item.inventory}<br>`
  196. }
  197. return item
  198. })
  199. if (sum != '') {
  200. this.inventoryContent = sum + '请修正数量后重新结算'
  201. this.inventoryShow = true
  202. return true
  203. }
  204. return false
  205. },
  206. clickAddress() {
  207. this.$u.route('/pages/views/personalInformation/addressManagement');
  208. },
  209. async getList() {
  210. try {
  211. this.companyValue = []
  212. this.radiovalue = []
  213. const res = await shoppingCartList()
  214. this.companyValueLength = res.data.length
  215. if(this.companyValueLength){
  216. uni.setTabBarBadge({
  217. index: 3, // tabIndex,tabBar的哪一项,从0开始
  218. text: this.companyValueLength.toString() // 显示的文本,超过 99 显示成 “…”
  219. })
  220. }else{
  221. uni.removeTabBarBadge({
  222. index: 3, // tabIndex,tabBar的哪一项,从0开始
  223. })
  224. }
  225. this.$refs.paging.complete(res.data)
  226. } catch (e) {
  227. this.$refs.paging.complete(false)
  228. uni.showToast({
  229. title: '加载失败',
  230. icon: 'none'
  231. })
  232. }
  233. this.firstLoad = true
  234. },
  235. deleteGoods(val) {
  236. let _this = this
  237. uni.showModal({
  238. title: '提示',
  239. content: '是否删除?',
  240. success: function(res) {
  241. if (res.confirm) {
  242. uni.showLoading({
  243. title: '加载中',
  244. mask: true
  245. });
  246. shoppingCartUpdate({
  247. ids: val
  248. }).then(res => {
  249. uni.showToast({
  250. title: "删除成功",
  251. icon: 'none'
  252. });
  253. _this.getList()
  254. _this.companyValue = []
  255. }).catch(err => {
  256. uni.hideLoading();
  257. })
  258. }
  259. }
  260. });
  261. },
  262. // 立即支付
  263. submit() {
  264. if (this.selecteList.length == 0) {
  265. uni.showToast({
  266. title: "请先选择要支付的商品",
  267. icon: 'none'
  268. });
  269. return
  270. }
  271. if (this.inventoryfun(this.dataList)) {
  272. uni.showToast({
  273. title: '当前下单数量超出库存数量,请修改下单数量',
  274. icon: 'none',
  275. mask: true,
  276. duration: 2000
  277. });
  278. return
  279. }
  280. let obj = {
  281. address: null,
  282. payType: null,
  283. useRecoveredBalance: false,
  284. shoppingCartList: this.selecteList
  285. }
  286. let _this = this
  287. uni.showModal({
  288. title: '提示',
  289. content: '是否生成订单?',
  290. success: function(res) {
  291. if (res.confirm) {
  292. uni.showLoading({
  293. title: '加载中',
  294. mask: true
  295. });
  296. generateOrder(obj).then(res => {
  297. uni.showToast({
  298. title: '下单成功',
  299. icon: 'none',
  300. duration: 2000
  301. });
  302. _this.$refs.paging.reload();
  303. // uni.navigateTo({
  304. // url: '/pages/settlement/index'
  305. // })
  306. })
  307. .finally(() => {
  308. uni.hideLoading()
  309. });
  310. }
  311. }
  312. });
  313. },
  314. radioGroupChange(e) {
  315. console.log(e)
  316. this.radiovalue = e
  317. if (e.length == 0) {
  318. this.companyValue = []
  319. } else {
  320. for (let li of this.dataList) {
  321. if (!this.companyValue.includes(li.goodsName)) {
  322. this.companyValue.push(li.goodsName)
  323. }
  324. }
  325. }
  326. this.inventoryfun(this.dataList)
  327. this.cartTotal()
  328. },
  329. checkRecovered(e) {
  330. this.checkRecoveredBalance = e
  331. },
  332. statistics(val, index, row) {
  333. if (val) {
  334. this.dataList[index].goodsNum = val.value
  335. console.log(row)
  336. let obj = {
  337. id: row.id,
  338. goodsNum: val.value
  339. }
  340. updateNumber(obj)
  341. }
  342. this.cartTotal()
  343. },
  344. cartTotal() {
  345. let data = []
  346. for (let item of this.companyValue) {
  347. for (let ite of this.dataList) {
  348. if (item == ite.goodsName) {
  349. data.push(ite)
  350. }
  351. }
  352. }
  353. this.selecteList = data
  354. this.totalPrice = 0
  355. let num = 0
  356. for (let item of data) {
  357. this.totalPrice += Number(item.price) * Number(item.goodsNum)
  358. }
  359. this.totalPrice = this.totalPrice.toFixed(2)
  360. },
  361. companyChange(n) {
  362. this.companyValue = n
  363. this.inventoryfun(this.dataList)
  364. }
  365. }
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. .dynamic-bottom {
  370. padding-bottom: 40rpx;
  371. }
  372. .container {
  373. // #ifdef H5
  374. height: calc(100vh - var(--nav-bar, 44px) - var(--tab-bar, 50px) - 124px);
  375. // #endif
  376. // #ifdef APP-PLUS
  377. height: calc(100vh - 105px);;
  378. // #endif
  379. display: flex;
  380. flex-direction: column;
  381. }
  382. .card {
  383. background: #FFFFFF;
  384. padding: 32rpx;
  385. margin: 10rpx 0;
  386. ::v-deep .u-checkbox__icon-wrap {
  387. border-color: #03803B !important;
  388. }
  389. ::v-deep .u-number-box {
  390. border: 2rpx #E1E1E1 solid;
  391. border-radius: 8rpx;
  392. }
  393. ::v-deep .u-number-box__minus {
  394. border-right: 2rpx #E1E1E1 solid;
  395. }
  396. ::v-deep .u-number-box__plus {
  397. border-left: 2rpx #E1E1E1 solid;
  398. }
  399. }
  400. .submitBar {
  401. position: fixed;
  402. // bottom: 0;
  403. background-color: #fff;
  404. width: 100%;
  405. z-index: 10;
  406. .balance-row {
  407. display: flex;
  408. justify-content: space-between;
  409. align-items: flex-start;
  410. /* 改为flex-start使内容顶部对齐 */
  411. padding: 20rpx 0;
  412. .balance-info {
  413. text-align: right;
  414. display: flex;
  415. flex-direction: column;
  416. }
  417. }
  418. .top-row {
  419. display: flex;
  420. justify-content: space-between;
  421. align-items: center;
  422. padding: 20rpx 0;
  423. .select-all {
  424. flex: 1;
  425. }
  426. .total-price {
  427. flex: 1;
  428. text-align: right;
  429. }
  430. }
  431. .left-btn {
  432. background-color: #FFEEE9;
  433. color: #03803B;
  434. font-size: 26rpx;
  435. width: 160rpx;
  436. height: 65rpx;
  437. display: flex;
  438. justify-content: center;
  439. align-items: center;
  440. border-top-left-radius: 33rpx;
  441. border-bottom-left-radius: 33rpx;
  442. }
  443. .right-btn {
  444. background-color: #03803B;
  445. color: #fff;
  446. font-size: 26rpx;
  447. width: 160rpx;
  448. height: 65rpx;
  449. display: flex;
  450. justify-content: center;
  451. align-items: center;
  452. // border-top-right-radius: 33rpx;
  453. // border-bottom-right-radius: 33rpx;
  454. border-radius: 33rpx;
  455. }
  456. }
  457. </style>