index.vue 22 KB

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