index.vue 22 KB

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