Edit.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div>
  3. <a-form :form="form" @submit="handleSubmit">
  4. <a-form-item
  5. :labelCol="labelCol"
  6. :wrapperCol="wrapperCol"
  7. label="规则编号"
  8. hasFeedback
  9. validateStatus="success"
  10. >
  11. <a-input
  12. placeholder="规则编号"
  13. v-decorator="[
  14. 'no',
  15. {rules: [{ required: true, message: '请输入规则编号' }]}
  16. ]"
  17. :disabled="true"
  18. ></a-input>
  19. </a-form-item>
  20. <a-form-item
  21. :labelCol="labelCol"
  22. :wrapperCol="wrapperCol"
  23. label="服务调用次数"
  24. hasFeedback
  25. validateStatus="success"
  26. >
  27. <a-input-number :min="1" style="width: 100%" v-decorator="['callNo', {rules: [{ required: true }]}]" />
  28. </a-form-item>
  29. <a-form-item
  30. :labelCol="labelCol"
  31. :wrapperCol="wrapperCol"
  32. label="状态"
  33. hasFeedback
  34. validateStatus="warning"
  35. >
  36. <a-select v-decorator="['status', {rules: [{ required: true, message: '请选择状态' }], initialValue: '1'}]">
  37. <a-select-option value="1">Option 1</a-select-option>
  38. <a-select-option value="2">Option 2</a-select-option>
  39. <a-select-option value="3">Option 3</a-select-option>
  40. </a-select>
  41. </a-form-item>
  42. <a-form-item
  43. :labelCol="labelCol"
  44. :wrapperCol="wrapperCol"
  45. label="描述"
  46. hasFeedback
  47. help="请填写一段描述"
  48. >
  49. <a-textarea :rows="5" placeholder="..." v-decorator="['description', {rules: [{ required: true }]}]" />
  50. </a-form-item>
  51. <a-form-item
  52. :labelCol="labelCol"
  53. :wrapperCol="wrapperCol"
  54. label="更新时间"
  55. hasFeedback
  56. validateStatus="error"
  57. >
  58. <a-date-picker
  59. style="width: 100%"
  60. showTime
  61. format="YYYY-MM-DD HH:mm:ss"
  62. placeholder="Select Time"
  63. />
  64. </a-form-item>
  65. <a-form-item
  66. v-bind="buttonCol"
  67. >
  68. <a-row>
  69. <a-col span="6">
  70. <a-button type="primary" html-type="submit">提交</a-button>
  71. </a-col>
  72. <a-col span="10">
  73. <a-button @click="handleGoBack">返回</a-button>
  74. </a-col>
  75. <a-col span="8"></a-col>
  76. </a-row>
  77. </a-form-item>
  78. </a-form>
  79. </div>
  80. </template>
  81. <script>
  82. export default {
  83. name: 'TableEdit',
  84. props: {
  85. record: {
  86. type: [Object, String],
  87. default: ''
  88. }
  89. },
  90. data () {
  91. return {
  92. labelCol: {
  93. xs: { span: 24 },
  94. sm: { span: 5 }
  95. },
  96. wrapperCol: {
  97. xs: { span: 24 },
  98. sm: { span: 12 }
  99. },
  100. buttonCol: {
  101. wrapperCol: {
  102. xs: { span: 24 },
  103. sm: { span: 12, offset: 5 }
  104. }
  105. },
  106. form: this.$form.createForm(this),
  107. id: 0
  108. }
  109. },
  110. // beforeCreate () {
  111. // this.form = this.$form.createForm(this)
  112. // },
  113. mounted () {
  114. this.$nextTick(() => {
  115. this.loadEditInfo(this.record)
  116. })
  117. },
  118. methods: {
  119. handleGoBack () {
  120. this.$emit('onGoBack')
  121. },
  122. handleSubmit () {
  123. const { form: { validateFields } } = this
  124. validateFields((err, values) => {
  125. if (!err) {
  126. // eslint-disable-next-line no-console
  127. console.log('Received values of form: ', values)
  128. }
  129. })
  130. },
  131. handleGetInfo () {
  132. },
  133. loadEditInfo (data) {
  134. const { form } = this
  135. // ajax
  136. console.log(`将加载 ${this.id} 信息到表单`)
  137. new Promise((resolve) => {
  138. setTimeout(resolve, 1500)
  139. }).then(() => {
  140. form.setFieldsValue(data)
  141. // form.setFieldsValue({ no: '1', callNo: '999' })
  142. })
  143. }
  144. }
  145. }
  146. </script>