TpmParamsForm.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. <!-- <j-search-select-tag v-model="model.equipmentid" placeholder="请选择设备" dict="tpm_equipment,equipmentname,id" /> -->
  9. <a-select
  10. v-model="model.equipmentid"
  11. placeholder="请输入设备名称或设备编号"
  12. show-search
  13. :filterOption="filterOptions"
  14. @search="searchDevice"
  15. @change="handleInput"
  16. allowClear>
  17. <a-select-option v-for="(item, index) in deviceOptions" :key="index" :value="item.equipmentcode" :label="item.equipmentname">
  18. <span>{{item.equipmentname}}</span>
  19. <span style="position: absolute;right: 2%;">{{ item.equipmentcode }}</span>
  20. </a-select-option>
  21. </a-select>
  22. </a-form-model-item>
  23. </a-col>
  24. <a-col :span="12">
  25. <a-form-model-item label="参数名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tagname">
  26. <a-input v-model="model.tagname" placeholder="请输入参数名称" ></a-input>
  27. </a-form-model-item>
  28. </a-col>
  29. <a-col :span="12">
  30. <a-form-model-item label="参数符号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="symbol">
  31. <a-input v-model="model.symbol" placeholder="请输入参数符号" ></a-input>
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :span="12">
  35. <a-form-model-item label="最小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="minv">
  36. <a-input-number v-model="model.minv" placeholder="请输入最小值" style="width: 100%" />
  37. </a-form-model-item>
  38. </a-col>
  39. <a-col :span="12">
  40. <a-form-model-item label="最大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maxv">
  41. <a-input-number v-model="model.maxv" placeholder="请输入最大值" style="width: 100%" />
  42. </a-form-model-item>
  43. </a-col>
  44. <a-col :span="12">
  45. <a-form-model-item label="参数类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="valuetype">
  46. <a-select
  47. placeholder="请选择"
  48. default-value="0"
  49. v-model="model.valuetype">
  50. <a-select-option value="int">int</a-select-option>
  51. <a-select-option value="timestamp">timestamp</a-select-option>
  52. <a-select-option value="float">float</a-select-option>
  53. </a-select>
  54. </a-form-model-item>
  55. </a-col>
  56. </a-row>
  57. </a-form-model>
  58. </j-form-container>
  59. </a-spin>
  60. </template>
  61. <script>
  62. import { httpAction, getAction } from '@/api/manage'
  63. import { validateDuplicateValue } from '@/utils/util'
  64. export default {
  65. name: 'TpmParamsForm',
  66. components: {
  67. },
  68. props: {
  69. //表单禁用
  70. disabled: {
  71. type: Boolean,
  72. default: false,
  73. required: false
  74. }
  75. },
  76. data () {
  77. return {
  78. model:{
  79. },
  80. deviceOptions: [],
  81. deviceOptionsAll: [],
  82. labelCol: {
  83. xs: { span: 24 },
  84. sm: { span: 5 },
  85. },
  86. wrapperCol: {
  87. xs: { span: 24 },
  88. sm: { span: 16 },
  89. },
  90. confirmLoading: false,
  91. validatorRules: {
  92. equipmentname: [
  93. { required: true, message: '请输入设备名称!'},
  94. ],
  95. equipmentcode: [
  96. { required: true, message: '请输入设备编号!'},
  97. ],
  98. tagname: [
  99. { required: true, message: '请输入参数名称!'},
  100. ],
  101. symbol: [
  102. { required: true, message: '请输入参数符号!'},
  103. ],
  104. },
  105. url: {
  106. add: "/tpmParams/tpmParams/add",
  107. edit: "/tpmParams/tpmParams/edit",
  108. queryById: "/tpmParams/tpmParams/queryById"
  109. }
  110. }
  111. },
  112. computed: {
  113. formDisabled(){
  114. return this.disabled
  115. },
  116. },
  117. created () {
  118. //备份model原始值
  119. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  120. this.getDeviceOption();
  121. },
  122. methods: {
  123. handleInput(e) {
  124. var _this = this;
  125. this.deviceOptions.forEach(element => {
  126. if (element.equipmentcode === e) {
  127. _this.model.equipmentcode = e;
  128. _this.model.equipmentname = element.equipmentname;
  129. return;
  130. }
  131. });
  132. },
  133. // 获取设备下拉列表
  134. getDeviceOption(){
  135. getAction(`/tpmEquipment/tpmEquipment/selectEquipmentList`).then(res=>{
  136. this.deviceOptions = res.result.map((res) => {
  137. return {
  138. id: res.id,
  139. equipmentname: res.equipmentname,
  140. equipmentcode: res.equipmentcode,
  141. }
  142. })
  143. // 存一个完整的设备表
  144. this.deviceOptionsAll = this.deviceOptions
  145. })
  146. },
  147. // 筛选设备
  148. searchDevice(value) {
  149. // 若输入的值删除,则重新赋完整的设备列表
  150. if (value.trim().length === 0) {
  151. this.deviceOptions = this.deviceOptionsAll
  152. }
  153. // 通过判断字符串中是数字还是文字进而判断是通过设备名筛选还是设备编号筛选
  154. let panDuan = isNaN(parseFloat(value))
  155. if (!panDuan) {
  156. // 数字
  157. let filteredArray = this.deviceOptionsAll.filter(item => item.equipmentcode.includes(value));
  158. this.deviceOptions = filteredArray
  159. } else {
  160. let filteredArray = this.deviceOptionsAll.filter(item => item.equipmentname.includes(value));
  161. this.deviceOptions = filteredArray
  162. }
  163. },
  164. // 解决筛选后option不回显问题
  165. filterOptions(input, option) {
  166. return this.deviceOptions
  167. },
  168. // 解决筛选后删除option不回显问题
  169. clearOptions() {
  170. this.deviceOptions = this.deviceOptionsAll
  171. },
  172. add () {
  173. this.edit(this.modelDefault);
  174. },
  175. edit (record) {
  176. this.model = Object.assign({}, record);
  177. this.visible = true;
  178. },
  179. submitForm () {
  180. const that = this;
  181. // 触发表单验证
  182. this.$refs.form.validate(valid => {
  183. if (valid) {
  184. that.confirmLoading = true;
  185. let httpurl = '';
  186. let method = '';
  187. if(!this.model.id){
  188. httpurl+=this.url.add;
  189. method = 'post';
  190. }else{
  191. httpurl+=this.url.edit;
  192. method = 'put';
  193. }
  194. httpAction(httpurl,this.model,method).then((res)=>{
  195. if(res.success){
  196. that.$message.success(res.message);
  197. that.$emit('ok');
  198. }else{
  199. that.$message.warning(res.message);
  200. }
  201. }).finally(() => {
  202. that.confirmLoading = false;
  203. })
  204. }
  205. })
  206. },
  207. }
  208. }
  209. </script>