replace-take.vue 17 KB

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