index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. } else {
  192. uni.showToast({
  193. title: res.msg,
  194. icon: "none",
  195. });
  196. }
  197. });
  198. },
  199. //处理扫码之后不同的状态 0-扫码频繁 1-成功 2-本单已有该书,数量+1 3-没有该书 4-本书暂不回收 5-超过每单最大可卖数量 6-单个订单最多40本书
  200. handleBookCode(code) {
  201. if (code == 1) {
  202. this.bookList.push();
  203. }
  204. let tempKeys = [
  205. "tiredDialog",
  206. "",
  207. "",
  208. "noInfoDialog",
  209. "notAcceptDialog",
  210. "maxAcceptDialog",
  211. "orderMaxNumDialog",
  212. ];
  213. let key = tempKeys[code];
  214. if (key) {
  215. this.$refs[key].openPopup();
  216. }
  217. },
  218. //获取当前用户未提交订单 /api/token/order/lastOrder
  219. getLastOrder() {
  220. uni.$u.http.get("/token/order/lastOrder").then((res) => {
  221. if (res.code == 200) {
  222. this.orderInfo = res.data;
  223. this.bookList = res.data?.orderDetailList
  224. ? res.data.orderDetailList.map((v) => {
  225. v.orderId = res.data.orderId;
  226. return v;
  227. })
  228. : [];
  229. this.serviceList = res.data.serviceList || [];
  230. }
  231. });
  232. },
  233. goToScannedBooks() {
  234. uni.navigateTo({
  235. url: "/pages-home/pages/scaned-book",
  236. });
  237. },
  238. goToRules() {
  239. uni.navigateTo({
  240. url: "/pages/rules/index",
  241. });
  242. },
  243. goToInputISBN() {
  244. this.$refs.isbnPopup.openPopup();
  245. },
  246. handleStartSelling() {
  247. // 标记已显示过温馨提示
  248. uni.setStorageSync("kindReminderShown", true);
  249. },
  250. handleViewRules() {
  251. // 可以在这里添加额外的逻辑,如果需要的话
  252. },
  253. },
  254. onShow() {
  255. // 获取上一个订单
  256. setTimeout(() => {
  257. this.getLastOrder();
  258. }, 300);
  259. // 显示温馨提示弹窗
  260. if (!uni.getStorageSync("kindReminderShown")) {
  261. this.$nextTick(() => {
  262. this.$refs.kindReminder.openPopup();
  263. });
  264. }
  265. },
  266. };
  267. </script>
  268. <style lang="scss" scoped>
  269. .customer-service {
  270. position: fixed;
  271. width: 126rpx;
  272. height: 140rpx;
  273. bottom: 20%;
  274. right: 0;
  275. z-index: 9;
  276. z-index: 999;
  277. button {
  278. height: max-content;
  279. background-color: transparent;
  280. padding: 0;
  281. }
  282. }
  283. .container {
  284. height: 100%;
  285. position: relative;
  286. overflow: auto;
  287. z-index: 1;
  288. /* #ifdef MP-WEIXIN */
  289. min-height: 100vh;
  290. /* #endif */
  291. /* #ifndef MP-WEIXIN */
  292. min-height: calc(100vh - 120rpx);
  293. /* #endif */
  294. &.book-list {
  295. padding-bottom: 300rpx;
  296. }
  297. padding-bottom: 130rpx;
  298. .nav-title {
  299. font-family: PingFang SC;
  300. font-weight: bold;
  301. font-size: 34rpx;
  302. color: #ffffff;
  303. padding-left: 40rpx;
  304. }
  305. }
  306. .common-text {
  307. font-family: PingFang SC;
  308. font-weight: 500;
  309. font-size: 28rpx;
  310. color: #999999;
  311. &.tip {
  312. color: #ff8a4b;
  313. }
  314. }
  315. .color-red {
  316. color: #ff0000;
  317. margin: 0 10rpx;
  318. }
  319. .bottom-fixed {
  320. position: fixed;
  321. left: 0;
  322. right: 0;
  323. bottom: 0;
  324. z-index: 9;
  325. background-color: #ffffff;
  326. /* #ifdef H5 */
  327. padding-bottom: 120rpx;
  328. /* #endif */
  329. .btn-wrap {
  330. display: flex;
  331. gap: 20rpx;
  332. padding: 20rpx;
  333. padding-bottom: 0;
  334. button {
  335. flex: 1;
  336. height: 88rpx;
  337. border-radius: 10rpx;
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. gap: 10rpx;
  342. border: none;
  343. text {
  344. font-size: 32rpx;
  345. }
  346. &::after {
  347. border: none;
  348. }
  349. }
  350. .isbn-btn {
  351. background-color: #ffffff;
  352. color: #4cd964;
  353. border: 3rpx solid #4cd964;
  354. }
  355. }
  356. .scan-btn {
  357. background-color: #4cd964;
  358. color: #ffffff;
  359. }
  360. .next-btn {
  361. margin: 0;
  362. margin-left: 20rpx;
  363. &[aria-disabled="true"] {
  364. background-color: #cccccc;
  365. color: #ffffff;
  366. opacity: 0.7;
  367. cursor: not-allowed;
  368. }
  369. }
  370. }
  371. </style>