index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="gift">
  3. <div class="top">
  4. <div class="card">
  5. <div class="my_nums">我的积分:<span class="num">{{useInfo.jifen}}</span></div>
  6. <image src="@/static/images/gift/gift.png" mode="" class="icon_6"></image>
  7. </div>
  8. </div>
  9. <div class="list">
  10. <div class="card" v-for="(item,index) in list" :key="item.id">
  11. <div class="tips" v-if="item.day_duihuan_nums">今日已兑换 <text
  12. class="tip_num">{{item.day_duihuan_nums}}</text> </div>
  13. <image :src="item.cover" mode="" class="c_image"></image>
  14. <div class="right">
  15. <div class="name">{{item.name}}</div>
  16. <div class="jf_btn">
  17. <div class="fen"><span>{{item.jifen}}</span><span style="font-size: 12px;">积分</span></div>
  18. <!-- <u-number-box v-if="item.buy_num" v-model="item.buy_num" @change="valChange" bg-color="#FFF4F1"
  19. color="#F5222D"></u-number-box> -->
  20. <div class="num_input" v-if="item.buy_num">
  21. <div class="jian" @click="jianNumber(index)">-</div>
  22. <u-input type="number" v-model="item.buy_num" :clearable="false" :custom-style="inputCustom"
  23. @change="changeNumber"></u-input>
  24. <div class="jia" @click="jiaNumber(index,item)">+</div>
  25. </div>
  26. <div v-if="!item.buy_num">
  27. <div class="button" v-if="item.nums>0" @click="doExchange(item.id)">立即兑换
  28. </div>
  29. <div v-else class="button gray">已兑完 </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="bottom">
  36. <div class="bottom-btn" @click="onSubmit">立即下单({{totalFen}}积分)</div>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. page: 1,
  45. last: false,
  46. list: [],
  47. useInfo: {},
  48. totalFen: 0,
  49. inputCustom: {
  50. 'width': '38px',
  51. 'height': '24px',
  52. 'line-height': '24px',
  53. 'border': 'solid 1px #F5222D',
  54. 'min-height': '25px',
  55. 'text-align': 'center',
  56. 'background-color': '#FFF4F1',
  57. 'font-size': '18px',
  58. 'color': '#F5222D'
  59. }
  60. }
  61. },
  62. onShow() {
  63. localStorage.removeItem('ExchangeList')
  64. this.totalFen = 0
  65. this.useInfo = this.vuex_user
  66. this.page = 1
  67. this.last = false
  68. this.list = []
  69. this.getList()
  70. },
  71. onReachBottom() {
  72. if (!this.last) {
  73. this.page++
  74. }
  75. this.getList()
  76. },
  77. methods: {
  78. onSubmit() {
  79. if (this.totalFen == 0) {
  80. this.$u.toast('请选择需要兑换的商品!')
  81. return
  82. }
  83. if (this.totalFen > this.useInfo.jifen) {
  84. this.$u.toast('您的积分不足!')
  85. return
  86. }
  87. localStorage.setItem('ExchangeList', JSON.stringify(this.list))
  88. uni.reLaunch({
  89. url: '/pages/gift/detail'
  90. })
  91. },
  92. getList() {
  93. this.$u.get('/dwbs/shop/goods', {
  94. page: this.page,
  95. }).then(res => {
  96. console.log(res, 'list')
  97. let data = res.data.data
  98. if (this.page > 1 && data.length == 0) {
  99. uni.showToast({
  100. title: '暂无更多',
  101. icon: 'none'
  102. })
  103. this.last = true
  104. } else {
  105. this.list = this.list.concat(data)
  106. }
  107. })
  108. },
  109. doExchange(id) {
  110. console
  111. this.list.map((item, index) => {
  112. if (item.id == id) {
  113. let buy_num = item.buy_num ? item.buy_num++ : 1
  114. console.log(buy_num)
  115. this.totalFen = this.totalFen + (buy_num * item.jifen)
  116. this.$set(this.list[index], 'buy_num', buy_num);
  117. }
  118. })
  119. console.log(this.list)
  120. },
  121. jianNumber(index) {
  122. this.list[index].buy_num--
  123. this.valChange(this.list)
  124. },
  125. jiaNumber(index, item) {
  126. if (item.buy_num == item.nums) {
  127. uni.showToast({
  128. title: '商品库存不足!',
  129. icon: 'none'
  130. })
  131. return
  132. }
  133. this.list[index].buy_num++
  134. console.log(this.list)
  135. this.valChange(this.list)
  136. },
  137. changeNumber() {
  138. this.valChange(this.list)
  139. },
  140. //商品数量加减
  141. valChange(arr) {
  142. let num = 0
  143. arr.map(item => {
  144. if (item.buy_num) {
  145. num = num + (item.buy_num * item.jifen)
  146. }
  147. })
  148. this.list = arr
  149. this.totalFen = num
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. page {
  156. background-color: #f5f5f5;
  157. }
  158. .gift {
  159. padding-bottom: 100px;
  160. }
  161. .top {
  162. background-color: #fff;
  163. padding: 16px 12px;
  164. .card {
  165. padding: 24px 15px;
  166. display: flex;
  167. align-items: center;
  168. background: linear-gradient(270deg, #FF571B 0%, #F5222D 100%);
  169. border-radius: 10px;
  170. position: relative;
  171. .my_nums {
  172. font-weight: 400;
  173. font-size: 20px;
  174. color: #fff;
  175. flex: 1;
  176. text-align: left;
  177. margin-left: 20px;
  178. .num {
  179. font-size: 22px;
  180. }
  181. }
  182. .icon_6 {
  183. position: absolute;
  184. right: 15px;
  185. bottom: 0;
  186. width: 55px;
  187. height: 56px;
  188. }
  189. }
  190. }
  191. .list {
  192. .card {
  193. margin-top: 14px;
  194. background-color: #fff;
  195. display: flex;
  196. padding: 8px 16px;
  197. border-radius: 5px;
  198. position: relative;
  199. .tips {
  200. position: absolute;
  201. top: 0;
  202. right: 0;
  203. display: flex;
  204. align-items: center;
  205. border-radius: 0px 5px 0px 5px;
  206. opacity: 1;
  207. background: #FAC858;
  208. font-size: 12px;
  209. padding: 0px 10px;
  210. color: #F5222D;
  211. .tip_num {
  212. font-size: 20px;
  213. display: inline-block;
  214. margin-left: 4px;
  215. }
  216. }
  217. .c_image {
  218. width: 98px;
  219. height: 78px;
  220. margin-right: 9px;
  221. border-radius: 8px;
  222. }
  223. .right {
  224. flex: 1;
  225. }
  226. .name {
  227. font-size: 18px;
  228. }
  229. .jf_btn {
  230. margin-top: 23px;
  231. display: flex;
  232. align-items: center;
  233. .num_input {
  234. display: flex;
  235. align-items: center;
  236. .jian {
  237. height: 25px;
  238. line-height: 24px;
  239. border-left: solid 1px #F5222D;
  240. border-top: solid 1px #F5222D;
  241. border-bottom: solid 1px #F5222D;
  242. border-radius: 5px 0 0 5px;
  243. width: 26px;
  244. font-size: 18px;
  245. text-align: center;
  246. color: #F5222D;
  247. background-color: #FFF4F1;
  248. }
  249. .jia {
  250. border-right: solid 1px #F5222D;
  251. border-top: solid 1px #F5222D;
  252. border-bottom: solid 1px #F5222D;
  253. height: 25px;
  254. line-height: 24px;
  255. font-size: 18px;
  256. width: 26px;
  257. text-align: center;
  258. background-color: #FFF4F1;
  259. color: #F5222D;
  260. border-radius: 0px 5px 5px 0px;
  261. }
  262. }
  263. .fen {
  264. font-size: 18px;
  265. color: #F5222D;
  266. flex: 1;
  267. }
  268. .button {
  269. width: 87px;
  270. height: 28px;
  271. line-height: 28px;
  272. border-radius: 20px;
  273. font-size: 12px;
  274. background: linear-gradient(90deg, #FB7B58 0%, #F5222D 97%);
  275. color: #FFFFFF;
  276. text-align: center;
  277. }
  278. .gray {
  279. background: #D8D8D8;
  280. color: #ADADAD;
  281. }
  282. }
  283. }
  284. }
  285. .bottom {
  286. position: fixed;
  287. width: 100%;
  288. left: 0;
  289. bottom: 0;
  290. padding: 15px 0;
  291. background-color: #ffffff;
  292. display: flex;
  293. .bottom-btn {
  294. border-radius: 30px;
  295. height: 44px;
  296. margin: 0 12px;
  297. flex: 1;
  298. text-align: center;
  299. color: #ffffff;
  300. font-size: 16px;
  301. line-height: 44px;
  302. background: linear-gradient(90deg, #FB7B58 0%, #F5222D 97%);
  303. }
  304. }
  305. </style>