index.vue 24 KB

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