TaskAdd.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="width"
  5. :visible="visible"
  6. switchFullscreen
  7. @ok="handleOk"
  8. :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
  9. @cancel="handleCancel"
  10. cancelText="关闭">
  11. <a-spin :spinning="confirmLoading">
  12. <j-form-container :disabled="disableSubmit">
  13. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  14. <a-row>
  15. <a-col :span="24">
  16. <a-form-model-item label="任务名称" prop="taskName" v-bind="labelCol1">
  17. <a-input v-model="model.taskName" placeholder="请输入任务名称" ></a-input>
  18. </a-form-model-item>
  19. </a-col>
  20. <a-col :span="12">
  21. <a-form-model-item label="开始时间" prop="taskStartTime" v-bind="labelCol2">
  22. <j-date placeholder="请选择任务开始时间" v-model="model.taskStartTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :span="12">
  26. <a-form-model-item label="结束时间" prop="taskEndTime" v-bind="labelCol2">
  27. <j-date placeholder="请选择任务结束时间" v-model="model.taskEndTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :span="24">
  31. <a-form-model-item label="描述" prop="description" v-bind="labelCol1">
  32. <j-editor v-model="model.description"/>
  33. </a-form-model-item>
  34. </a-col>
  35. </a-row>
  36. </a-form-model>
  37. </j-form-container>
  38. </a-spin>
  39. </j-modal>
  40. </template>
  41. <script>
  42. import { httpAction } from '@api/manage'
  43. export default {
  44. name: 'TaskAdd',
  45. data () {
  46. return {
  47. description: '添加页面',
  48. title: '',
  49. width: 960,
  50. visible: false,
  51. disableSubmit: false,
  52. model:{
  53. },
  54. // 1列
  55. labelCol1 : {
  56. labelCol: {
  57. xs: { span: 24 },
  58. sm: { span: 2 },
  59. },
  60. wrapperCol: {
  61. xs: { span: 24 },
  62. sm: { span: 21 },
  63. }
  64. },
  65. // 2列
  66. labelCol2 : {
  67. labelCol: {
  68. xs: { span: 24 },
  69. sm: { span: 4 },
  70. },
  71. wrapperCol: {
  72. xs: { span: 24 },
  73. sm: { span: 18 },
  74. }
  75. },
  76. confirmLoading: false,
  77. validatorRules: {
  78. taskName: [
  79. { required: true, message: '请输入任务名称!'},
  80. ],
  81. taskStartTime: [
  82. { required: true, message: '请输入任务开始时间!'},
  83. ],
  84. taskEndTime: [
  85. { required: true, message: '请输入任务结束时间!'},
  86. ],
  87. fileUrl: [
  88. { required: true, message: '请输入文件路径!'},
  89. ],
  90. },
  91. url: {
  92. add: "/smsCheck/task/add",
  93. edit: "/smsCheck/task/edit",
  94. queryById: "/smsCheck/task/queryById"
  95. }
  96. }
  97. },
  98. created () {
  99. // 备份model原始值
  100. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  101. },
  102. methods: {
  103. handleOk () {
  104. this.submitForm();
  105. },
  106. handleCancel () {
  107. this.visible = false;
  108. },
  109. add () {
  110. this.edit(this.modelDefault);
  111. },
  112. edit (record) {
  113. this.model = Object.assign({}, record);
  114. this.visible = true;
  115. },
  116. submitForm () {
  117. const that = this;
  118. // 触发表单验证
  119. this.$refs.form.validate(valid => {
  120. // 验证通过
  121. if (valid) {
  122. that.confirmLoading = true;
  123. let httpUrl = '';
  124. let method = '';
  125. if (!this.model.id) {
  126. httpUrl += this.url.add;
  127. method = 'post';
  128. } else {
  129. httpUrl += this.url.edit;
  130. method = 'put';
  131. }
  132. // 发送请求
  133. httpAction(httpUrl, this.model, method)
  134. .then((res) => {
  135. if(res.success){
  136. that.$message.success(res.message);
  137. that.$emit('ok');
  138. that.visible = false;
  139. }else{
  140. that.$message.warning(res.message);
  141. }
  142. }).finally(() => {
  143. that.confirmLoading = false;
  144. })
  145. }
  146. })
  147. },
  148. }
  149. }
  150. </script>
  151. <style scoped>
  152. </style>