index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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="getLastOrder"
  8. :bookList="bookList"></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">
  23. <view class="flex-a common-text">
  24. 共<text class="color-red">{{ totalBooks }}</text>件
  25. 预估回收价 <text class="color-red">¥{{ totalPrice || 0 }}</text>
  26. </view>
  27. <text class="common-text tip">*旧书预估价格满30元起收</text>
  28. </view>
  29. <button class="scan-btn next-btn" @click="onNext">下一步</button>
  30. </view>
  31. <view class="service-icons" v-if="bookList.length">
  32. <view class="icon-item" v-for="(item, index) in serviceItems" :key="index" @tap="showServiceGuarantee">
  33. <u-icon :name="item.icon" size="32" color="#FFF6ED"></u-icon>
  34. <text style="margin-left: 6rpx;">{{ item.text }}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <InputIsbn ref="isbnPopup" @submit="checkBookISBN" />
  39. <!-- 套装书说明弹窗 -->
  40. <CommonDialog ref="setBookDialog" title="套装书说明" :showCancel="false">
  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. </view>
  64. </template>
  65. <script>
  66. import notScanned from './components/notScanned.vue'
  67. import InputIsbn from './components/InputIsbn.vue';
  68. import ScanBookList from './components/ScanBookList.vue';
  69. import CommonDialog from '@/components/common-dialog.vue';
  70. export default {
  71. components: {
  72. notScanned,
  73. InputIsbn,
  74. ScanBookList,
  75. CommonDialog
  76. },
  77. data() {
  78. return {
  79. collapseState: {
  80. step1: false,
  81. step3: false
  82. },
  83. scrollTop: 0,
  84. bookList: [],
  85. serviceItems: [{
  86. icon: 'gift',
  87. text: '免费退回'
  88. },
  89. {
  90. icon: 'clock',
  91. text: '24小时验'
  92. },
  93. {
  94. icon: 'rmb-circle',
  95. text: '极速打款'
  96. },
  97. {
  98. icon: 'shield',
  99. text: '卖亏必赔'
  100. }
  101. ]
  102. }
  103. },
  104. computed: {
  105. navbarBackground() {
  106. if (this.scrollTop > 0) {
  107. return 'linear-gradient(180deg, #4CD964 0%, #5ff178 100%)'
  108. }
  109. return 'transparent'
  110. },
  111. containerBg() {
  112. return this.bookList.length > 0 ? 'linear-gradient(180deg, #4CD964 0%, #F8F8F8 25%)' :
  113. 'linear-gradient(180deg, #4CD964 0%, #ffffff 25%)'
  114. },
  115. containerPb() {
  116. return this.bookList.length > 0 ? '300rpx' : '110rpx'
  117. },
  118. totalBooks() {
  119. return this.bookList.reduce((sum, book) => sum + (book.num || 1), 0)
  120. },
  121. totalPrice() {
  122. return this.bookList.reduce((sum, book) => sum + book.recyclePrice * (book.num || 1), 0).toFixed(2)
  123. }
  124. },
  125. onPageScroll(e) {
  126. this.$nextTick(() => {
  127. this.scrollTop = e.scrollTop
  128. })
  129. },
  130. methods: {
  131. //提交
  132. onNext() {
  133. let orderId = this.bookList[0].orderId
  134. //预提交
  135. uni.$u.http.get('/token/order/preSubmit?orderId=' + orderId).then(res => {
  136. if (res.code == 200) {
  137. if (res.data.code == 1 || res.data.code == 2) {
  138. uni.navigateTo({
  139. url: "/pages-home/pages/book-order"
  140. })
  141. uni.setStorageSync('orderId', orderId)
  142. } else {
  143. uni.showToast({
  144. icon: 'none',
  145. title: res.msg
  146. })
  147. }
  148. } else {
  149. uni.showToast({
  150. icon: 'none',
  151. title: res.msg
  152. })
  153. }
  154. })
  155. },
  156. updateBooksList(data) {
  157. this.bookList = data
  158. },
  159. toggleCollapse(step) {
  160. this.$set(this.collapseState, step, !this.collapseState[step])
  161. },
  162. handleScan() {
  163. uni.scanCode({
  164. scanType: ['barCode'],
  165. success: (res) => {
  166. this.checkBookISBN(res.result)
  167. },
  168. fail: () => {
  169. uni.showToast({
  170. title: '扫码失败',
  171. icon: 'none'
  172. })
  173. }
  174. })
  175. },
  176. checkBookISBN(isbn) {
  177. uni.$u.http.get('/token/order/scanIsbn?isbn=' + isbn).then(res => {
  178. if (res.code == 200) {
  179. let code = res.data.code
  180. if (code == 1) {
  181. res.data.num = 1
  182. this.bookList.push(res.data)
  183. } else if (code == 2) {
  184. let item = this.bookList.find(v => v.isbn === isbn)
  185. item.num = item.num + 1
  186. } else {
  187. this.handleBookCode(res.data.code)
  188. }
  189. }
  190. })
  191. },
  192. //处理扫码之后不同的状态 0-扫码频繁 1-成功 2-本单已有该书,数量+1 3-没有该书 4-本书暂不回收 5-超过每单最大可卖数量 6-单个订单最多40本书
  193. handleBookCode(code) {
  194. if (code == 1) {
  195. this.bookList.push()
  196. }
  197. let tempKeys = ['tiredDialog', '', '', 'noInfoDialog', "notAcceptDialog", 'maxAcceptDialog',
  198. 'orderMaxNumDialog'
  199. ]
  200. let key = tempKeys[code]
  201. if (key) {
  202. this.$refs[key].openPopup()
  203. }
  204. },
  205. //获取当前用户未提交订单 /api/token/order/lastOrder
  206. getLastOrder() {
  207. uni.$u.http.get('/token/order/lastOrder').then(res => {
  208. if (res.code == 200) {
  209. this.bookList = res.data?.orderDetailList ? res.data.orderDetailList.map(v => {
  210. v.orderId = res.data.orderId
  211. return v
  212. }) : []
  213. }
  214. })
  215. },
  216. goToScannedBooks() {
  217. uni.navigateTo({
  218. url: '/pages-home/pages/scaned-book'
  219. })
  220. },
  221. goToRules() {
  222. uni.navigateTo({
  223. url: '/pages/rules/index'
  224. })
  225. },
  226. showServiceGuarantee() {
  227. this.$refs.serviceGuarantee.openPopup()
  228. },
  229. goToInputISBN() {
  230. this.$refs.isbnPopup.openPopup()
  231. }
  232. },
  233. onShow() {
  234. setTimeout(() => {
  235. this.getLastOrder()
  236. }, 300)
  237. }
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .container {
  242. height: 100%;
  243. position: relative;
  244. overflow: auto;
  245. z-index: 1;
  246. /* #ifdef MP-WEIXIN */
  247. min-height: 100vh;
  248. /* #endif */
  249. /* #ifndef MP-WEIXIN */
  250. min-height: calc(100vh - 120rpx);
  251. /* #endif */
  252. &.book-list {
  253. padding-bottom: 300rpx;
  254. }
  255. padding-bottom: 130rpx;
  256. .nav-title {
  257. font-family: PingFang SC;
  258. font-weight: bold;
  259. font-size: 34rpx;
  260. color: #FFFFFF;
  261. padding-left: 40rpx;
  262. }
  263. }
  264. .common-text {
  265. font-family: PingFang SC;
  266. font-weight: 500;
  267. font-size: 28rpx;
  268. color: #999999;
  269. &.tip {
  270. color: #FF8A4B;
  271. }
  272. }
  273. .color-red {
  274. color: #ff0000;
  275. margin: 0 10rpx;
  276. }
  277. .bottom-fixed {
  278. position: fixed;
  279. left: 0;
  280. right: 0;
  281. bottom: 0;
  282. z-index: 9;
  283. background-color: #ffffff;
  284. /* #ifdef H5 */
  285. padding-bottom: 120rpx;
  286. /* #endif */
  287. .btn-wrap {
  288. display: flex;
  289. gap: 20rpx;
  290. padding: 20rpx;
  291. padding-bottom: 0;
  292. button {
  293. flex: 1;
  294. height: 88rpx;
  295. border-radius: 10rpx;
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. gap: 10rpx;
  300. border: none;
  301. text {
  302. font-size: 32rpx;
  303. }
  304. &::after {
  305. border: none;
  306. }
  307. }
  308. .isbn-btn {
  309. background-color: #FFFFFF;
  310. color: #4CD964;
  311. border: 3rpx solid #4CD964;
  312. }
  313. }
  314. .scan-btn {
  315. background-color: #4CD964;
  316. color: #FFFFFF;
  317. }
  318. .next-btn {
  319. margin: 0;
  320. margin-left: 20rpx;
  321. }
  322. }
  323. .service-icons {
  324. display: flex;
  325. justify-content: space-around;
  326. padding: 14rpx;
  327. background: #1F1303;
  328. box-sizing: border-box;
  329. .icon-item {
  330. display: flex;
  331. align-items: center;
  332. font-family: Source Han Sans CN;
  333. font-weight: 400;
  334. font-size: 24rpx;
  335. color: #FFF6ED;
  336. }
  337. }
  338. </style>