replace-take.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <template>
  2. <view class="replace-take-box iPhone-bottom flex-common-css box-border-box bgc-f">
  3. <scroll-view :scroll-y="true" class="scroll-view-css" @scroll="scroll">
  4. <view class="list-box">
  5. <view class="nav-box">
  6. <image class="bg-img" src="@/static/img/takeout/dq-bg.png" mode="scaleToFill"></image>
  7. <Nav :leftShow='false' :customNav='true' :bgckgroundBox='bgckgroundBox'>
  8. <template>
  9. <view slot="custom" class="align-items-center">
  10. <uni-icons type="left" size="20" @click="toBack()"></uni-icons>
  11. <view class="w-390 text-overflow-ellipsis-one fs-36 fw-400">{{schoolData.school_name}}
  12. </view>
  13. </view>
  14. </template>
  15. </Nav>
  16. <view :class="addressData.id?'bottom-124':''"
  17. class="address-box align-items-center box-border-box plr-24" @click="selectFun()">
  18. <view v-if="!addressData.site_id" class="address-1 flex-justify-space align-items-center">
  19. <view class="align-items-center">
  20. <image class="qu-image" src="@/static/img/takeout/qu-icon.png" mode=""></image>
  21. <view class="fw-600 fs-40">请选择站点</view>
  22. </view>
  23. <image class="address-box-right" src="@/static/img/toRight.png" mode=""></image>
  24. </view>
  25. <view v-else class="address-2 flex-justify-space align-items-center">
  26. <view class="display-flex">
  27. <image class="address-img mr-20" :src="addressData.site_logo" mode="scaleToFill">
  28. </image>
  29. <view class="">
  30. <view class="w-474 fs-40 fw-600 mb-8">{{addressData.site_name}}</view>
  31. <view class="w-474 fw-400 fs-26 fc-9">{{addressData.site_address}}</view>
  32. </view>
  33. </view>
  34. <image class="address-box-right" src="@/static/img/toRight.png" mode=""></image>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="mb-32" :class="addressData.id?'h-120':'h-60'"></view>
  39. <view class="list-box-b mb-48 box-border-box plr-24">
  40. <view class="fs-36 fw-600 mb-22">快递类型</view>
  41. <view class="list-item flex-justify-space" v-for="(item,i) in list" :key="i">
  42. <image class="item_img" :src="item.serve_image" mode="scaleToFill"></image>
  43. <view class="flex-1">
  44. <view class="fs-32 fw-600 mb-32 ">{{item.serve_name}}</view>
  45. <view class="fs-24 fw-400 mb-32 fc-9">{{item.serve_desc}}</view>
  46. <!-- <view class="fs-24 fw-400 mb-4 fc-9">销量2801</view> -->
  47. <view class="flex-justify-space">
  48. <view class="">
  49. <span class="fw-4 fc-FB3D03 fs-24">¥</span>
  50. <span class="fw-b fc-FB3D03 fs-40">{{item.price}}</span>
  51. <span class="fw-400 fc-9 fs-24">/份</span>
  52. </view>
  53. <view class="display-flex align-items-center">
  54. <image v-if="item.number > 0" class="wh44" src="@/static/img/takeout/j.png" mode=""
  55. @click="redNumber(1,item)"></image>
  56. <!-- <view v-if="item.number > 0" class="right-only-right-red fw-500 fs-36 fc-f align-items-center flex-justify-center" @click="redNumber(1,item)">-</view> -->
  57. <view v-if="item.number > 0"
  58. class="right-only-right-2 text-align-center fs-28 fw-400">{{item.number}}</view>
  59. <!-- <view class="right-only-right-add fw-500 fs-36 fc-f align-items-center flex-justify-center" @click="addNumber(1,item)">+</view> -->
  60. <image class="wh44" src="@/static/img/takeout/add.png" mode=""
  61. @click="addNumber(1,item)"></image>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="box-border-box plr-24">
  68. <view v-show="cardData.total_num>0" class="fs-36 fw-600 mb-22">取件码({{pickup_code.length}})</view>
  69. <view class="mb-20" v-for="(item,i) in pickup_code" :key="i">
  70. <input class="input-num" v-model="item.code" type="text" maxlength="20" placeholder="未输入取件码"
  71. placeholder-class="input-p fc-FB3D03">
  72. </view>
  73. </view>
  74. </view>
  75. </scroll-view>
  76. <view class="shop-buttom-money box-border-box">
  77. <view class="shop-buttom-money-1 flex-justify-space align-items-center">
  78. <image src="@/static/img/takeout/buy-icon.png" mode="scaleToFill" @click="openBuyCrad()"></image>
  79. <view v-show="cardData.total_num>0" class="shop-buttom-num fs-24 fc-f text-align-center"
  80. @click="openBuyCrad()">{{cardData.total_num}}</view>
  81. <view class="" @click="openBuyCrad()">
  82. <span class="fw-600 fs-24 fc-f">¥</span>
  83. <span class="fw-600 fs-44 fc-f">{{cardData.total_price||0}}</span>
  84. </view>
  85. <view v-if="cardData.total_num>0" class="shop-buttom-money-2 text-align-center fs-32 fc-f fw-600"
  86. @click="createOrder()">去结算</view>
  87. <view v-else class="fs-32 fc-f fw-600 mr-36">
  88. 暂未选择
  89. </view>
  90. </view>
  91. </view>
  92. <uni-popup ref="popupBuy" type="bottom" style="z-index: 200;">
  93. <view class="buy-card flex-index-css">
  94. <view class="buy-card-top box-border-box plr-32 flex-justify-space align-items-center">
  95. <view class="">
  96. <span class="fs-32 fc-3 mr-12">已选商品</span>
  97. </view>
  98. <view class="fs-28 fw-400 fc-9 align-items-center">
  99. <view class="">
  100. <uni-icons type="trash" size="18" color="#999"></uni-icons>
  101. </view>
  102. <view class="fs-28 fw-400 fc-9" @click="cardAllDel()">清空</view>
  103. </view>
  104. </view>
  105. <view class="scroll-view-css box-border-box p-32">
  106. <view class="buy-card-item display-flex" v-for="(item,i) in cardData.goods_list" :key="i">
  107. <image class="item_img" :src="item.serve_image" mode="aspectFill"></image>
  108. <view class="flex-1">
  109. <view class="w-514 text-overflow-ellipsis-one fs-34 fw-600 mb-12">{{item.serve_name}}</view>
  110. <view class="w-514 text-overflow-ellipsis-one fs-24 fw-400 fc-9 mb-18">{{item.serve_desc}}
  111. </view>
  112. <view class="flex-justify-space">
  113. <view class="">
  114. <span class="fs-24 fc-FB3D03 fw-400">¥</span>
  115. <span class="fs-40 fc-FB3D03 fw-b">{{item.price}}</span>
  116. </view>
  117. <view class="display-flex align-items-center">
  118. <image class="wh44" src="@/static/img/takeout/j.png" mode=""
  119. @click="redNumber(2,item)"></image>
  120. <!-- <view class="right-only-right-red fw-500 fs-36 fc-f align-items-center flex-justify-center" @click="redNumber(2,item)">-</view> -->
  121. <view class="right-only-right-2 text-align-center fs-28 fw-400">{{item.number}}
  122. </view>
  123. <!-- <view class="right-only-right-add fw-500 fs-36 fc-f align-items-center flex-justify-center" @click="addNumber(2,item)">+</view> -->
  124. <image class="wh44" src="@/static/img/takeout/add.png" mode=""
  125. @click="addNumber(2,item)"></image>
  126. </view>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. <view class="shop-buttom-money box-border-box">
  132. <view class="shop-buttom-money-1 flex-justify-space align-items-center">
  133. <image src="@/static/img/takeout/buy-icon.png" mode="scaleToFill" @click="closeCardBox()">
  134. </image>
  135. <view class="shop-buttom-num fs-24 fc-f text-align-center" @click="closeCardBox()">
  136. {{cardData.total_num}}
  137. </view>
  138. <view class="" @click="closeCardBox()">
  139. <view class="">
  140. <span class="fw-600 fs-24 fc-f">¥</span>
  141. <span class="fw-600 fs-44 fc-f">{{cardData.total_price||0}}</span>
  142. </view>
  143. </view>
  144. <view class="shop-buttom-money-2 text-align-center fs-32 fc-f fw-600" @click="createOrder()">去结算
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. </uni-popup>
  150. </view>
  151. </template>
  152. <script>
  153. import tools from "@/service/tools";
  154. import {
  155. getExpressServe
  156. } from '@/api/express.js';
  157. import {
  158. setShopIngAdd,
  159. setShopIngNumber,
  160. setShopIngDel,
  161. getShopIngList
  162. } from '@/api/shopping.js'
  163. export default {
  164. data() {
  165. return {
  166. schoolData: {
  167. school_id: '',
  168. school_name: '',
  169. },
  170. addressData: {
  171. site_id: '',
  172. site_name: '',
  173. site_address: '',
  174. site_logo: '',
  175. },
  176. list: [],
  177. bgckgroundBox: 'transparent',
  178. isAJAX: false,
  179. pickup_code: [],
  180. cardData: {
  181. goods_list: [],
  182. total_num: 0,
  183. total_price: 0,
  184. },
  185. isInitial: true,
  186. }
  187. },
  188. onShow() {
  189. this.list = [];
  190. // this.pickup_code = [];
  191. this.cardData = {
  192. goods_list: [],
  193. total_num: 0,
  194. total_price: 0,
  195. },
  196. this.schoolData.school_id = uni.getStorageSync('school_id');
  197. this.schoolData.school_name = uni.getStorageSync('school_name');
  198. this.addressData.site_id = uni.getStorageSync('site_id');
  199. this.addressData.site_name = uni.getStorageSync('site_name');
  200. this.addressData.site_address = uni.getStorageSync('site_address');
  201. this.addressData.site_logo = uni.getStorageSync('site_logo');
  202. this.isInitial = true;
  203. this.getList();
  204. },
  205. methods: {
  206. scroll(e) {
  207. if (e.detail.scrollTop > 1) {
  208. this.bgckgroundBox = '#fff';
  209. } else {
  210. this.bgckgroundBox = 'transparent';
  211. }
  212. },
  213. getList() {
  214. getExpressServe({
  215. school_id: this.schoolData.school_id
  216. }).then((res) => {
  217. if (res.code === 1) {
  218. this.list = res.data;
  219. this.list.forEach((v) => {
  220. v.number = 0
  221. })
  222. this.getCard();
  223. }
  224. })
  225. },
  226. getCard() {
  227. getShopIngList({
  228. type: 2,
  229. school_id: this.schoolData.school_id
  230. }).then((res) => {
  231. if (res.code === 1) {
  232. this.cardData = res.data;
  233. if (this.cardData.total_num > 0) {
  234. for (let i = 0; i < this.list.length; i++) {
  235. for (let n = 0; n < this.cardData.goods_list.length; n++) {
  236. if (this.list[i].id == this.cardData.goods_list[n].goods_id) {
  237. this.list[i].number = this.cardData.goods_list[n].number;
  238. break
  239. } else {
  240. this.list[i].number = 0
  241. }
  242. }
  243. }
  244. // 初始设置code 输入框数量
  245. console.log(this.pickup_code.length,this.cardData.total_num)
  246. console.log(this.pickup_code.length<this.cardData.total_num)
  247. if(this.pickup_code.length<this.cardData.total_num){
  248. let maxNum = this.cardData.total_num-this.pickup_code.length
  249. console.log(maxNum)
  250. console.log('易安居完成asssssssssssssssssssss')
  251. for (let i = 0; i < maxNum; i++) {
  252. let obj = {
  253. code: ''
  254. };
  255. this.pickup_code.push(obj);
  256. console.log( '---------------易安居完成'+i )
  257. }
  258. console.log( this.pickup_code)
  259. }
  260. // let saveData = uni.getStorageSync('saveData')
  261. // if (saveData) {
  262. // return
  263. // } else {
  264. // this.pickup_code = [];
  265. //
  266. // }
  267. } else {
  268. this.list.forEach(t => {
  269. t.number = 0;
  270. })
  271. }
  272. }
  273. })
  274. },
  275. toBack() {
  276. tools.leftClick()
  277. uni.setStorageSync('saveData', false)
  278. },
  279. selectFun() {
  280. uni.setStorageSync('saveData', true)
  281. uni.navigateTo({
  282. url: 'pages-takeout/replace-mod/select-site?site_id=' + this.addressData.site_id
  283. })
  284. },
  285. closeCardBox() {
  286. this.$refs.popupBuy.close();
  287. },
  288. openBuyCrad() {
  289. // if (!this.addressData.site_id) {
  290. // return tools.error('请选择站点')
  291. // }
  292. if (this.pickup_code.length == 0) {
  293. return tools.error('请选择商品')
  294. }
  295. this.$refs.popupBuy.open()
  296. },
  297. createOrder() {
  298. if (!this.addressData.site_id) {
  299. return tools.error('请选择站点')
  300. }
  301. if (this.pickup_code.length == 0) {
  302. return tools.error('请选择商品')
  303. }
  304. let flag = this.pickup_code.every((item) => {
  305. return item.code
  306. });
  307. if (!flag) {
  308. return tools.error('请输入取件码')
  309. }
  310. let codeRule = /^[A-Za-z0-9-]+$/
  311. let flagRule = this.pickup_code.every((item) => {
  312. return codeRule.test(item.code)
  313. });
  314. if (!flagRule) {
  315. return tools.error('请输入正确的取件码')
  316. }
  317. let arr = [];
  318. this.pickup_code.forEach((v) => {
  319. arr.push(v.code)
  320. })
  321. let pickup_code = arr.join(',')
  322. uni.setStorageSync('isConfirmAddressFlag', false);
  323. uni.setStorageSync('saveData', true)
  324. uni.navigateTo({
  325. url: 'pages-takeout/confirm-order?pickup_code=' + pickup_code + '&type=2'
  326. })
  327. },
  328. // 增加
  329. addNumber(type, item) {
  330. if (this.isAJAX) {
  331. return
  332. }
  333. this.isAJAX = true;
  334. let id = type == 1 ? item.id : item.goods_id;
  335. setShopIngAdd({
  336. type: 2,
  337. goods_id: id,
  338. school_id: this.schoolData.school_id
  339. }).then((res) => {
  340. if (res.code === 1) {
  341. this.isAJAX = false;
  342. item.number += 1;
  343. let obj = {
  344. code: ''
  345. };
  346. this.pickup_code.push(obj);
  347. this.$forceUpdate();
  348. this.isInitial = false;
  349. this.getCard();
  350. } else {
  351. this.isAJAX = false;
  352. tools.error('添加操作失败')
  353. }
  354. })
  355. },
  356. // 减少
  357. redNumber(type, item) {
  358. if (item.number > 0) {
  359. if (this.isAJAX) {
  360. return
  361. }
  362. this.isAJAX = true;
  363. let id = type == 1 ? item.id : item.goods_id;
  364. setShopIngNumber({
  365. type: 2,
  366. goods_id: id,
  367. operation: 2,
  368. school_id: this.schoolData.school_id
  369. }).then((res) => {
  370. if (res.code === 1) {
  371. this.isAJAX = false;
  372. item.number -= 1;
  373. this.pickup_code.pop();
  374. this.$forceUpdate();
  375. this.isInitial = false;
  376. this.getCard();
  377. } else {
  378. this.isAJAX = false;
  379. tools.error('减少操作失败')
  380. }
  381. })
  382. } else {
  383. tools.error('已无可减少商品')
  384. }
  385. },
  386. cardAllDel() {
  387. setShopIngDel({
  388. type: 2,
  389. school_id: this.schoolData.school_id
  390. }).then((res) => {
  391. if (res.code === 1) {
  392. this.pickup_code = [];
  393. this.isInitial = false;
  394. this.getCard();
  395. } else {
  396. tools.error('清空失败')
  397. }
  398. })
  399. },
  400. }
  401. }
  402. </script>
  403. <style scoped lang="scss">
  404. .wh44 {
  405. width: 44rpx;
  406. height: 44rpx;
  407. }
  408. .replace-take-box {
  409. .h-80 {
  410. width: 470rpx;
  411. height: 88rpx;
  412. }
  413. .right-only-right-red {
  414. box-sizing: border-box;
  415. width: 44rpx;
  416. height: 44rpx;
  417. border-radius: 12rpx;
  418. border: 1rpx solid #41ABF5;
  419. color: #41ABF5;
  420. }
  421. .right-only-right-add {
  422. width: 44rpx;
  423. height: 44rpx;
  424. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  425. border-radius: 12rpx;
  426. }
  427. .right-only-right-2 {
  428. min-width: 50rpx;
  429. }
  430. .w-514 {
  431. width: 514rpx;
  432. }
  433. .buy-card {
  434. z-index: 200;
  435. height: 828rpx;
  436. background-color: #fff;
  437. border-radius: 24rpx 24rpx 0rpx 0rpx;
  438. .buy-card-top {
  439. width: 100%;
  440. height: 92rpx;
  441. background: #FCF5DB;
  442. border-radius: 24rpx 24rpx 0rpx 0rpx;
  443. }
  444. .buy-card-item {
  445. width: 100%;
  446. height: 176rpx;
  447. margin-bottom: 32rpx;
  448. .item_img {
  449. width: 152rpx;
  450. height: 152rpx;
  451. border-radius: 12rpx;
  452. margin-right: 20rpx;
  453. }
  454. }
  455. }
  456. .h-120 {
  457. height: 120rpx;
  458. }
  459. .h-60 {
  460. height: 60rpx;
  461. }
  462. .w-474 {
  463. width: 474rpx;
  464. }
  465. .w-390 {
  466. width: 390rpx;
  467. margin-left: 38rpx;
  468. }
  469. .nav-box {
  470. height: 490rpx;
  471. position: relative;
  472. .bg-img {
  473. position: absolute;
  474. top: 0;
  475. left: 0;
  476. width: 100%;
  477. height: 490rpx;
  478. // z-index: -1;
  479. }
  480. .bottom-124 {
  481. bottom: -124rpx !important;
  482. }
  483. .address-box {
  484. z-index: 100;
  485. position: absolute;
  486. bottom: -64rpx;
  487. left: 24rpx;
  488. box-sizing: border-box;
  489. width: 702rpx;
  490. min-height: 136rpx;
  491. background: linear-gradient(182deg, #F1F9FF 0%, #FFFFFF 100%);
  492. box-shadow: 0rpx 0rpx 40rpx 0rpx rgba(172, 210, 235, 0.19);
  493. border-radius: 20rpx;
  494. border-image: linear-gradient(167deg, rgba(255, 255, 255, 1), rgba(208, 236, 255, 0.61)) 2 2;
  495. .address-1 {
  496. width: 100%;
  497. .qu-image {
  498. width: 40rpx;
  499. height: 49rpx;
  500. margin: 10rpx 10rpx 0 0;
  501. }
  502. }
  503. .address-2 {
  504. box-sizing: border-box;
  505. padding: 32rpx 0;
  506. }
  507. .address-img {
  508. width: 100rpx;
  509. height: 100rpx;
  510. border-radius: 8rpx;
  511. }
  512. .address-box-right {
  513. width: 32rpx;
  514. height: 32rpx;
  515. }
  516. }
  517. }
  518. .shop-buttom-money {
  519. width: 100%;
  520. height: 140rpx;
  521. background: rgba(255, 255, 255, 0.8);
  522. padding: 20rpx 24rpx;
  523. .shop-buttom-money-1 {
  524. width: 100%;
  525. height: 100%;
  526. background: #333333;
  527. border-radius: 200rpx;
  528. box-sizing: border-box;
  529. padding-left: 136rpx;
  530. // padding-right: 32rpx;
  531. position: relative;
  532. image {
  533. position: absolute;
  534. bottom: 0;
  535. left: 8rpx;
  536. width: 128rpx;
  537. height: 128rpx;
  538. }
  539. .shop-buttom-num {
  540. width: 32rpx;
  541. height: 32rpx;
  542. line-height: 32rpx;
  543. background: #FB3D03;
  544. border-radius: 50%;
  545. position: absolute;
  546. top: 36rpx;
  547. left: 82rpx;
  548. }
  549. .shop-buttom-money-2 {
  550. width: 200rpx;
  551. height: 100rpx;
  552. line-height: 100rpx;
  553. background: #41ABF5;
  554. border-radius: 0rpx 200rpx 200rpx 0rpx;
  555. }
  556. }
  557. }
  558. .list-box {
  559. .list-box-b {
  560. border-bottom: 1rpx solid #f9f9f9;
  561. }
  562. .list-item {
  563. width: 100%;
  564. min-height: 100rpx;
  565. margin-bottom: 50rpx;
  566. .item_img {
  567. width: 200rpx;
  568. height: 200rpx;
  569. border-radius: 20rpx;
  570. margin-right: 20rpx;
  571. }
  572. }
  573. .input-num {
  574. width: 100%;
  575. height: 92rpx;
  576. box-sizing: border-box;
  577. padding: 0 24rpx;
  578. background: #F6F6F6;
  579. border-radius: 20rpx;
  580. font-size: 32rpx;
  581. }
  582. .input-p {
  583. font-weight: 400;
  584. font-size: 28rpx;
  585. color: #FB3D03;
  586. }
  587. }
  588. }
  589. </style>