index.vue 12 KB

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