index.vue 21 KB

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