MobileForm.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model
  5. ref="form"
  6. :model="model"
  7. :rules="validatorRules"
  8. slot="detail"
  9. >
  10. <a-row>
  11. <a-col :span="24">
  12. <a-form-model-item
  13. label="每人发放张数"
  14. :labelCol="labelCol"
  15. :wrapperCol="wrapperCol"
  16. prop="num"
  17. >
  18. <a-input-number
  19. v-model="model.num"
  20. placeholder="请输入每人发放张数"
  21. style="width: 50%"
  22. />
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :span="24" v-for="(item, index) in model.mobiles" :key="index">
  26. <a-form-model-item
  27. :label="'手机号' + (index + 1)"
  28. :labelCol="labelCol"
  29. :wrapperCol="wrapperCol"
  30. :prop="`mobiles[${index}]`"
  31. :rules="[
  32. {
  33. required: true,
  34. message: '请输入手机号!',
  35. trigger: 'change',
  36. },
  37. ]"
  38. >
  39. <a-input
  40. v-model="item.value"
  41. placeholder="请输入手机号"
  42. style="width: 50%"
  43. ></a-input>
  44. <a-icon
  45. v-if="model.mobiles.length - 1 == index"
  46. type="plus-circle"
  47. class="dynamic-delete-button"
  48. @click="puls()"
  49. />
  50. <a-icon
  51. type="minus-circle"
  52. style="color: #f56c6c"
  53. class="dynamic-delete-button"
  54. v-if="model.mobiles.length > 1"
  55. @click="() => remove(index)"
  56. />
  57. </a-form-model-item>
  58. </a-col>
  59. </a-row>
  60. </a-form-model>
  61. </j-form-container>
  62. </a-spin>
  63. </template>
  64. <script>
  65. import { httpAction, getAction } from "@/api/manage";
  66. import { validateDuplicateValue } from "@/utils/util";
  67. export default {
  68. name: "MobileForm",
  69. components: {},
  70. props: {
  71. //表单禁用
  72. disabled: {
  73. type: Boolean,
  74. default: false,
  75. required: false,
  76. },
  77. couponsId: {
  78. type: String,
  79. default: "",
  80. required: true,
  81. },
  82. },
  83. data() {
  84. return {
  85. model: { num: 1, mobiles: [{ value: "" }] },
  86. labelCol: {
  87. xs: { span: 24 },
  88. sm: { span: 3 },
  89. },
  90. wrapperCol: {
  91. xs: { span: 24 },
  92. sm: { span: 16 },
  93. },
  94. confirmLoading: false,
  95. validatorRules: {
  96. num: [{ required: true, message: "请输入每人发放张数!" }],
  97. },
  98. };
  99. },
  100. computed: {
  101. formDisabled() {
  102. return this.disabled;
  103. },
  104. },
  105. created() {
  106. this.model.couponsId = this.couponsId;
  107. },
  108. methods: {
  109. puls() {
  110. this.model.mobiles.push({ value: "" });
  111. },
  112. remove(index) {
  113. this.model.mobiles.splice(index, 1);
  114. },
  115. submitForm() {
  116. const that = this;
  117. // 触发表单验证
  118. this.$refs.form.validate((valid) => {
  119. if (valid) {
  120. that.confirmLoading = true;
  121. httpAction(
  122. "/business/busMarketCouponsUsed/gainCouponsUsedToNoMember",
  123. this.model,
  124. "post"
  125. )
  126. .then((res) => {
  127. if (res.success) {
  128. that.$message.success(res.message);
  129. that.$emit("ok");
  130. } else {
  131. that.$message.warning(res.message);
  132. }
  133. })
  134. .finally(() => {
  135. that.confirmLoading = false;
  136. });
  137. }
  138. });
  139. },
  140. },
  141. };
  142. </script>
  143. <style scoped>
  144. .dynamic-delete-button {
  145. cursor: pointer;
  146. position: relative;
  147. top: 4px;
  148. margin-left: 5px;
  149. font-size: 18px;
  150. color: #1890ff;
  151. transition: all 0.3s;
  152. }
  153. .dynamic-delete-button:hover {
  154. color: #777;
  155. }
  156. .dynamic-delete-button[disabled] {
  157. cursor: not-allowed;
  158. opacity: 0.5;
  159. }
  160. </style>