index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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
  8. v-else
  9. @updateBooks="updateBooksList"
  10. @deleted="getLastOrder"
  11. :bookList="bookList"
  12. ref="scanBookList"
  13. ></scan-book-list>
  14. <!-- 底部固定按钮 -->
  15. <view class="bottom-fixed">
  16. <view class="btn-wrap mb-20">
  17. <button class="scan-btn flex-1" @click="handleScan">
  18. <u-icon name="scan" color="#FFFFFF" size="40"></u-icon>
  19. <text>扫码卖书</text>
  20. </button>
  21. <button class="isbn-btn flex-1" @click="goToInputISBN">
  22. <u-icon name="edit-pen" color="#4CD964" size="40"></u-icon>
  23. <text>输入ISBN</text>
  24. </button>
  25. </view>
  26. <view class="flex-a flex-j-b pad-20" style="padding-top: 0" v-if="bookList.length">
  27. <view class="left-info" style="min-width: 194px">
  28. <view class="flex-a common-text">
  29. 共<text class="color-red">{{ totalBooks }}</text
  30. >件 预估回收价 <text class="color-red">¥{{ totalPrice || 0 }}</text>
  31. </view>
  32. <text class="common-text tip">*旧书预估价格满 {{ orderInfo.minOrderMoney }} 元起收</text>
  33. </view>
  34. <button class="scan-btn next-btn" @click="onNext" :disabled="isDisabled">下一步</button>
  35. </view>
  36. <service-info v-if="bookList.length" :serviceList="serviceList"></service-info>
  37. </view>
  38. <InputIsbn ref="isbnPopup" @submit="checkBookISBN" />
  39. <!-- 套装书说明弹窗 -->
  40. <CommonDialog ref="setBookDialog" title="套装书说明" :showCancel="false" @confirm="handleSetBookConfirm">
  41. <text
  42. >套装书(ISBN码相同的系列书箱)只需扫描其中一册,扫码价即套装价。打包时请把所有单册统在一起或放在一个袋子里寄出。</text
  43. >
  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. <KindReminder ref="kindReminder" @start="handleStartSelling" @viewRules="handleViewRules" />
  67. <view class="customer-service">
  68. <button class="service-btn" open-type="contact">
  69. <image src="/static/img/kf.png" mode="widthFix" style="width: 126rpx; height: 140rpx"></image>
  70. </button>
  71. </view>
  72. <ConfirmBooks ref="confirmBooks" @incomplete="handleIncomplete" />
  73. <!-- 首单免费弹窗 -->
  74. <FirstOrderFreePopup ref="firstOrderFreePopup" />
  75. </view>
  76. </template>
  77. <script>
  78. import notScanned from "./components/notScanned.vue";
  79. import InputIsbn from "./components/InputIsbn.vue";
  80. import ScanBookList from "./components/ScanBookList.vue";
  81. import CommonDialog from "@/components/common-dialog.vue";
  82. import KindReminder from "./components/KindReminder.vue";
  83. import ServiceInfo from "./components/ServiceInfo.vue";
  84. import ConfirmBooks from "./components/ConfirmBooks.vue";
  85. import FirstOrderFreePopup from "./components/FirstOrderFreePopup.vue";
  86. export default {
  87. components: {
  88. notScanned,
  89. InputIsbn,
  90. ScanBookList,
  91. CommonDialog,
  92. KindReminder,
  93. ServiceInfo,
  94. ConfirmBooks,
  95. FirstOrderFreePopup,
  96. },
  97. data() {
  98. return {
  99. orderInfo: {},
  100. collapseState: {
  101. step1: false,
  102. step3: false,
  103. },
  104. scrollTop: 0,
  105. bookList: [],
  106. serviceList: [],
  107. currentBook: {},
  108. };
  109. },
  110. computed: {
  111. navbarBackground() {
  112. if (this.scrollTop > 0) {
  113. return "linear-gradient(180deg, #4CD964 0%, #5ff178 100%)";
  114. }
  115. return "transparent";
  116. },
  117. containerBg() {
  118. return this.bookList.length > 0
  119. ? "linear-gradient(180deg, #4CD964 0%, #F8F8F8 25%)"
  120. : "linear-gradient(180deg, #4CD964 0%, #ffffff 25%)";
  121. },
  122. containerPb() {
  123. return this.bookList.length > 0 ? "300rpx" : "110rpx";
  124. },
  125. totalBooks() {
  126. return this.bookList.reduce((sum, book) => sum + (book.num || 1), 0);
  127. },
  128. totalPrice() {
  129. return this.bookList.reduce((sum, book) => sum + book.recyclePrice * (book.num || 1), 0).toFixed(2);
  130. },
  131. isDisabled() {
  132. return this.totalPrice < this.orderInfo.minOrderMoney;
  133. },
  134. },
  135. onPageScroll(e) {
  136. this.$nextTick(() => {
  137. this.scrollTop = e.scrollTop;
  138. });
  139. },
  140. methods: {
  141. handleStart() {
  142. this.showPopup = true;
  143. },
  144. //套装书确认
  145. handleSetBookConfirm() {
  146. this.$refs.confirmBooks.openPopup(this.currentBook);
  147. },
  148. //书册补全
  149. handleIncomplete() {
  150. this.$refs.scanBookList.handleDeleteBook(this.currentBook);
  151. },
  152. //提交
  153. onNext() {
  154. let orderId = this.orderInfo.orderId;
  155. //预提交
  156. uni.$u.http.get("/token/order/preSubmit?orderId=" + orderId).then((res) => {
  157. if (res.code == 200) {
  158. if (res.data.code == 1 || res.data.code == 2) {
  159. uni.navigateTo({
  160. url: "/pages-home/pages/book-order",
  161. });
  162. uni.setStorageSync("orderId", orderId);
  163. } else {
  164. uni.showToast({
  165. icon: "none",
  166. title: res.msg,
  167. });
  168. }
  169. } else {
  170. uni.showToast({
  171. icon: "none",
  172. title: res.msg,
  173. });
  174. }
  175. });
  176. },
  177. updateBooksList(data) {
  178. this.bookList = data;
  179. },
  180. toggleCollapse(step) {
  181. this.$set(this.collapseState, step, !this.collapseState[step]);
  182. },
  183. handleScan() {
  184. uni.scanCode({
  185. scanType: ["barCode"],
  186. success: (res) => {
  187. this.checkBookISBN(res.result);
  188. },
  189. fail: () => {
  190. uni.showToast({
  191. title: "扫码失败",
  192. icon: "none",
  193. });
  194. },
  195. });
  196. },
  197. checkBookISBN(isbn) {
  198. uni.$u.http.get("/token/order/scanIsbn?isbn=" + isbn).then((res) => {
  199. if (res.code == 200) {
  200. let code = res.data.code;
  201. if (code == 1) {
  202. res.data.num = 1;
  203. res.data.recyclePrice = res.data.recycleMoney;
  204. this.currentBook = res.data;
  205. this.bookList.push(res.data);
  206. if (res.data.suit == 1) {
  207. this.$refs.setBookDialog.openPopup();
  208. }
  209. } else if (code == 2) {
  210. let item = this.bookList.find((v) => v.isbn === isbn);
  211. item.num = item.num + 1;
  212. } else {
  213. this.handleBookCode(res.data.code);
  214. }
  215. } else {
  216. uni.showToast({
  217. title: res.msg,
  218. icon: "none",
  219. });
  220. }
  221. });
  222. },
  223. //处理扫码之后不同的状态 0-扫码频繁 1-成功 2-本单已有该书,数量+1 3-没有该书 4-本书暂不回收 5-超过每单最大可卖数量 6-单个订单最多40本书
  224. handleBookCode(code) {
  225. if (code == 1) {
  226. this.bookList.push();
  227. }
  228. let tempKeys = [
  229. "tiredDialog",
  230. "",
  231. "",
  232. "noInfoDialog",
  233. "notAcceptDialog",
  234. "maxAcceptDialog",
  235. "orderMaxNumDialog",
  236. ];
  237. let key = tempKeys[code];
  238. if (key) {
  239. this.$refs[key].openPopup();
  240. }
  241. },
  242. //获取当前用户未提交订单 /api/token/order/lastOrder
  243. getLastOrder() {
  244. uni.$u.http.get("/token/order/lastOrder").then((res) => {
  245. if (res.code == 200) {
  246. this.orderInfo = res.data;
  247. if (res.data.showDialog == 1) {
  248. this.$refs.firstOrderFreePopup.openPopup();
  249. } else if (res.data.showDialog == 2) {
  250. this.$refs.kindReminder.openPopup();
  251. }
  252. this.bookList = res.data?.orderDetailList
  253. ? res.data.orderDetailList.map((v) => {
  254. v.orderId = res.data.orderId;
  255. return v;
  256. })
  257. : [];
  258. this.serviceList = res.data.serviceList || [];
  259. }
  260. });
  261. },
  262. goToScannedBooks() {
  263. uni.navigateTo({
  264. url: "/pages-home/pages/scaned-book",
  265. });
  266. },
  267. goToInputISBN() {
  268. this.$refs.isbnPopup.openPopup();
  269. },
  270. handleStartSelling() {
  271. // 标记已显示过温馨提示
  272. uni.setStorageSync("kindReminderShown", true);
  273. },
  274. },
  275. onShow() {
  276. // 获取上一个订单
  277. setTimeout(() => {
  278. this.getLastOrder();
  279. }, 300);
  280. },
  281. };
  282. </script>
  283. <style lang="scss" scoped>
  284. .customer-service {
  285. position: fixed;
  286. width: 126rpx;
  287. height: 140rpx;
  288. bottom: 20%;
  289. right: 0;
  290. z-index: 9;
  291. z-index: 999;
  292. button {
  293. height: max-content;
  294. background-color: transparent;
  295. padding: 0;
  296. }
  297. }
  298. .container {
  299. height: 100%;
  300. position: relative;
  301. overflow: auto;
  302. z-index: 1;
  303. /* #ifdef MP-WEIXIN */
  304. min-height: 100vh;
  305. /* #endif */
  306. /* #ifndef MP-WEIXIN */
  307. min-height: calc(100vh - 120rpx);
  308. /* #endif */
  309. &.book-list {
  310. padding-bottom: 300rpx;
  311. }
  312. padding-bottom: 130rpx;
  313. .nav-title {
  314. font-family: PingFang SC;
  315. font-weight: bold;
  316. font-size: 34rpx;
  317. color: #ffffff;
  318. padding-left: 40rpx;
  319. }
  320. }
  321. .common-text {
  322. font-family: PingFang SC;
  323. font-weight: 500;
  324. font-size: 28rpx;
  325. color: #999999;
  326. &.tip {
  327. color: #ff8a4b;
  328. }
  329. }
  330. .color-red {
  331. color: #ff0000;
  332. margin: 0 10rpx;
  333. }
  334. .bottom-fixed {
  335. position: fixed;
  336. left: 0;
  337. right: 0;
  338. bottom: 0;
  339. z-index: 9;
  340. background-color: #ffffff;
  341. /* #ifdef H5 */
  342. padding-bottom: 120rpx;
  343. /* #endif */
  344. .btn-wrap {
  345. display: flex;
  346. gap: 20rpx;
  347. padding: 20rpx;
  348. padding-bottom: 0;
  349. button {
  350. flex: 1;
  351. height: 88rpx;
  352. border-radius: 10rpx;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. gap: 10rpx;
  357. border: none;
  358. text {
  359. font-size: 32rpx;
  360. }
  361. &::after {
  362. border: none;
  363. }
  364. }
  365. .isbn-btn {
  366. background-color: #ffffff;
  367. color: #4cd964;
  368. border: 3rpx solid #4cd964;
  369. }
  370. }
  371. .scan-btn {
  372. background-color: #4cd964;
  373. color: #ffffff;
  374. }
  375. .next-btn {
  376. margin: 0;
  377. margin-left: 20rpx;
  378. &[aria-disabled="true"] {
  379. background-color: #cccccc;
  380. color: #ffffff;
  381. opacity: 0.7;
  382. cursor: not-allowed;
  383. }
  384. }
  385. }
  386. </style>