index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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" />
  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.recycleMoney * (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. if (this.totalPrice < 30) {
  134. uni.showToast({
  135. title: '预估价格需满30元才能回收',
  136. icon: 'none'
  137. })
  138. return
  139. }
  140. let orderId = this.bookList[0].orderId
  141. //预提交
  142. uni.$u.http.get('/token/order/preSubmit?orderId=' + orderId).then(res => {
  143. if (res.code == 200) {
  144. if (res.data.code == 1 || res.data.code == 2) {
  145. uni.navigateTo({
  146. url: "/pages-home/pages/book-order"
  147. })
  148. uni.setStorageSync('orderId', orderId)
  149. } else {
  150. uni.showToast({
  151. icon: 'none',
  152. title: res.msg
  153. })
  154. }
  155. }
  156. })
  157. },
  158. updateBooksList(data) {
  159. this.bookList = data
  160. },
  161. toggleCollapse(step) {
  162. this.$set(this.collapseState, step, !this.collapseState[step])
  163. },
  164. handleScan() {
  165. uni.scanCode({
  166. scanType: ['barCode'],
  167. success: (res) => {
  168. this.checkBookISBN(res.result)
  169. },
  170. fail: () => {
  171. uni.showToast({
  172. title: '扫码失败',
  173. icon: 'none'
  174. })
  175. }
  176. })
  177. },
  178. checkBookISBN(isbn) {
  179. uni.$u.http.get('/token/order/scanIsbn?isbn=' + isbn).then(res => {
  180. if (res.code == 200) {
  181. let code = res.data.code
  182. if (code == 1) {
  183. res.data.num = 1
  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 = ['tiredDialog', '', '', 'noInfoDialog', "notAcceptDialog", 'maxAcceptDialog',
  200. 'orderMaxNumDialog'
  201. ]
  202. let key = tempKeys[code]
  203. if (key) {
  204. this.$refs[key].openPopup()
  205. }
  206. },
  207. //获取当前用户未提交订单 /api/token/order/lastOrder
  208. getLastOrder() {
  209. uni.$u.http.get('/token/order/lastOrder').then(res => {
  210. if (res.code == 200) {
  211. this.bookList = res.data ? res.data.orderDetailList.map(v => {
  212. v.orderId = res.data.orderId
  213. return v
  214. }) : []
  215. }
  216. })
  217. },
  218. goToScannedBooks() {
  219. uni.navigateTo({
  220. url: '/pages-home/pages/scaned-book'
  221. })
  222. },
  223. goToRules() {
  224. uni.navigateTo({
  225. url: '/pages/rules/index'
  226. })
  227. },
  228. showServiceGuarantee() {
  229. this.$refs.serviceGuarantee.openPopup()
  230. },
  231. goToInputISBN() {
  232. this.$refs.isbnPopup.openPopup()
  233. }
  234. },
  235. mounted() {
  236. setTimeout(() => {
  237. this.getLastOrder()
  238. }, 300)
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .container {
  244. height: 100%;
  245. position: relative;
  246. overflow: auto;
  247. z-index: 1;
  248. /* #ifdef MP-WEIXIN */
  249. min-height: 100vh;
  250. /* #endif */
  251. /* #ifndef MP-WEIXIN */
  252. min-height: calc(100vh - 120rpx);
  253. /* #endif */
  254. &.book-list {
  255. padding-bottom: 300rpx;
  256. }
  257. padding-bottom: 130rpx;
  258. .nav-title {
  259. font-family: PingFang SC;
  260. font-weight: bold;
  261. font-size: 34rpx;
  262. color: #FFFFFF;
  263. padding-left: 40rpx;
  264. }
  265. }
  266. .common-text {
  267. font-family: PingFang SC;
  268. font-weight: 500;
  269. font-size: 28rpx;
  270. color: #999999;
  271. &.tip {
  272. color: #FF8A4B;
  273. }
  274. }
  275. .color-red {
  276. color: #ff0000;
  277. margin: 0 10rpx;
  278. }
  279. .bottom-fixed {
  280. position: fixed;
  281. left: 0;
  282. right: 0;
  283. bottom: 0;
  284. z-index: 9;
  285. background-color: #ffffff;
  286. /* #ifdef H5 */
  287. padding-bottom: 120rpx;
  288. /* #endif */
  289. .btn-wrap {
  290. display: flex;
  291. gap: 20rpx;
  292. padding: 20rpx;
  293. padding-bottom: 0;
  294. button {
  295. flex: 1;
  296. height: 88rpx;
  297. border-radius: 10rpx;
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. gap: 10rpx;
  302. border: none;
  303. text {
  304. font-size: 32rpx;
  305. }
  306. &::after {
  307. border: none;
  308. }
  309. }
  310. .isbn-btn {
  311. background-color: #FFFFFF;
  312. color: #4CD964;
  313. border: 3rpx solid #4CD964;
  314. }
  315. }
  316. .scan-btn {
  317. background-color: #4CD964;
  318. color: #FFFFFF;
  319. }
  320. .next-btn {
  321. margin: 0;
  322. width: 208rpx;
  323. }
  324. }
  325. .service-icons {
  326. display: flex;
  327. justify-content: space-around;
  328. padding: 14rpx;
  329. background: #1F1303;
  330. box-sizing: border-box;
  331. .icon-item {
  332. display: flex;
  333. align-items: center;
  334. font-family: Source Han Sans CN;
  335. font-weight: 400;
  336. font-size: 24rpx;
  337. color: #FFF6ED;
  338. }
  339. }
  340. </style>