index.vue 22 KB

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