editClientPopup.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div>
  3. <!-- 新增客户、编辑客户 -->
  4. <popup v-model:show="showClient" closeable round class="popup-client">
  5. <div class="popup-title">{{ typePopup === "add" ? "新增客户" : "编辑客户" }}</div>
  6. <div class="popup-content">
  7. <el-form
  8. ref="ruleFormRef"
  9. :model="ruleForm"
  10. :rules="rules"
  11. label-width="auto"
  12. class="rule-form"
  13. size="large"
  14. >
  15. <el-form-item label="姓名" prop="name">
  16. <el-input class="input" v-model="ruleForm.name" size="large" placeholder="请输入姓名" />
  17. </el-form-item>
  18. <el-form-item label="电话" prop="tel">
  19. <el-input class="input" v-model="ruleForm.tel" size="large" placeholder="请输入电话号码" />
  20. </el-form-item>
  21. <el-form-item label="地址" prop="address">
  22. <el-input class="input" v-model="ruleForm.address" size="large" placeholder="请输入地址" />
  23. </el-form-item>
  24. <el-form-item label="头像" prop="photo">
  25. <upload></upload>
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. <div class="popup-footer">
  30. <div class="cancel" @click="resetForm">取消</div>
  31. <div @click="submitForm">保存</div>
  32. </div>
  33. </popup>
  34. </div>
  35. </template>
  36. <script setup>
  37. import { Popup } from "vant";
  38. import { reactive, ref } from 'vue';
  39. import { ElMessage } from "element-plus";
  40. import upload from "@/components/common/upload.vue";
  41. const showClient = ref(false);
  42. const ruleForm = reactive({
  43. name: "",
  44. tel: "",
  45. address: "",
  46. });
  47. const rules = reactive({
  48. name: { required: true, message: "请输入用户名称", trigger: ["blur", "change"] },
  49. tel: { required: true, message: "请输入电话号码", trigger: ["blur", "change"] },
  50. });
  51. const ruleFormRef = ref(null);
  52. const submitForm = async () => {
  53. if (!ruleFormRef.value) return;
  54. await ruleFormRef.value.validate((valid, fields) => {
  55. if (valid) {
  56. ElMessage.success("保存成功");
  57. showClient.value = false;
  58. } else {
  59. console.log("error submit!");
  60. }
  61. });
  62. };
  63. //新增客户
  64. const typePopup = ref("add");
  65. const resetForm = () => {
  66. if (!ruleFormRef.value) return;
  67. ruleFormRef.value.resetFields();
  68. showClient.value = false;
  69. };
  70. // 打开弹窗-类型
  71. function openClientPopup(type, data) {
  72. console.log('data', data);
  73. if (type === "edit") {
  74. ruleForm.name = data.name;
  75. ruleForm.tel = data.tel;
  76. ruleForm.address = data.address;
  77. } else {
  78. ruleForm.name = "";
  79. ruleForm.tel = "";
  80. ruleForm.address = "";
  81. }
  82. typePopup.value = type;
  83. showClient.value = true;
  84. }
  85. defineExpose({
  86. openClientPopup,
  87. });
  88. </script>
  89. <style lang="scss" scoped>
  90. .popup-client {
  91. // width: 24%;
  92. width: 504px;
  93. padding: 31px 25px;
  94. box-sizing: border-box;
  95. background: #fff;
  96. ::v-deep {
  97. .van-popup__close-icon {
  98. // color: #ffffff;
  99. }
  100. }
  101. .popup-title {
  102. text-align: center;
  103. color: #000;
  104. font-size: 24px;
  105. margin-bottom: 15px;
  106. }
  107. .popup-content {
  108. width: 100%;
  109. ::v-deep {
  110. .el-form-item__label {
  111. color: rgba(0, 0, 0, 0.4);
  112. }
  113. .el-input__wrapper {
  114. background: transparent;
  115. box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.46) inset;
  116. }
  117. }
  118. .input {
  119. height: 46px;
  120. font-size: 16px;
  121. }
  122. }
  123. .popup-footer {
  124. width: 100%;
  125. display: flex;
  126. border-top: 1px solid rgba(0, 0, 0, 0.1);
  127. margin-top: 30px;
  128. padding-top: 25px;
  129. div {
  130. flex: 1;
  131. background: linear-gradient(120deg, #ffd887, #ed9e1e);
  132. border-radius: 6px;
  133. padding: 13px;
  134. font-size: 20px;
  135. color: #000;
  136. text-align: center;
  137. cursor: pointer;
  138. }
  139. .cancel {
  140. color: #000;
  141. background: #f3f3f3;
  142. margin-right: 30px;
  143. }
  144. }
  145. }
  146. </style>