childDialog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="dialog">
  3. <el-dialog
  4. v-model="dialogVisible"
  5. :title="dialogTitle"
  6. width="480"
  7. @close="closeDialog()"
  8. >
  9. <el-form
  10. ref="formRef"
  11. :model="formData"
  12. :rules="rules"
  13. label-width="120px"
  14. >
  15. <el-row>
  16. <el-col :span="24">
  17. <el-form-item prop="clientName" label="客户名称">
  18. <el-input v-model="formData.clientName" />
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="24">
  22. <el-form-item prop="clientCode" label="客户编码">
  23. <el-input
  24. :disabled="formData.id > 0"
  25. v-model="formData.clientCode"
  26. />
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="24">
  30. <el-form-item prop="md5ParamDigest" label="通讯密钥">
  31. <el-input v-model="formData.md5ParamDigest" />
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="24">
  35. <el-form-item prop="contactPhone" label="联系电话">
  36. <el-input v-model="formData.contactPhone" />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="24">
  40. <el-form-item prop="contactPerson" label="联系人">
  41. <el-input v-model="formData.contactPerson" />
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="24">
  45. <el-form-item prop="clientAddress" label="地址">
  46. <el-input v-model="formData.clientAddress" />
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="24">
  50. <el-form-item prop="erpServerUrl" label="erp服务器连接地址">
  51. <el-input v-model="formData.erpServerUrl" />
  52. </el-form-item>
  53. </el-col>
  54. </el-row>
  55. </el-form>
  56. <template #footer>
  57. <div class="dialog-footer">
  58. <el-button v-throttle type="primary" @click="handleSubmit"
  59. >确 定
  60. </el-button>
  61. <el-button @click="closeDialog()">取 消</el-button>
  62. </div>
  63. </template>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script setup lang="ts">
  68. import { addClientInfo, getERPClient, updateClientInfo } from "@/api/baseInfo";
  69. import type { FormInstance } from "element-plus";
  70. let dialogVisible = ref(false);
  71. let dialogTitle = ref("");
  72. const formRef = ref<FormInstance>();
  73. const emit = defineEmits(["dialogChange"]);
  74. const formData = reactive({
  75. contactPerson: "",
  76. contactPhone: "",
  77. clientAddress: "",
  78. clientName: "",
  79. clientCode: "",
  80. md5ParamDigest: "",
  81. erpServerUrl: "",
  82. id: 0,
  83. });
  84. const rules = reactive({
  85. clientName: [{ required: true, message: "请输入客户名称", trigger: "blur" }],
  86. });
  87. function handleSubmit() {
  88. formRef.value.validate((valid: any) => {
  89. if (valid) {
  90. const itemId = formData.id;
  91. if (itemId) {
  92. //修改
  93. const postData = JSON.stringify(formData);
  94. const params = {
  95. erpClient: postData,
  96. };
  97. updateClientInfo(params).then((response) => {
  98. dialogVisible.value = false;
  99. if (response.httpCode == 200) {
  100. emit("dialogChange");
  101. ElMessage.success("操作成功");
  102. }
  103. });
  104. } else {
  105. //增加
  106. const postData = JSON.stringify(formData);
  107. const params = {
  108. erpClient: postData,
  109. };
  110. addClientInfo(params).then((response) => {
  111. dialogVisible.value = false;
  112. if (response.httpCode == 200) {
  113. emit("dialogChange");
  114. ElMessage.success("操作成功");
  115. }
  116. });
  117. }
  118. }
  119. });
  120. }
  121. function getItemData(item) {
  122. const data = {
  123. idClient: item,
  124. };
  125. getERPClient(data).then((response) => {
  126. if (response.httpCode == 200) {
  127. const data = response.data;
  128. Object.assign(formData, { ...data });
  129. }
  130. });
  131. }
  132. /** 重置表单 */
  133. function resetForm() {
  134. formRef.value.resetFields();
  135. formData.id = "";
  136. }
  137. /**关闭弹窗 */
  138. function closeDialog() {
  139. dialogVisible.value = false;
  140. formRef.value.resetFields();
  141. formData.id = undefined;
  142. }
  143. defineExpose({
  144. dialogVisible,
  145. dialogTitle,
  146. getItemData,
  147. resetForm,
  148. });
  149. </script>
  150. <style scoped lang="scss"></style>