giftInfo.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <!-- <u-form-item label="赠品" label-position="top"></u-form-item> -->
  5. <u-form-item :label="item.name" v-for="(item, index1) in giftList" :key="index1">
  6. <u-radio-group v-model="item.value" v-if="item.type == 1">
  7. <u-radio v-for="(site, index2) in item.itemList" :key="index2" :name="site.id">
  8. {{site.name}}
  9. </u-radio>
  10. </u-radio-group>
  11. <u-checkbox-group v-model="item.value" v-else>
  12. <u-checkbox v-model="site.checked" v-for="(site, index2) in item.itemList" :key="index2" :name="site.id">
  13. {{site.name}}
  14. </u-checkbox>
  15. </u-checkbox-group>
  16. </u-form-item>
  17. </u-form>
  18. <view class="handle-fix-box">
  19. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm">提交</u-button>
  20. </view>
  21. <u-top-tips ref="uTips"></u-top-tips>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. mapGetters
  27. } from 'vuex'
  28. const NET = require('@/utils/request')
  29. const API = require('@/config/api')
  30. export default {
  31. computed: {
  32. ...mapGetters([
  33. 'customStyle',
  34. ])
  35. },
  36. data() {
  37. return {
  38. form: {},
  39. giftList: [],
  40. }
  41. },
  42. onLoad() {
  43. this.getGiftInfo()
  44. },
  45. methods: {
  46. getGiftInfo() {
  47. NET.request(API.getGiftList, {}, 'POST').then(res => {
  48. res.data.forEach(item => {
  49. if (item == 1) {
  50. item.value = ''
  51. } else {
  52. item.itemList.forEach(site => {
  53. site.checked = false
  54. })
  55. }
  56. })
  57. this.giftList = res.data
  58. }).catch(error => {
  59. this.$refs.uTips.show({
  60. title: error.message,
  61. type: 'warning',
  62. })
  63. })
  64. },
  65. submitForm() {
  66. let giftId = []
  67. this.giftList.forEach(item => {
  68. if (item.type == 1 && item.value) {
  69. giftId.push(item.value)
  70. } else if (item.type == 0) {
  71. giftId = giftId.concat(item.itemList.filter(site => site.checked).map(site => {
  72. return site.id
  73. }))
  74. }
  75. })
  76. console.log(giftId);
  77. // 调接口
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. page {
  84. width: 100%;
  85. height: 100%;
  86. position: relative;
  87. }
  88. </style>
  89. <style lang="scss" scoped>
  90. @import "@/static/css/themes.scss";
  91. .content {
  92. width: 100%;
  93. float: left;
  94. padding: 0 15px 60px 15px;
  95. box-sizing: border-box;
  96. }
  97. </style>