editClientPopup.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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="groupId">
  25. <el-select
  26. popper-class="select-popper-orange"
  27. class="select mr-10 select-orange"
  28. v-model="ruleForm.groupId"
  29. >
  30. <el-option
  31. v-for="(item, index) in groupOptions"
  32. :key="index"
  33. :label="item.groupName"
  34. :value="item.id"
  35. />
  36. <template #footer>
  37. <div class="add-btn" v-if="!isAddingItem" @click="isAddingItem=true">
  38. <el-icon class="add-icon" size="16">
  39. <Plus />
  40. </el-icon>
  41. <span>新增分组</span>
  42. </div>
  43. <template v-else>
  44. <el-input v-model="ruleForm.groupName" class="option-input" /><br />
  45. <el-button type="primary" @click="submitGroupName"> 新增 </el-button>
  46. <el-button @click="isAddingItem=false">取消</el-button>
  47. </template>
  48. </template>
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="头像" prop="photo">
  52. <upload></upload>
  53. </el-form-item>
  54. </el-form>
  55. </div>
  56. <div class="popup-footer">
  57. <div class="cancel" @click="resetForm">取消</div>
  58. <div @click="submitForm">保存</div>
  59. </div>
  60. </popup>
  61. </div>
  62. </template>
  63. <script setup>
  64. import { Popup } from "vant";
  65. import { onMounted, reactive, ref } from 'vue';
  66. import { ElMessage } from "element-plus";
  67. import upload from "@/components/common/upload.vue";
  68. const showClient = ref(false);
  69. const ruleForm = reactive({
  70. name: "",
  71. tel: "",
  72. address: "",
  73. groupId: "",
  74. groupName: ""
  75. });
  76. const rules = reactive({
  77. name: { required: true, message: "请输入用户名称", trigger: ["blur", "change"] },
  78. tel: { required: true, message: "请输入电话号码", trigger: ["blur", "change"] },
  79. });
  80. const ruleFormRef = ref(null);
  81. const userId = ref(null);
  82. const submitForm = async () => {
  83. if (!ruleFormRef.value) return;
  84. await ruleFormRef.value.validate((valid, fields) => {
  85. if (valid) {
  86. const params = {
  87. id: userId.value,
  88. name: ruleForm.name,
  89. tel: ruleForm.tel,
  90. address: ruleForm.address,
  91. groupId: ruleForm.groupId,
  92. };
  93. VE_API.manage_interface.saveUserInfo(params).then(({code}) => {
  94. if (code === 0) {
  95. ElMessage.success("保存成功");
  96. showClient.value = false;
  97. emit("updateGroupList");
  98. }
  99. })
  100. } else {
  101. console.log("error submit!");
  102. }
  103. });
  104. };
  105. const groupOptions = ref([]);
  106. const isAddingItem = ref(false);
  107. function getGroupList() {
  108. VE_API.manage_user.fetchGroupList({farmId: 766}).then(({ data }) => {
  109. groupOptions.value = data;
  110. });
  111. }
  112. const submitGroupName = () => {
  113. const params = {
  114. groupName: ruleForm.groupName,
  115. };
  116. VE_API.manage_user
  117. .saveGroup(params)
  118. .then(({ code }) => {
  119. if (code === 0) {
  120. ElMessage.success("新建分组成功");
  121. getGroupList()
  122. emit("updateGroupList");
  123. }
  124. });
  125. };
  126. const emit = defineEmits(["updateGroupList"]);
  127. onMounted(() => {
  128. getGroupList();
  129. });
  130. //新增客户
  131. const typePopup = ref("add");
  132. const resetForm = () => {
  133. if (!ruleFormRef.value) return;
  134. ruleFormRef.value.resetFields();
  135. showClient.value = false;
  136. };
  137. // 打开弹窗-类型
  138. function openClientPopup(type, data) {
  139. userId.value = data ? data.id : null;
  140. if (type === "edit") {
  141. ruleForm.name = data.name;
  142. ruleForm.tel = data.tel;
  143. ruleForm.address = data.address;
  144. // ruleForm.groupId = data.groupId;
  145. } else {
  146. ruleForm.name = "";
  147. ruleForm.tel = "";
  148. ruleForm.address = "";
  149. }
  150. typePopup.value = type;
  151. showClient.value = true;
  152. }
  153. defineExpose({
  154. openClientPopup,
  155. });
  156. </script>
  157. <style lang="scss" scoped>
  158. .popup-client {
  159. // width: 24%;
  160. width: 504px;
  161. padding: 31px 25px;
  162. box-sizing: border-box;
  163. background: #fff;
  164. ::v-deep {
  165. .van-popup__close-icon {
  166. // color: #ffffff;
  167. }
  168. }
  169. .popup-title {
  170. text-align: center;
  171. color: #000;
  172. font-size: 24px;
  173. margin-bottom: 15px;
  174. }
  175. .popup-content {
  176. width: 100%;
  177. ::v-deep {
  178. .el-form-item__label {
  179. color: rgba(0, 0, 0, 0.4);
  180. }
  181. .el-input__wrapper {
  182. background: transparent;
  183. box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.46) inset;
  184. }
  185. }
  186. .input {
  187. height: 46px;
  188. font-size: 16px;
  189. }
  190. }
  191. .popup-footer {
  192. width: 100%;
  193. display: flex;
  194. border-top: 1px solid rgba(0, 0, 0, 0.1);
  195. margin-top: 30px;
  196. padding-top: 25px;
  197. div {
  198. flex: 1;
  199. background: linear-gradient(120deg, #ffd887, #ed9e1e);
  200. border-radius: 6px;
  201. padding: 13px;
  202. font-size: 20px;
  203. color: #000;
  204. text-align: center;
  205. cursor: pointer;
  206. }
  207. .cancel {
  208. color: #000;
  209. background: #f3f3f3;
  210. margin-right: 30px;
  211. }
  212. }
  213. }
  214. </style>