createCirclce.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="content">
  3. <uni-forms :modelValue="formData">
  4. <view class="content1">
  5. <uni-forms-item label="圈子名称" name="name">
  6. <uni-easyinput type="text" v-model="formData.circleName" placeholder="输入圈子名称" />
  7. </uni-forms-item>
  8. </view>
  9. <view class="content2">
  10. <view class="title">
  11. 圈子标签
  12. </view>
  13. <view class="">
  14. <uni-forms-item :label="'标签'+(index+1)" name="labelName" v-for="(item,index) in labelList"
  15. :key="index">
  16. <view class="flex">
  17. <uni-easyinput type="text" v-model="item.labelName" placeholder="输入圈子标签,2-4个字" />
  18. <uni-icons type="plus-filled" @click="add(item)" size="40"></uni-icons>
  19. <uni-icons type="minus-filled" @click="subtract(index)" size="40"></uni-icons>
  20. </view>
  21. </uni-forms-item>
  22. </view>
  23. </view>
  24. </uni-forms>
  25. <view class="">
  26. <button type="primary" @click="submit">提交</button>
  27. </view>
  28. <u-toast ref="uToast"></u-toast>
  29. </view>
  30. </template>
  31. <script>
  32. var that;
  33. export default {
  34. data() {
  35. return {
  36. labelList: [{
  37. labelName: ''
  38. },
  39. {
  40. labelName: ''
  41. }
  42. ],
  43. formData: {
  44. circleName: '',
  45. circleLabel: [],
  46. commonId: ''
  47. }
  48. };
  49. },
  50. onLoad() {
  51. that = this
  52. this.userInfo = uni.getStorageSync("userInfo")
  53. this.formData.commonId = this.userInfo.id
  54. },
  55. methods: {
  56. submit() {
  57. this.formData.circleLabel = []
  58. if (!this.formData.circleName) {
  59. this.$refs.uToast.show({
  60. type: 'error',
  61. message: '圈子名称不能为空!',
  62. })
  63. return
  64. }
  65. for (let i = 0; i < this.labelList.length; i++) {
  66. if (!this.labelList[i].labelName) {
  67. this.$refs.uToast.show({
  68. type: 'error',
  69. message: '标签内容不能为空!',
  70. })
  71. return
  72. }
  73. if (this.labelList[i].labelName.length > 4 || this.labelList[i].labelName.length < 2) {
  74. this.$refs.uToast.show({
  75. type: 'error',
  76. message: '标签内容2-4个字!',
  77. })
  78. return
  79. }
  80. this.formData.circleLabel.push(this.labelList[i].labelName)
  81. }
  82. this.formData.circleLabel = this.formData.circleLabel.toString()
  83. this.$request.baseRequest('admin.unimall.circleManagementInfo', 'add', {
  84. circleManagementInfo: JSON.stringify(this.formData)
  85. }, failres => {
  86. this.$refs.uToast.show({
  87. type: 'error',
  88. message: failres.errmsg,
  89. })
  90. uni.hideLoading()
  91. }).then(res => {
  92. this.$refs.uToast.show({
  93. type: 'success',
  94. message: '提交成功!',
  95. })
  96. setTimeout(() => {
  97. uni.navigateBack()
  98. }, 500)
  99. })
  100. },
  101. add() {
  102. if (this.labelList.length > 3) {
  103. this.$refs.uToast.show({
  104. type: 'error',
  105. message: '“标签数量2-4个!',
  106. })
  107. return
  108. }
  109. this.labelList.push({
  110. labelName: ''
  111. })
  112. },
  113. subtract(index) {
  114. if (this.labelList.length < 3) {
  115. this.$refs.uToast.show({
  116. type: 'error',
  117. message: '“标签数量2-4个!',
  118. })
  119. return
  120. }
  121. this.labelList.splice(index, 1)
  122. },
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. </style>