index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <view class="container" :style="{ background: containerBg }" :class="bookList.length ? 'book-list' : 'no-list'">
  3. <u-navbar :is-back="false" :border-bottom="false" :background="{ background: navbarBackground }">
  4. <text class="nav-title">卖书给书嗨</text>
  5. </u-navbar>
  6. <not-scanned v-if="!bookList.length"></not-scanned>
  7. <scan-book-list v-else @updateBooks="updateBooksList" @deleted="handleDeleteBook" :bookList="bookList"
  8. ref="scanBookList" @upsell="handleUpsell" @refresh="getLastOrder"></scan-book-list>
  9. <!-- 底部固定按钮 -->
  10. <view class="bottom-fixed">
  11. <view class="btn-wrap mb-20">
  12. <button class="scan-btn flex-1" @click="handleScan">
  13. <u-icon name="scan" color="#FFFFFF" size="40"></u-icon>
  14. <text>扫码卖书</text>
  15. </button>
  16. <button class="isbn-btn flex-1" @click="goToInputISBN">
  17. <u-icon name="edit-pen" color="#4CD964" size="40"></u-icon>
  18. <text>输入ISBN</text>
  19. </button>
  20. </view>
  21. <view class="flex-a flex-j-b pad-20" style="padding-top: 0" v-if="bookList.length">
  22. <view class="left-info" style="min-width: 194px">
  23. <view class="flex-a common-text">
  24. 共
  25. <text class="color-red">{{ orderInfo.totalNum }}</text>
  26. 件 预估回收价
  27. <text class="color-red">¥{{ orderInfo.totalRecycleMoney || 0 }}</text>
  28. </view>
  29. <text class="common-text tip">
  30. *<text v-if="orderInfo.minOrderNum > 1">旧书满{{ orderInfo.minOrderNum
  31. }}本,{{ orderInfo.recycleOrderAndOr == 2 ? '且' : '或' }}</text>预估价格满{{ orderInfo.minOrderMoney}}元起收
  32. </text>
  33. </view>
  34. <button class="scan-btn next-btn" @click="handleValidate" :disabled="isDisabled">
  35. 下一步
  36. </button>
  37. </view>
  38. <service-info v-if="bookList.length" :serviceList="serviceList"
  39. :firstOrder="orderInfo.firstOrder"></service-info>
  40. </view>
  41. <InputIsbn ref="isbnPopup" @submit="(isbn) => checkBookISBN(isbn, 'input')" />
  42. <!-- 套装书说明弹窗 -->
  43. <CommonDialog ref="setBookDialog" title="套装书说明" :showCancel="false" @confirm="handleSetBookConfirm">
  44. <text>套装书(ISBN码相同的系列书箱)只需扫描其中一册,扫码价即套装价。打包时请把所有单册统在一起或放在一个袋子里寄出。</text>
  45. </CommonDialog>
  46. <!-- 暂不回收弹窗 -->
  47. <CommonDialog ref="notAcceptDialog" title="暂不回收" :showCancel="false">
  48. <text>这本书暂时不回收,请您过段时间再来试试~</text>
  49. </CommonDialog>
  50. <!-- 暂无信息弹窗 -->
  51. <CommonDialog ref="noInfoDialog" title="暂无信息" :showCancel="false">
  52. <text>抱歉,没有该书的信息,书嗨会定期补充图书信息,请您过段时间再来试试~</text>
  53. </CommonDialog>
  54. <!-- 扫累了弹窗 -->
  55. <CommonDialog ref="tiredDialog" title="温馨提示" :showCancel="false">
  56. <text>扫累了,休息休息吧~</text>
  57. </CommonDialog>
  58. <!-- 该书超出最大回收本数 maxAcceptDialog-->
  59. <CommonDialog ref="maxAcceptDialog" title="温馨提示" :showCancel="false">
  60. <text>该书超出最大回收本数</text>
  61. </CommonDialog>
  62. <!-- 单个订单最多40本书 orderMaxNumDialog-->
  63. <CommonDialog ref="orderMaxNumDialog" title="温馨提示" :showCancel="false">
  64. <text>单个订单最多40本书</text>
  65. </CommonDialog>
  66. <!-- 删除活动书籍弹窗 -->
  67. <common-dialog ref="deleteDialog" title="温馨提示" @confirm="confirmDelete">
  68. <text>{{
  69. deleteBook.upsellMoney
  70. ? "此书为限时加价收图书,删除后再次添加将失去加价收资格,确定删除吗?"
  71. : "确定删除这本图书吗?"
  72. }}</text>
  73. </common-dialog>
  74. <!-- 此订单还有未加价的图书,提交订单后将失去加价资格,确定提交吗? -->
  75. <common-dialog ref="noUpsellDialog" title="温馨提示" @confirm="onNext">
  76. <text>此订单还有未加价的图书,提交订单后将失去加价资格,确定提交吗?</text>
  77. </common-dialog>
  78. <!-- 温馨提示弹窗 -->
  79. <KindReminder ref="kindReminder" @start="handleStartSelling" />
  80. <!-- 客服按钮 -->
  81. <FloatingDrag :width="126" :height="140" :initial-position="servicePosition"
  82. @position-change="handlePositionChange">
  83. <!-- #ifdef MP-ALIPAY -->
  84. <button class="service-btn" @click="navigateToCustomerService">
  85. <image src="/static/img/kf.png" mode="widthFix" style="width: 126rpx; height: 140rpx"></image>
  86. </button>
  87. <!-- #endif -->
  88. <!-- #ifndef MP-ALIPAY -->
  89. <button class="service-btn" open-type="contact">
  90. <image src="/static/img/kf.png" mode="widthFix" style="width: 126rpx; height: 140rpx"></image>
  91. </button>
  92. <!-- #endif -->
  93. </FloatingDrag>
  94. <ConfirmBooks ref="confirmBooks" @incomplete="handleIncomplete" />
  95. <!-- 首单免费弹窗 -->
  96. <FirstOrderFreePopup ref="firstOrderFreePopup" />
  97. <!-- 图书加价弹窗 -->
  98. <UpsellBook ref="upsellRef" @scan="handleScanCode" />
  99. <!-- 加价二维码弹窗 -->
  100. <UpsellQrcode ref="upsellQrcodeRef" />
  101. <!-- 加价规则弹窗 -->
  102. <UpsellRules ref="upsellRulesRef" />
  103. <!-- 仅承接加价分享 -->
  104. <ActivityHost ref="activityHost" :enable-reduce="false" @refresh-order="getLastOrder"
  105. @view-rules="handleViewSellRules" />
  106. <policy-consent-host />
  107. </view>
  108. </template>
  109. <script>
  110. import notScanned from "./components/notScanned.vue";
  111. import InputIsbn from "./components/InputIsbn.vue";
  112. import ScanBookList from "./components/ScanBookList.vue";
  113. import CommonDialog from "@/components/common-dialog.vue";
  114. import KindReminder from "./components/KindReminder.vue";
  115. import ServiceInfo from "./components/ServiceInfo.vue";
  116. import ConfirmBooks from "./components/ConfirmBooks.vue";
  117. import FirstOrderFreePopup from "./components/FirstOrderFreePopup.vue";
  118. import UpsellBook from "./components/upsell-book.vue";
  119. import UpsellRules from "./components/upsell-rules.vue";
  120. import UpsellQrcode from "./components/upsell-qrcode.vue";
  121. import ActivityHost from "@/components/activity-host.vue";
  122. import PolicyConsentHost from "@/components/policy-consent-host.vue";
  123. import tabbarBlockMixin from "@/utils/tabbar-block-mixin.js";
  124. import FloatingDrag from "@/components/floating-drag.vue";
  125. const app = getApp();
  126. export default {
  127. mixins: [tabbarBlockMixin],
  128. components: {
  129. notScanned,
  130. InputIsbn,
  131. ScanBookList,
  132. CommonDialog,
  133. KindReminder,
  134. ServiceInfo,
  135. ConfirmBooks,
  136. FirstOrderFreePopup,
  137. UpsellBook,
  138. UpsellRules,
  139. UpsellQrcode,
  140. ActivityHost,
  141. PolicyConsentHost,
  142. FloatingDrag,
  143. },
  144. data() {
  145. return {
  146. orderInfo: {},
  147. collapseState: {
  148. step1: false,
  149. step3: false,
  150. },
  151. scrollTop: 0,
  152. bookList: [],
  153. serviceList: [],
  154. currentBook: {},
  155. // 客服按钮位置
  156. servicePosition: {
  157. left: "auto",
  158. right: 0,
  159. bottom: "20%",
  160. },
  161. shareData: {},
  162. deleteBook: {},
  163. pendingActivityOptions: {},
  164. };
  165. },
  166. computed: {
  167. navbarBackground() {
  168. if (this.scrollTop > 0) {
  169. return "linear-gradient(180deg, #4CD964 0%, #5ff178 100%)";
  170. }
  171. return "transparent";
  172. },
  173. containerBg() {
  174. return this.bookList.length > 0
  175. ? "linear-gradient(180deg, #4CD964 0%, #F8F8F8 25%)"
  176. : "linear-gradient(180deg, #4CD964 0%, #ffffff 25%)";
  177. },
  178. containerPb() {
  179. return this.bookList.length > 0 ? "300rpx" : "110rpx";
  180. },
  181. totalBooks() {
  182. return this.bookList.reduce((sum, book) => sum + (book.num || 1), 0);
  183. },
  184. totalPrice() {
  185. return this.bookList
  186. .reduce(
  187. (sum, book) =>
  188. sum + book.recyclePrice * (book.num || 1) + book.currUpsellMoney ||
  189. 0,
  190. 0
  191. )
  192. .toFixed(2);
  193. },
  194. isDisabled() {
  195. //minOrderNum或minOrderMoney可能没有值,
  196. let { minOrderNum, minOrderMoney } = this.orderInfo
  197. if (!minOrderMoney && !minOrderNum) return false
  198. //minOrderMoney没有值,minOrderNum有值
  199. if (minOrderNum && !minOrderMoney) return minOrderNum > this.totalBooks
  200. if (minOrderNum && !minOrderMoney) return minOrderMoney > this.totalPrice
  201. if (minOrderNum && minOrderMoney) return minOrderNum > this.totalBooks && minOrderMoney > this.totalPrice
  202. },
  203. },
  204. onPageScroll(e) {
  205. this.$nextTick(() => {
  206. this.scrollTop = e.scrollTop;
  207. });
  208. },
  209. // 分享配置
  210. onShareAppMessage(res) {
  211. return this.$refs.activityHost?.getShareAppMessage(res) || {
  212. title: "书嗨",
  213. page: "/pages/home/index",
  214. };
  215. },
  216. // 分享到朋友圈
  217. onShareTimeline(res) {
  218. return this.$refs.activityHost?.getShareTimeline(res) || {
  219. title: "书嗨",
  220. page: "/pages/home/index",
  221. };
  222. },
  223. onReady() {
  224. // 获取屏幕宽度和高度
  225. uni.getSystemInfo({
  226. success: (res) => {
  227. this.screenWidth = res.windowWidth;
  228. this.screenHeight = res.windowHeight;
  229. },
  230. });
  231. this.$nextTick(() => {
  232. if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
  233. this.$refs.activityHost?.handlePageOptions(this.pendingActivityOptions, app.globalData.isColdLaunch);
  234. }
  235. this.pendingActivityOptions = {};
  236. });
  237. },
  238. onShow() {
  239. this.$updateCartBadge();
  240. if (!app.globalData.isColdLaunch) {
  241. if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
  242. return
  243. }
  244. let token = uni.getStorageSync("token");
  245. if (token) {
  246. this.getLastOrder();
  247. }
  248. return
  249. }
  250. },
  251. //针对多次扫码的热启动场景,需要判断是否是冷启动
  252. onLoad(options) {
  253. console.log(options, app.globalData.isColdLaunch, "onLoad");
  254. this.pendingActivityOptions = options || {};
  255. },
  256. // #ifdef MP-ALIPAY
  257. onPullDownRefresh() {
  258. this.getLastOrder()
  259. },
  260. // #endif
  261. // 清理活动缓存
  262. onUnload() {
  263. uni.removeStorageSync("upsellCode");
  264. uni.removeStorageSync("reduceCode");
  265. },
  266. methods: {
  267. //扫码助力
  268. handleScanCode(data = {}) {
  269. this.$refs.upsellQrcodeRef.open(data);
  270. },
  271. //查看活动规则
  272. handleViewSellRules() {
  273. this.$refs.upsellRulesRef.open();
  274. },
  275. //删除书籍
  276. handleDeleteBook(book) {
  277. this.deleteBook = book;
  278. this.$refs.deleteDialog.openPopup(book);
  279. },
  280. //支付宝小程序的客服
  281. navigateToCustomerService() {
  282. uni.navigateTo({
  283. url: "/pages-mine/pages/customer-service",
  284. });
  285. },
  286. confirmDelete() {
  287. uni.$u.http
  288. .post("/token/order/removeBook", {
  289. orderId: this.deleteBook.orderId,
  290. isbn: this.deleteBook.isbn,
  291. })
  292. .then((res) => {
  293. if (res.code == 200) {
  294. this.$u.toast("删除成功");
  295. this.getLastOrder();
  296. }
  297. });
  298. },
  299. handleStart() {
  300. this.showPopup = true;
  301. },
  302. //套装书确认
  303. handleSetBookConfirm() {
  304. this.$refs.confirmBooks.openPopup(this.currentBook);
  305. },
  306. //书册补全
  307. handleIncomplete() {
  308. this.$refs.scanBookList.handleDeleteBook(this.currentBook);
  309. },
  310. handleValidate() {
  311. if (this.bookList.some((v) => v.canInvite == 1)) {
  312. this.$refs.noUpsellDialog.openPopup();
  313. } else {
  314. this.onNext();
  315. }
  316. },
  317. hasActivityEntryOptions(options = {}) {
  318. return !!(options.scene || options.upsellCode || options.reduceCode);
  319. },
  320. //提交
  321. onNext() {
  322. let orderId = this.orderInfo.orderId;
  323. //预提交
  324. uni.$u.http
  325. .get("/token/order/preSubmit?orderId=" + orderId)
  326. .then((res) => {
  327. if (res.code == 200) {
  328. if (res.data.code == 1 || res.data.code == 2) {
  329. uni.navigateTo({
  330. url: "/pages-home/pages/book-order",
  331. });
  332. uni.setStorageSync("orderId", orderId);
  333. } else {
  334. uni.showToast({
  335. icon: "none",
  336. title: res.msg,
  337. duration: 3000,
  338. });
  339. }
  340. }
  341. // res.code !== 200 已由请求拦截器 toast,无需重复弹出
  342. });
  343. },
  344. // 加价
  345. handleUpsell(book) {
  346. this.$refs.upsellRef.open(book);
  347. },
  348. updateBooksList(data, book) {
  349. this.bookList = data;
  350. // book.upsellMoney && this.getLastOrder();
  351. this.getLastOrder();
  352. },
  353. toggleCollapse(step) {
  354. this.$set(this.collapseState, step, !this.collapseState[step]);
  355. },
  356. handleScan() {
  357. uni.scanCode({
  358. scanType: ["barCode"],
  359. success: (res) => {
  360. this.checkBookISBN(res.result, "scan");
  361. },
  362. fail: () => {
  363. uni.showToast({
  364. title: "扫码失败",
  365. icon: "none",
  366. });
  367. },
  368. });
  369. },
  370. checkBookISBN(isbn, type) {
  371. let url =
  372. type == "input"
  373. ? `/token/order/inputIsbn?isbn=${isbn}`
  374. : `/token/order/scanIsbn?isbn=${isbn}`;
  375. uni.$u.http.get(url).then((res) => {
  376. if (res.code == 200) {
  377. let code = res.data.code;
  378. if (code == 1) {
  379. res.data.num = 1;
  380. res.data.status = 1;
  381. res.data.recyclePrice = res.data.recycleMoney;
  382. this.currentBook = res.data;
  383. this.bookList.unshift(res.data);
  384. if (res.data.suit == 1) {
  385. this.$refs.setBookDialog.openPopup();
  386. }
  387. if (res.data.canInvite == 1) {
  388. this.$refs.upsellRef.open(res.data);
  389. }
  390. } else if (code == 2) {
  391. let item = this.bookList.find((v) => v.isbn === isbn);
  392. item.num = item.num + 1;
  393. if (res.data.canInvite == 1) {
  394. this.$refs.upsellRef.open(res.data);
  395. }
  396. } else {
  397. this.handleBookCode(res.data.code);
  398. }
  399. this.getLastOrder();
  400. } else {
  401. uni.showToast({
  402. title: res.msg,
  403. icon: "none",
  404. });
  405. }
  406. });
  407. },
  408. //处理扫码之后不同的状态 0-扫码频繁 1-成功 2-本单已有该书,数量+1 3-没有该书 4-本书暂不回收 5-超过每单最大可卖数量 6-单个订单最多40本书
  409. handleBookCode(code) {
  410. if (code == 1) {
  411. this.bookList.push();
  412. }
  413. let tempKeys = [
  414. "tiredDialog",
  415. "",
  416. "",
  417. "noInfoDialog",
  418. "notAcceptDialog",
  419. "maxAcceptDialog",
  420. "orderMaxNumDialog",
  421. ];
  422. let key = tempKeys[code];
  423. if (key) {
  424. this.$refs[key].openPopup();
  425. }
  426. },
  427. //获取当前用户未提交订单 /api/token/order/lastOrder
  428. getLastOrder() {
  429. uni.$u.http.get("/token/order/lastOrder").then((res) => {
  430. if (res.code == 200) {
  431. this.orderInfo = res.data;
  432. if (res.data.showDialog == 1) {
  433. this.$refs.firstOrderFreePopup.openPopup();
  434. } else if (res.data.showDialog == 2) {
  435. this.$refs.kindReminder.openPopup();
  436. }
  437. this.bookList = res.data?.orderDetailList
  438. ? res.data.orderDetailList.map((v) => {
  439. v.orderId = res.data.orderId;
  440. return v;
  441. })
  442. : [];
  443. this.serviceList = res.data.serviceList || [];
  444. } else {
  445. uni.showToast({
  446. title: res.msg,
  447. icon: "none",
  448. });
  449. }
  450. }).finally(() => {
  451. // #ifdef MP-ALIPAY
  452. my.stopPullDownRefresh()
  453. // #endif
  454. })
  455. },
  456. goToScannedBooks() {
  457. uni.navigateTo({
  458. url: "/pages-home/pages/scaned-book",
  459. });
  460. },
  461. goToInputISBN() {
  462. this.$refs.isbnPopup.openPopup();
  463. },
  464. handleStartSelling() {
  465. // 标记已显示过温馨提示
  466. uni.setStorageSync("kindReminderShown", true);
  467. },
  468. // 处理位置变更
  469. handlePositionChange(position) {
  470. this.servicePosition = position;
  471. },
  472. },
  473. };
  474. </script>
  475. <style lang="scss" scoped>
  476. .service-btn {
  477. height: max-content;
  478. background-color: transparent;
  479. padding: 0;
  480. }
  481. .container {
  482. height: 100%;
  483. position: relative;
  484. overflow: auto;
  485. z-index: 1;
  486. /* #ifdef MP-WEIXIN */
  487. min-height: 100vh;
  488. /* #endif */
  489. /* #ifndef MP-WEIXIN */
  490. min-height: calc(100vh - 120rpx);
  491. /* #endif */
  492. &.book-list {
  493. padding-bottom: 300rpx;
  494. }
  495. padding-bottom: 130rpx;
  496. .nav-title {
  497. font-family: PingFang SC;
  498. font-weight: bold;
  499. font-size: 34rpx;
  500. color: #ffffff;
  501. padding-left: 40rpx;
  502. /* #ifdef MP-ALIPAY */
  503. padding-left: 70rpx;
  504. /* #endif */
  505. }
  506. }
  507. .common-text {
  508. font-family: PingFang SC;
  509. font-weight: 500;
  510. font-size: 28rpx;
  511. color: #999999;
  512. &.tip {
  513. color: #ff8a4b;
  514. font-size: 26rpx;
  515. }
  516. }
  517. .color-red {
  518. color: #ff0000;
  519. margin: 0 10rpx;
  520. }
  521. .color-green {
  522. color: #276f1e;
  523. }
  524. .bottom-fixed {
  525. position: fixed;
  526. left: 0;
  527. right: 0;
  528. bottom: 0;
  529. z-index: 9;
  530. background-color: #ffffff;
  531. /* #ifdef H5 */
  532. padding-bottom: 120rpx;
  533. /* #endif */
  534. .btn-wrap {
  535. display: flex;
  536. gap: 20rpx;
  537. padding: 20rpx;
  538. padding-bottom: 0;
  539. button {
  540. flex: 1;
  541. height: 88rpx;
  542. border-radius: 10rpx;
  543. display: flex;
  544. align-items: center;
  545. justify-content: center;
  546. gap: 10rpx;
  547. border: none;
  548. text {
  549. font-size: 32rpx;
  550. }
  551. &::after {
  552. border: none;
  553. }
  554. }
  555. .isbn-btn {
  556. background-color: #ffffff;
  557. color: #4cd964;
  558. border: 3rpx solid #4cd964;
  559. }
  560. }
  561. .scan-btn {
  562. background-color: #4cd964;
  563. color: #ffffff;
  564. }
  565. .next-btn {
  566. margin: 0;
  567. margin-left: 40rpx;
  568. &[aria-disabled="true"] {
  569. background-color: #cccccc;
  570. color: #ffffff;
  571. opacity: 0.7;
  572. cursor: not-allowed;
  573. }
  574. }
  575. }
  576. </style>