TpmEquipmentForm.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  5. <a-row>
  6. <a-col :span="24">
  7. <a-form-model-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentname">
  8. <a-input v-model="model.equipmentname" placeholder="请输入设备名称" ></a-input>
  9. </a-form-model-item>
  10. </a-col>
  11. <a-col :span="24">
  12. <a-form-model-item label="设备分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmenttreeid">
  13. <!-- <j-category-select v-model="model.equipmenttreeid" pcode="id" placeholder="请选择设备分类" back="name" @change="handleCategoryChange" /> -->
  14. <j-tree-select
  15. ref="treeSelect"
  16. placeholder="请选择设备分类"
  17. v-model="model.equipmenttreeid"
  18. dict="ems_tpm_equipment_tree,name,id"
  19. pidField="parentid"
  20. pidValue="0"
  21. hasChildField="has_child"
  22. >
  23. </j-tree-select>
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :span="24">
  27. <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentcode">
  28. <span slot="label">
  29. 设备编号&nbsp;
  30. <a-tooltip title="若未填写设备编号 则自动生成">
  31. <a-icon type="exclamation-circle" theme="filled" />
  32. </a-tooltip>
  33. </span>
  34. <a-input v-model="model.equipmentcode" placeholder="请输入设备编号" ></a-input>
  35. </a-form-model-item>
  36. </a-col>
  37. <a-col :span="24">
  38. <a-form-model-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spec">
  39. <a-input v-model="model.spec" placeholder="请输入规格型号" ></a-input>
  40. </a-form-model-item>
  41. </a-col>
  42. <a-col :span="24">
  43. <a-form-model-item label="安装地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
  44. <a-input v-model="model.address" placeholder="请输入安装地点" ></a-input>
  45. </a-form-model-item>
  46. </a-col>
  47. <a-col :span="24">
  48. <a-form-model-item label="区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spaceid">
  49. <!-- <a-input v-model="model.spaceid" placeholder="请输入区域" ></a-input> -->
  50. <j-tree-select
  51. ref="treeSelect"
  52. placeholder="请选择区域"
  53. v-model="model.spaceid"
  54. dict="ems_space,name,id"
  55. pidField="parentid"
  56. pidValue="0"
  57. hasChildField="has_child"
  58. >
  59. </j-tree-select>
  60. </a-form-model-item>
  61. </a-col>
  62. </a-row>
  63. </a-form-model>
  64. </j-form-container>
  65. </a-spin>
  66. </template>
  67. <script>
  68. import { httpAction, getAction } from '@/api/manage'
  69. import { validateDuplicateValue } from '@/utils/util'
  70. export default {
  71. name: 'TpmEquipmentForm',
  72. components: {
  73. },
  74. props: {
  75. //表单禁用
  76. disabled: {
  77. type: Boolean,
  78. default: false,
  79. required: false
  80. }
  81. },
  82. data () {
  83. return {
  84. model:{
  85. },
  86. labelCol: {
  87. xs: { span: 24 },
  88. sm: { span: 5 },
  89. },
  90. wrapperCol: {
  91. xs: { span: 24 },
  92. sm: { span: 16 },
  93. },
  94. confirmLoading: false,
  95. validatorRules: {
  96. equipmentname: [
  97. { required: true, message: '请输入设备名称!'},
  98. ],
  99. equipmenttreeid: [
  100. { required: true, message: '请选择设备分类!'},
  101. ],
  102. },
  103. url: {
  104. add: "/tpmEquipment/tpmEquipment/add",
  105. edit: "/tpmEquipment/tpmEquipment/edit",
  106. queryById: "/tpmEquipment/tpmEquipment/queryById"
  107. }
  108. }
  109. },
  110. computed: {
  111. formDisabled(){
  112. return this.disabled
  113. },
  114. },
  115. created () {
  116. //备份model原始值
  117. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  118. },
  119. methods: {
  120. add () {
  121. this.edit(this.modelDefault);
  122. },
  123. edit (record) {
  124. this.model = Object.assign({}, record);
  125. this.visible = true;
  126. },
  127. submitForm () {
  128. const that = this;
  129. // 触发表单验证
  130. this.$refs.form.validate(valid => {
  131. if (valid) {
  132. that.confirmLoading = true;
  133. let httpurl = '';
  134. let method = '';
  135. if(!this.model.id){
  136. httpurl+=this.url.add;
  137. method = 'post';
  138. }else{
  139. httpurl+=this.url.edit;
  140. method = 'put';
  141. }
  142. httpAction(httpurl,this.model,method).then((res)=>{
  143. if(res.success){
  144. that.$message.success(res.message);
  145. that.$emit('ok');
  146. }else{
  147. that.$message.warning(res.message);
  148. }
  149. }).finally(() => {
  150. that.confirmLoading = false;
  151. })
  152. }
  153. })
  154. },
  155. handleCategoryChange(value,backObj){
  156. this.model = Object.assign(this.model, backObj);
  157. }
  158. }
  159. }
  160. </script>