threshold.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div>
  3. <a-modal v-model:visible="visible" width="50%" :closable="false" :maskClosable="false" :title="titleText"
  4. :footer="null">
  5. <a-form ref="formRef" :model="formState" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
  6. <div class="text-box">
  7. <a-form-item label="预警名称" name="warningName">
  8. <a-input class="title-box" autocomplete="off" :disabled="showLock" v-model:value="formState.warningName" />
  9. </a-form-item>
  10. <a-form-item label="架空期预警第一个月" name="firstMonthWarning">
  11. <a-input-number :formatter="formatter" class="title-box" autocomplete="off" :disabled="showLock"
  12. v-model:value="formState.firstMonthWarning" />
  13. </a-form-item>
  14. <a-form-item label="架空期预警第二个月" name="secondMonthWarning">
  15. <a-input-number :formatter="formatter" class="title-box" autocomplete="off" :disabled="showLock"
  16. v-model:value="formState.secondMonthWarning" />
  17. </a-form-item>
  18. <a-form-item label="架空期预警第三个月" name="thirdMonthWarning">
  19. <a-input-number :formatter="formatter" class="title-box" autocomplete="off" :disabled="showLock"
  20. v-model:value="formState.thirdMonthWarning" />
  21. </a-form-item>
  22. <a-form-item label="架空期预警第四个月" name="fourthMonthWarning">
  23. <a-input-number :formatter="formatter" class="title-box" autocomplete="off" :disabled="showLock"
  24. v-model:value="formState.fourthMonthWarning" />
  25. </a-form-item>
  26. </div>
  27. </a-form>
  28. <div class="btn-box">
  29. <a-button v-if="dataObj.isType !== '3'" style="margin-right: 16px" type="primary" @click="handleOk">保存</a-button>
  30. <a-button @click="handleCancel">关闭</a-button>
  31. </div>
  32. </a-modal>
  33. </div>
  34. </template>
  35. <script setup>
  36. import rotationPlanApi from "@/api/rotationPlan.info/rotationPlanApi";
  37. // import { isSocialCreditOrIdCode } from '@/utils/validator'
  38. const props = defineProps({
  39. dataObj: {
  40. type: Object,
  41. default: () => { }
  42. }
  43. })
  44. const formState = ref({})
  45. const rules = ref({
  46. warningName: [{ required: true, message: '请输入预警名称', trigger: 'blur' }],
  47. firstMonthWarning: [{ required: true, message: '请输入第一月百分值', trigger: 'blur' }],
  48. secondMonthWarning: [{ required: true, message: '请输入第二月百分值', trigger: 'blur' }],
  49. thirdMonthWarning: [{ required: true, message: '请输入第三月百分值', trigger: 'blur' }],
  50. fourthMonthWarning: [{ required: true, message: '请输入第四月百分值', trigger: 'blur' }]
  51. })
  52. const isTypeData = ref('')
  53. const showLock = ref(false)
  54. const visible = ref(false)
  55. const titleText = ref('')
  56. const formRef = ref(null)
  57. const emit = defineEmits(['isVisible'])
  58. // 取消按钮
  59. const handleCancel = () => {
  60. colosData()
  61. }
  62. // 确定按钮
  63. const handleOk = () => {
  64. formRef.value
  65. .validate()
  66. .then(() => {
  67. // isTypeData === '1' 新增 2是编辑 3是查看
  68. if (isTypeData.value === '1') return addData()
  69. if (isTypeData.value === '2') return editData()
  70. })
  71. .catch((error) => {
  72. message.warning('请填写完善')
  73. console.log('error', error)
  74. })
  75. }
  76. // 新增
  77. const addData = () => {
  78. formRef.value
  79. .validate()
  80. .then(() => {
  81. let obj = {
  82. warningName: formState.value.warningName,
  83. firstMonthWarning: formState.value.firstMonthWarning,
  84. secondMonthWarning: formState.value.secondMonthWarning,
  85. thirdMonthWarning: formState.value.thirdMonthWarning,
  86. fourthMonthWarning: formState.value.fourthMonthWarning
  87. }
  88. rotationPlanApi.rotationAdd(obj).then((res) => {
  89. colosData()
  90. message.success('操作成功')
  91. })
  92. })
  93. .catch((error) => {
  94. message.warning('请填写完善')
  95. console.log('error', error)
  96. })
  97. }
  98. // 编辑
  99. const editData = () => {
  100. formRef.value
  101. .validate()
  102. .then(() => {
  103. let obj = {
  104. id: props.dataObj.id,
  105. warningName: formState.value.warningName,
  106. firstMonthWarning: formState.value.firstMonthWarning,
  107. secondMonthWarning: formState.value.secondMonthWarning,
  108. thirdMonthWarning: formState.value.thirdMonthWarning,
  109. fourthMonthWarning: formState.value.fourthMonthWarning
  110. }
  111. rotationPlanApi.rotationEdit(obj).then((res) => {
  112. colosData()
  113. message.success('操作成功')
  114. })
  115. })
  116. .catch((error) => {
  117. message.warning('请填写完善')
  118. console.log('error', error)
  119. })
  120. }
  121. // 用于查看调用
  122. const detailData = (id) => {
  123. rotationPlanApi.rotationSubmitForm({ id: id }).then((res) => {
  124. formState.value = { ...res }
  125. })
  126. }
  127. //推荐使用: 实时验证,输入值大于100时显示100,并且不显示多余的数字;值为空时显示0 ;如果不满足需求你可以在接着改
  128. const formatter = (value) => {
  129. let reg = /^([0-9]{1,2}|100)$/ //0-100的正整数
  130. let reg1 = /\D/g
  131. if (reg.test(value)) {
  132. return Number(value.replace(reg1, '')).toLocaleString()
  133. } else {
  134. // value = 100
  135. if (value == '') {
  136. return null
  137. } else {
  138. value = null
  139. return value
  140. }
  141. }
  142. }
  143. // 取消按钮
  144. const colosData = () => {
  145. visible.value = false
  146. emit('isVisible', false)
  147. formRef.value.resetFields() //resetFields()函数是组件库提供的
  148. formState.value = {}
  149. }
  150. // 监听点击事件更新数据
  151. watch(
  152. () => props.dataObj,
  153. async (newValue, oldvalue) => {
  154. await nextTick()
  155. titleText.value = newValue.titleText
  156. visible.value = newValue.visible
  157. showLock.value = newValue.showLock
  158. isTypeData.value = newValue.isType
  159. // isType字段用于查看接口
  160. if (newValue.isType == '2' || newValue.isType == '3') {
  161. detailData(newValue.id)
  162. } else {
  163. // 用于新增时清空表格数据
  164. formState.value = {}
  165. }
  166. },
  167. { deep: true, immediate: true }
  168. )
  169. </script>
  170. <style lang="less" scoped>
  171. .ant-input {
  172. width: 80%;
  173. }
  174. /* 针对 a-form-item 的 label 应用样式 */
  175. ::v-deep .ant-form-item-label {
  176. width: 160px;
  177. text-align: right;
  178. }
  179. ::v-deep .ant-form-item-control-input {
  180. width: 100%;
  181. }
  182. /deep/.ant-input-number-input {
  183. text-align: left !important;
  184. }
  185. .title-box {
  186. width: 100%;
  187. }
  188. .ant-picker {
  189. width: 92%;
  190. }
  191. .ant-select {
  192. width: 80% !important;
  193. }
  194. .from-input {
  195. width: 101.4%;
  196. }
  197. ::v-deep.ant-modal-footer {
  198. display: none !important;
  199. }
  200. .text-box {
  201. margin: 0 auto;
  202. width: 60%;
  203. }
  204. .btn-box {
  205. text-align: center;
  206. }
  207. .btn-type {
  208. background-color: #22ce8d;
  209. color: #fff;
  210. }
  211. //去除 input输入框后面的小箭头
  212. /deep/.ant-input-number-input {
  213. height: 32px !important;
  214. }
  215. /deep/.ant-input-number {
  216. width: 100%;
  217. height: 100%;
  218. box-shadow: none;
  219. .ant-input-number-input-wrap {
  220. height: 100%;
  221. input {
  222. height: 100%;
  223. text-align: center;
  224. }
  225. }
  226. .ant-input-number-handler-wrap {
  227. display: none;
  228. }
  229. }
  230. </style>