editMath.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <!-- 偏移随机 -->
  3. <n-button @click="showImportModal">偏移(随机)</n-button>
  4. <n-modal v-model:show="showModal" title="偏移(随机)" :mask-closable="false" :show-icon="false" preset="dialog">
  5. <n-form label-placement="left" label-width="auto" style="margin-top: 20px;">
  6. <n-form-item label="最大温度">
  7. <n-input-number v-model:value="data.TemperatureMax" :validator="(x) => x >= 0" style="width: 100%;">
  8. <template #suffix>
  9. °C
  10. </template>
  11. </n-input-number>
  12. </n-form-item>
  13. <n-form-item label="最小温度">
  14. <n-input-number v-model:value="data.TemperatureMin" :validator="(x) => x >= 0" style="width: 100%;">
  15. <template #suffix>
  16. °C
  17. </template>
  18. </n-input-number>
  19. </n-form-item>
  20. <n-form-item label="最大湿度">
  21. <n-input-number v-model:value="data.HumidityMax" :validator="(x) => x >= 0" style="width: 100%;">
  22. <template #suffix>
  23. %
  24. </template>
  25. </n-input-number>
  26. </n-form-item>
  27. <n-form-item label="最小湿度">
  28. <n-input-number v-model:value="data.HumidityMin" :validator="(x) => x >= 0" style="width: 100%;">
  29. <template #suffix>
  30. %
  31. </template>
  32. </n-input-number>
  33. </n-form-item>
  34. <div style="display: flex; justify-content: flex-end">
  35. <n-button @click="showModal = false" style="margin-right: 10px;">取消</n-button>
  36. <n-button type="primary" @click="handleValidateButtonClick">立即提交</n-button>
  37. </div>
  38. </n-form>
  39. </n-modal>
  40. </template>
  41. <script setup>
  42. import {TaskUpdateRand } from '@/api';
  43. import { reactive, ref, watch } from 'vue'
  44. import { useMessage } from 'naive-ui';
  45. import {TimeDate} from '@/plugin/timeFun.js'
  46. const message = useMessage();
  47. const value = ref(0)
  48. const props = defineProps({
  49. queryObj: {
  50. type: Object,
  51. default: () => ({}),
  52. },
  53. checkData:{
  54. type:Array,
  55. default: () => ([])
  56. }
  57. })
  58. const data = reactive({
  59. TemperatureMin: 0,
  60. TemperatureMax: 0,
  61. HumidityMin: 0,
  62. HumidityMax: 0,
  63. T_task_id: '',
  64. SN_List: ''
  65. })
  66. const model = reactive({
  67. StartTime:null,
  68. EndTime:null,
  69. })
  70. const showModal = ref(false)
  71. const showImportModal = () => {
  72. Object.keys(model).forEach(item=>{
  73. console.log(item)
  74. model[item] = null
  75. })
  76. if(props.checkData==null){
  77. message.error('请选择需要设置随机偏移的设备')
  78. return
  79. }else if(props.queryObj.Time_start=='' && props.queryObj.Time_end==''){
  80. message.error('请选择随机偏移时间')
  81. return
  82. }else{
  83. data.T_task_id = props.queryObj.T_task_id
  84. model.StartTime = props.queryObj.Time_start
  85. model.EndTime = props.queryObj.Time_end
  86. showModal.value = true
  87. }
  88. }
  89. //提交
  90. const handleValidateButtonClick = ()=>{
  91. TaskCopyApi()
  92. }
  93. const TaskCopyApi = async()=>{
  94. let resIt = await dataFun()
  95. TaskUpdateRand(resIt).then(res=>{
  96. if(res.data.Code==200){
  97. message.success(res.data.Msg)
  98. showModal.value = false
  99. }
  100. })
  101. }
  102. const dataFun = ()=>{
  103. return new Promise(resolve=>{
  104. let models = {...model}
  105. let snList = [...props.checkData]
  106. //处理时间戳转时间格式补零
  107. Object.keys(models).forEach(item=>{
  108. models[item] = TimeDate(models[item])+':00'
  109. })
  110. //处理sn List
  111. const arr1 = snList.map(item => item.T_sn + ',' +item.T_id)
  112. data.SN_List = arr1.join('|')+'|'
  113. resolve({
  114. ...data,...models
  115. })
  116. })
  117. }
  118. </script>
  119. <style lang="scss" scoped></style>