addDiverModal.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div>
  3. <a-modal
  4. :footer="null"
  5. :title="titleText"
  6. v-model="isshow"
  7. @cancle="cancel"
  8. :centered="true">
  9. <a-spin :spinning="loading">
  10. <a-form-model ref="ruleForm" :model="formData" :rules="rules">
  11. <a-form-model-item label="司机姓名" prop="name" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
  12. <a-input v-model.trim="formData.name" :maxLength="30" placeholder="请输入司机姓名(最多30个字符)" id="addDiverModal-name"/>
  13. </a-form-model-item>
  14. <a-form-model-item label="手机号码" prop="phone" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
  15. <a-input v-model.trim="formData.phone" :maxLength="11" placeholder="请输入手机号" id="addDiverModal-phone"/>
  16. </a-form-model-item>
  17. <a-form-model-item label="状态" prop="loginFlag" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
  18. <a-radio-group
  19. name="radioGroup"
  20. v-model="formData.loginFlag"
  21. id="addDiverModal-loginFlag"
  22. >
  23. <a-radio :value="1">是</a-radio>
  24. <a-radio :value="0">否</a-radio>
  25. </a-radio-group>
  26. </a-form-model-item>
  27. <a-form-model-item :wrapper-col="{ span: 24, offset: 8 }">
  28. <a-button type="primary" @click="onSubmit" :style="{ marginRight: '15px' }" id="addDiverModal-onSubmit">保存</a-button>
  29. <a-button @click="cancel" :style="{ marginLeft: '15px' }" id="addDiverModal-cancel">取消</a-button>
  30. </a-form-model-item>
  31. </a-form-model>
  32. </a-spin >
  33. </a-modal>
  34. </div>
  35. </template>
  36. <script>
  37. import {
  38. STable,
  39. VSelect
  40. } from '@/components'
  41. import { saveDriver, driverDetails } from '@/api/cleanManage.js'
  42. export default {
  43. name: 'AddDiverModal',
  44. components: {
  45. STable,
  46. VSelect
  47. },
  48. props: {
  49. visible: {
  50. type: Boolean,
  51. default: false
  52. },
  53. itemId: {
  54. type: String,
  55. default: ''
  56. }
  57. },
  58. data () {
  59. return {
  60. titleText: '新增',
  61. isshow: this.visible,
  62. formLayout: 'horizontal',
  63. optionData: [],
  64. formData: {
  65. name: '', // 姓名
  66. loginFlag: '', // 状态
  67. phone: '' // 手机号码
  68. },
  69. rules: {
  70. phone: [{ required: true, pattern: /^\d{11}$/, message: '请输入手机号', trigger: 'blur' }],
  71. name: [{ required: true, message: '请输入司机姓名', trigger: 'blur' }],
  72. loginFlag: [{ required: true, message: '请选择状态', trigger: 'blur' }]
  73. },
  74. loading: false
  75. }
  76. },
  77. methods: {
  78. cancel (e) {
  79. this.clear()
  80. this.$emit('close')
  81. },
  82. // 编辑查详情
  83. getPageInfo () {
  84. this.loading = true
  85. driverDetails({
  86. id: this.itemId
  87. }).then(res => {
  88. if (res.status == 200) {
  89. this.loading = false
  90. this.formData = Object.assign({}, this.formData, res.data)
  91. this.formData.loginFlag = Number(this.formData.loginFlag)
  92. }
  93. })
  94. },
  95. // 保存提交
  96. onSubmit () {
  97. this.$refs.ruleForm.validate(valid => {
  98. const _this = this
  99. if (valid) {
  100. const params = JSON.parse(JSON.stringify(this.formData))
  101. saveDriver(params).then(res => {
  102. if (res.status == 200) {
  103. _this.$message.success(res.message)
  104. _this.$emit('refresh')
  105. setTimeout(function () {
  106. _this.cancel()
  107. }, 300)
  108. }
  109. })
  110. }
  111. })
  112. },
  113. // 取消
  114. handleCancel () {
  115. this.cancel()
  116. },
  117. clear () {
  118. this.$refs.ruleForm.resetFields()
  119. delete this.formData.id
  120. this.formData.name = ''
  121. this.formData.loginFlag = ''
  122. this.formData.phone = ''
  123. }
  124. },
  125. watch: {
  126. visible (newValue, oldValue) {
  127. this.isshow = newValue
  128. },
  129. isshow (val) {
  130. if (!val) {
  131. this.$emit('close')
  132. } else {
  133. this.$nextTick(() => {
  134. this.$refs.ruleForm.resetFields()
  135. })
  136. }
  137. },
  138. itemId (newValue, oldValue) {
  139. if (newValue && this.isshow) {
  140. this.titleText = '编辑'
  141. this.getPageInfo(newValue)
  142. } else {
  143. this.titleText = '新增'
  144. console.log(this.loading)
  145. }
  146. }
  147. }
  148. }
  149. </script>
  150. <style>
  151. </style>