BookItem.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view class="book-item" :class="{ disabled: book.status != 1 }">
  3. <view class="book-info">
  4. <view class="book-image-container">
  5. <u-image
  6. width="140rpx"
  7. height="140rpx"
  8. :src="book.cover"
  9. mode="aspectFill"
  10. />
  11. <view class="no-recycle" v-if="book.status != 1">
  12. <text>已收满</text>
  13. </view>
  14. </view>
  15. <view class="book-detail">
  16. <view class="book-title">
  17. <view class="book-name">{{ book.bookName }}</view>
  18. <view class="book-price-labels">
  19. <view
  20. class="book-upsell has-upsell"
  21. v-if="book.currUpsellMoney > 0 && book.canInvite !== 1"
  22. >已涨价{{ book.currUpsellMoney }}元
  23. <image
  24. src="/static/img/activity/up3.png"
  25. mode="aspectFill"
  26. style="width: 22rpx; height: 16rpx; margin-left: 6rpx"
  27. />
  28. </view>
  29. <view
  30. class="book-upsell enable-upsell"
  31. v-if="book.canInvite === 1 && book.upsellMoney"
  32. >
  33. 可涨价{{ book.upsellMoney }}元
  34. <image
  35. src="/static/img/activity/up.png"
  36. mode="aspectFill"
  37. style="width: 16rpx; height: 16rpx; margin-left: 6rpx"
  38. />
  39. </view>
  40. </view>
  41. </view>
  42. <view class="flex flex-j-b flex-a-c mb-10">
  43. <view class="top-info">
  44. <view class="book-tags">
  45. <text class="tzs tag-text" v-if="book.suit == 1">套装书</text>
  46. <text class="kmdb tag-text" v-if="book.maxNum > 1">可卖多本</text>
  47. </view>
  48. </view>
  49. <view class="countdown-wrap" v-if="book.restTime > 0">
  50. <text>加价即将结束</text>
  51. <u-count-down
  52. :timestamp="book.restTime"
  53. format="HH:mm:ss"
  54. autoStart
  55. color="#db0702"
  56. font-size="24"
  57. separator-color="#db0702"
  58. separator-size="24"
  59. @finish="onCountdownFinish"
  60. ></u-count-down>
  61. </view>
  62. </view>
  63. <view class="flex flex-j-b" style="align-items: center">
  64. <view class="price-action">
  65. <view class="book-price"
  66. >回收价
  67. <text style="font-weight: 600; color: #db0702; margin-left: 8rpx">
  68. ¥{{ book.recycleMoney }}</text
  69. ></view
  70. >
  71. <button
  72. class="up-price-btn"
  73. @tap="handleUpsell"
  74. v-if="book.canInvite === 1"
  75. >
  76. 去加价
  77. </button>
  78. </view>
  79. <u-number-box
  80. class="number-box"
  81. bg-color="#38c148"
  82. color="#ffffff"
  83. v-model="book.num"
  84. :min="1"
  85. :max="book.maxNum || 40"
  86. @blur="onQuantityChange"
  87. @minus="addReduceNum(-1)"
  88. @plus="addReduceNum(1)"
  89. :disabled="book.status != 1"
  90. ></u-number-box>
  91. </view>
  92. </view>
  93. <view class="delete-btn" @tap="onDelete">
  94. <u-icon name="close" size="26" color="#999"></u-icon>
  95. </view>
  96. </view>
  97. <common-dialog ref="deleteDialog" title="温馨提示" @confirm="confirmDelete">
  98. <text>{{
  99. book.upsellMoney
  100. ? "此书为限时加价收图书,删除后再次添加将失去加价收资格,确定删除吗?"
  101. : "确定删除这本图书吗?"
  102. }}</text>
  103. </common-dialog>
  104. </view>
  105. </template>
  106. <script>
  107. import commonDialog from "@/components/common-dialog.vue";
  108. export default {
  109. components: {
  110. commonDialog,
  111. },
  112. props: {
  113. book: {
  114. type: Object,
  115. required: true,
  116. },
  117. },
  118. data() {
  119. return {};
  120. },
  121. computed: {
  122. recycleMoney() {
  123. return (this.book.recyclePrice * (this.book.num || 1)).toFixed(2);
  124. },
  125. },
  126. methods: {
  127. onDelete() {
  128. this.$emit("delete", this.book);
  129. // this.$refs.deleteDialog.openPopup();
  130. },
  131. confirmDelete() {
  132. this.$emit("delete", this.book);
  133. },
  134. // /api/token/order/addReduceNum
  135. addReduceNum(changeNum) {
  136. uni.$u.http
  137. .post("/token/order/addReduceNum", {
  138. orderId: this.book.orderId,
  139. isbn: this.book.isbn,
  140. changeNum,
  141. })
  142. .then((res) => {
  143. if (res.code == 200) {
  144. if (res.data == 1) {
  145. this.$emit("quantity-change", this.book);
  146. let { upsellMoney, upsellNum, maxUpsellNum, num } = this.book;
  147. let bool = upsellMoney && maxUpsellNum >= num && changeNum == 1 && maxUpsellNum > upsellNum
  148. if (bool) {
  149. this.handleUpsell();
  150. }
  151. }
  152. } else {
  153. uni.$u.toast(res.msg);
  154. }
  155. });
  156. },
  157. onQuantityChange(data) {
  158. uni.$u.http
  159. .post("/token/order/changeNum", {
  160. orderId: this.book.orderId,
  161. isbn: this.book.isbn,
  162. afterNum: data.value,
  163. })
  164. .then((res) => {
  165. if (res.data == 1) {
  166. this.$emit("quantity-change", this.book);
  167. }
  168. });
  169. },
  170. handleUpsell() {
  171. this.$emit("upsell", this.book);
  172. },
  173. onCountdownFinish() {
  174. this.$emit("countdown-finish", this.book);
  175. },
  176. },
  177. };
  178. </script>
  179. <style lang="scss" scoped>
  180. .book-item {
  181. background: #ffffff;
  182. padding: 20rpx;
  183. margin-top: 20rpx;
  184. border-radius: 10rpx;
  185. &.disabled {
  186. background: #f9ccc9;
  187. }
  188. ::v-deep .u-countdown-colon {
  189. font-size: 24rpx !important;
  190. }
  191. .book-info {
  192. display: flex;
  193. align-items: center;
  194. position: relative;
  195. .book-image-container {
  196. position: relative;
  197. .no-recycle {
  198. position: absolute;
  199. bottom: 0;
  200. left: 50%;
  201. transform: translateX(-50%);
  202. background-color: #ff5252;
  203. color: #ffffff;
  204. padding: 4rpx 10rpx;
  205. border-radius: 4rpx 4rpx 0 0;
  206. font-size: 24rpx;
  207. text-align: center;
  208. width: 100%;
  209. }
  210. }
  211. .book-cover {
  212. width: 140rpx;
  213. height: 196rpx;
  214. border-radius: 8rpx;
  215. }
  216. .tag-text {
  217. font-family: Source Han Sans CN;
  218. font-weight: 400;
  219. font-size: 24rpx;
  220. color: #ffffff;
  221. }
  222. .tzs {
  223. width: 91rpx;
  224. height: 30rpx;
  225. background: linear-gradient(263deg, #98e05f, #0de3ac);
  226. border-radius: 2rpx;
  227. padding: 4rpx 10rpx;
  228. margin-right: 10rpx;
  229. }
  230. .kmdb {
  231. width: 117rpx;
  232. height: 30rpx;
  233. background: linear-gradient(263deg, #f7cb6b, #fba980);
  234. border-radius: 2rpx;
  235. padding: 4rpx 10rpx;
  236. margin-right: 10rpx;
  237. }
  238. .book-detail {
  239. flex: 1;
  240. margin-left: 20rpx;
  241. display: flex;
  242. flex-direction: column;
  243. justify-content: space-between;
  244. :v-deep .u-number-input {
  245. background: #f9f9f9 !important;
  246. border-radius: 6rpx;
  247. }
  248. .book-title {
  249. width: calc(100% - 60rpx);
  250. margin-bottom: 10rpx;
  251. display: flex;
  252. align-items: center;
  253. }
  254. .book-name {
  255. font-size: 28rpx;
  256. color: #333;
  257. line-height: 1.4;
  258. display: -webkit-box;
  259. -webkit-box-orient: vertical;
  260. -webkit-line-clamp: 2;
  261. overflow: hidden;
  262. font-family: Source Han Sans CN;
  263. font-weight: bold;
  264. word-break: break-all;
  265. margin-right: 10rpx;
  266. }
  267. .book-price-labels {
  268. display: flex;
  269. margin-top: -2rpx;
  270. flex-shrink: 0;
  271. }
  272. .book-price {
  273. font-family: Source Han Sans CN;
  274. font-weight: 400;
  275. font-size: 24rpx;
  276. color: #999999;
  277. }
  278. .price-action {
  279. display: flex;
  280. align-items: center;
  281. .up-price-btn {
  282. background-color: #38c148;
  283. color: #ffffff;
  284. font-size: 24rpx;
  285. height: 48rpx;
  286. line-height: 48rpx;
  287. padding: 0 10rpx;
  288. border-radius: 24rpx;
  289. margin-left: 10rpx;
  290. }
  291. }
  292. }
  293. .countdown-wrap {
  294. display: flex;
  295. align-items: center;
  296. font-size: 24rpx !important;
  297. color: #db0702;
  298. margin-left: 6rpx;
  299. text {
  300. margin-right: 6rpx;
  301. }
  302. }
  303. .book-upsell {
  304. font-size: 22rpx;
  305. padding: 2rpx 10rpx;
  306. border-radius: 4rpx;
  307. margin-right: 10rpx;
  308. display: inline-flex;
  309. align-items: center;
  310. &.has-upsell {
  311. color: #276f1e;
  312. background-color: #a8dda2;
  313. }
  314. &.enable-upsell {
  315. color: #ff0e11;
  316. background-color: #ffe9eb;
  317. }
  318. .u-image {
  319. margin-left: 4rpx;
  320. }
  321. }
  322. .delete-btn {
  323. position: absolute;
  324. right: 0;
  325. top: -10rpx;
  326. padding: 10rpx;
  327. }
  328. }
  329. }
  330. </style>