shoppingMall.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="" style="background-color: #171520; height: 100vh">
  3. <div class="py-3 px-2 flex flex-wrap justify-between">
  4. <div
  5. style="width: 175px"
  6. v-for="goods in list"
  7. :key="goods.id"
  8. @click="handleSubmit(goods)"
  9. class="mx-1 bg-white rounded-lg shadow-md mb-2"
  10. >
  11. <img :src="goods.icon" class="rounded-t-lg w-full" style="height: 200px" />
  12. <div class="fontPFSCS p-2">{{ goods.name }}</div>
  13. <div class="text-right pr-2 mb-1">
  14. <span style="font-size: 12px">积分:</span>
  15. <span class="fontPFSCS text-red-500">{{ goods.integral }}</span>
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import { goodsList, submitGoods } from '@/api/shoppingMall'
  23. export default {
  24. data() {
  25. return {
  26. list: [],
  27. }
  28. },
  29. methods: {
  30. handleSubmit(goods) {
  31. wx.showModal({
  32. title: '提示',
  33. content: '确认兑换商品?',
  34. success: res => {
  35. if (res.confirm) {
  36. console.log('用户点击确定')
  37. submitGoods({ id: goods.id }).then(res => {
  38. console.log(res)
  39. if (res.errno === 0) {
  40. wx.showToast({
  41. title: '兑换成功',
  42. icon: 'success',
  43. duration: 2000,
  44. })
  45. } else {
  46. // wx.showToast({
  47. // title: res.msg,
  48. // icon: 'none',
  49. // duration: 2000,
  50. // })
  51. }
  52. })
  53. } else if (res.cancel) {
  54. console.log('用户点击取消')
  55. }
  56. },
  57. })
  58. },
  59. },
  60. created() {
  61. goodsList({ page: 1, limit: 1000 }).then(res => {
  62. this.list = res.data.list
  63. })
  64. },
  65. }
  66. </script>