addEquipmentModal.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <a-modal
  3. centered
  4. class="userEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="绑定设备"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="800">
  11. <a-form-model
  12. id="userEdit-form"
  13. ref="ruleForm"
  14. :model="form"
  15. :rules="rules"
  16. :label-col="formItemLayout.labelCol"
  17. :wrapper-col="formItemLayout.wrapperCol">
  18. <a-form-model-item label="设备编码" prop="deviceCode">
  19. <a-input v-model="form.deviceCode" placeholder="请输入设备编码" />
  20. </a-form-model-item>
  21. <a-form-model-item label="设备名称" prop="deviceName">
  22. <a-input v-model="form.deviceName" placeholder="请输入设备名称" />
  23. </a-form-model-item>
  24. <a-form-model-item label="绑定经销商" prop="dealerSn">
  25. <storeList ref="storeList" @change="custChange"></storeList>
  26. </a-form-model-item>
  27. <a-form-model-item label="是否启用" prop="enabledFlag">
  28. <a-radio-group default-value="0" button-style="solid" v-model="form.enabledFlag">
  29. <a-radio-button value="1">
  30. </a-radio-button>
  31. <a-radio-button value="0">
  32. </a-radio-button>
  33. </a-radio-group>
  34. </a-form-model-item>
  35. <a-form-model-item :label-col="{span: 0}" :wrapper-col="{span: 24}" style="text-align: center;">
  36. <a-button :style="{ marginRight: '8px' }" @click="isShow=false">取消</a-button>
  37. <a-button type="primary" @click="handleSubmit()" :style="{ marginLeft: '8px' }">确定</a-button>
  38. </a-form-model-item>
  39. </a-form-model>
  40. </a-modal>
  41. </template>
  42. <script>
  43. import { VSelect } from '@/components'
  44. import storeList from '@/views/common/storeList.vue'
  45. import { handDeviceSave, handDeviceDetail, handDeviceEdit } from '@/api/handDevice'
  46. export default {
  47. components: { VSelect, storeList },
  48. props: {
  49. openModal: { // 弹框显示状态
  50. type: Boolean,
  51. default: false
  52. },
  53. itemId: {
  54. type: String,
  55. default: ''
  56. }
  57. },
  58. data () {
  59. return {
  60. isShow: this.openModal, // 是否打开弹框
  61. formItemLayout: {
  62. labelCol: { span: 6 },
  63. wrapperCol: { span: 16 }
  64. },
  65. form: {
  66. dealerSn: undefined, // 客户SN
  67. deviceCode: '', // 设备编码
  68. deviceName: '', // 设备名称
  69. enabledFlag: '0'// 启用标记
  70. },
  71. rules: {
  72. deviceCode: [ { required: true, message: '请输入设备编码', trigger: 'blur' } ],
  73. deviceName: [ { required: true, message: '请输入设备名称', trigger: 'blur' } ],
  74. dealerSn: [ { required: true, message: '请选择绑定经销商', trigger: 'change' } ],
  75. enabledFlag: [ { required: true, message: '请选择是否启用', trigger: 'change' } ]
  76. }
  77. }
  78. },
  79. methods: {
  80. custChange (val) {
  81. this.form.dealerSn = val.key
  82. },
  83. // 保存
  84. handleSubmit () {
  85. const _this = this
  86. this.$refs.ruleForm.validate(valid => {
  87. if (valid) {
  88. const params = JSON.parse(JSON.stringify(_this.form))
  89. if (!_this.itemId) {
  90. handDeviceSave(params).then(res => {
  91. if (res.status == 200) {
  92. _this.$message.success(res.message)
  93. _this.$emit('confirm', _this.form)
  94. _this.isShow = false
  95. }
  96. })
  97. } else {
  98. params.id = _this.itemId
  99. handDeviceEdit(params).then(res => {
  100. if (res.status == 200) {
  101. _this.$message.success(res.message)
  102. _this.$emit('confirm', _this.form)
  103. _this.isShow = false
  104. }
  105. })
  106. }
  107. } else {
  108. console.log('error submit!!')
  109. return false
  110. }
  111. })
  112. },
  113. // 获取详情
  114. getDetail () {
  115. handDeviceDetail({ id: this.itemId }).then(res => {
  116. if (res.status == 200) {
  117. this.form.dealerSn = res.data.dealerSn
  118. this.form.deviceCode = res.data.deviceCode
  119. this.form.deviceName = res.data.deviceName
  120. this.form.enabledFlag = res.data.enabledFlag
  121. this.$refs.storeList.getInfo({ key: res.data.dealerSn, name: res.data.dealer.dealerName })
  122. } else {
  123. this.$refs.ruleForm.resetFields()
  124. }
  125. })
  126. },
  127. // 重置数据
  128. reset () {
  129. this.form = {
  130. dealerSn: undefined, // 客户SN
  131. deviceCode: '', // 设备编码
  132. deviceName: '', // 设备名称
  133. enabledFlag: '0'// 启用标记
  134. }
  135. this.$refs.storeList.resetForm()
  136. this.$refs.ruleForm.resetFields()
  137. },
  138. pageInit (data) {
  139. this.getDetail()
  140. }
  141. },
  142. watch: {
  143. // 父页面传过来的弹框状态
  144. openModal (newValue, oldValue) {
  145. this.isShow = newValue
  146. },
  147. // 重定义的弹框状态
  148. isShow (newValue, oldValue) {
  149. if (!newValue) {
  150. this.$emit('close')
  151. this.reset()
  152. }
  153. }
  154. }
  155. }
  156. </script>
  157. <style>
  158. </style>