addSignUpDialog.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script setup>
  2. import { ficcManageInterface } from "@/api/api.js";
  3. import { ElMessage, ElMessageBox } from 'element-plus'
  4. import { ref } from 'vue'
  5. const props = defineProps({
  6. // 活动Id
  7. ActivityId: {
  8. type: [Number, String],
  9. required: true,
  10. },
  11. // 弹窗是否显示
  12. isShow: {
  13. type: Boolean,
  14. required: true,
  15. },
  16. getSignUpList:{
  17. type:Function,
  18. default:()=>{}
  19. }
  20. })
  21. let dynamicItem = ref([{ name: "", isShow: false }]) // 新增列表
  22. let companyList = ref([]) // 联想用户列表
  23. // 新增报名窗口关闭
  24. const emit = defineEmits(["closeDia"]);
  25. function addDialogClose() {
  26. dynamicItem.value = [{ name: "", isShow: false }];
  27. companyList=[];
  28. emit("closeDia")
  29. }
  30. // 获取客户名称
  31. async function getCompany(Keyword) {
  32. if (Keyword.includes(",")) return;
  33. if (!Keyword) return (companyList.value = []);
  34. try {
  35. const res = await ficcManageInterface.activitySignupUserList({ Keyword });
  36. if (res.Ret === 200) {
  37. companyList.value = res.Data
  38. ? res.Data.map((item) => {
  39. return {
  40. ...item,
  41. value: `${item.RealName},${item.Mobile},${item.CompanyName}`,
  42. };
  43. })
  44. : [];
  45. }
  46. } catch (err) {
  47. console.dir(err);
  48. }
  49. }
  50. async function callbackHandle(data, cb) {
  51. if(!data) return
  52. await getCompany(data);
  53. cb(companyList.value);
  54. }
  55. //联想选择后
  56. function selectCompany(val, index) {
  57. companyList.value.forEach((item) => {
  58. if (item.value == val.name) {
  59. dynamicItem.value.splice(index, 1, {
  60. name: val.name,
  61. isShow: false,
  62. id: item.UserId,
  63. });
  64. }
  65. });
  66. }
  67. //失去焦点
  68. function focusCompany(name) {
  69. if (name.length && companyList.value.length == 0) {
  70. dynamicItem.value.find((item) => item.name == name).isShow = true;
  71. } else {
  72. dynamicItem.value.find((item) => item.name == name).isShow = false;
  73. }
  74. }
  75. // 添加用户
  76. function addItem() {
  77. dynamicItem.value.push({
  78. name: "",
  79. isShow: false,
  80. });
  81. }
  82. // 删除用户
  83. function deleteItem(index) {
  84. dynamicItem.value.splice(index, 1);
  85. }
  86. // 确定提交报名
  87. async function confirmPerson() {
  88. if (dynamicItem.value.some((item) => item.isShow))
  89. return ElMessage.error("姓名有误");
  90. // 对数组进行处理(去空去重,取出id)
  91. const UserIdList = dynamicItem.value
  92. .map((item) => item.id)
  93. .filter((item,index,arr) => {
  94. return item && arr.indexOf(item, 0) === index;
  95. })
  96. // 数组为空提示
  97. if (!UserIdList.length) return ElMessage.error("请至少选择一个");
  98. try {
  99. const res = await ficcManageInterface.activitySignupAddUser({
  100. ActivityId: props.ActivityId,
  101. UserIdList,
  102. });
  103. if (res.Ret === 200) {
  104. ElMessage.success("添加成功");
  105. props.getSignUpList()
  106. addDialogClose();
  107. }
  108. } catch (err) {
  109. console.dir(err);
  110. }
  111. }
  112. </script>
  113. <template>
  114. <el-dialog
  115. :modal-append-to-body="false"
  116. :center="true"
  117. close-on-press-escape
  118. :close-on-click-modal="false"
  119. :model-value="isShow"
  120. @close="addDialogClose"
  121. title="新增线下报名"
  122. width="500px"
  123. class="add-signup-dialog"
  124. >
  125. <div class="inline" v-for="(item, index) in dynamicItem" :key="index">
  126. <div class="inline-content">
  127. <el-autocomplete
  128. class="inline-input"
  129. v-model.trim="item.name"
  130. :fetch-suggestions="callbackHandle"
  131. placeholder="请输入姓名"
  132. @select="selectCompany(item, index)"
  133. @blur="focusCompany(item.name)"
  134. :trigger-on-focus="false"
  135. clearable
  136. ></el-autocomplete>
  137. <img
  138. @click="deleteItem(index)"
  139. src="~@/assets/img/icons/delete-Item.png"
  140. :class="index == 0 ? 'defaultyi' : ''"
  141. alt=""
  142. />
  143. </div>
  144. <p v-if="item.isShow">
  145. 系统中无此人,请先将其添加到对应公司的联系人列表下
  146. </p>
  147. </div>
  148. <div @click="addItem" class="add-box">
  149. <img :src="$icons.addblue" alt="" />
  150. <span>添加</span>
  151. </div>
  152. <span slot="footer" class="dialog-footer">
  153. <el-button type="primary" @click="confirmPerson">确定</el-button>
  154. <el-button @click="addDialogClose">取消</el-button>
  155. </span>
  156. </el-dialog>
  157. </template>
  158. <style lang="scss">
  159. .add-signup-dialog{
  160. .inline {
  161. margin-bottom: 20px;
  162. .inline-content{
  163. padding-right: 20px;
  164. display: flex;
  165. justify-content: space-between;
  166. align-items: center;
  167. .inline-input{
  168. width: 392px;
  169. .el-input {
  170. width: 100%;
  171. }
  172. }
  173. img {
  174. width: 14px;
  175. height: 14px;
  176. cursor: pointer;
  177. }
  178. .defaultyi {
  179. display: none;
  180. }
  181. }
  182. p {
  183. padding-top: 5px;
  184. font-size: 14px;
  185. font-family: PingFang SC;
  186. font-weight: 500;
  187. line-height: 20px;
  188. color: #ef5858;
  189. opacity: 1;
  190. }
  191. }
  192. .add-box {
  193. width: 80px;
  194. display: flex;
  195. align-items: center;
  196. color: #5882ef;
  197. cursor: pointer;
  198. img {
  199. width: 16px;
  200. height: 16px;
  201. margin-right: 10px;
  202. }
  203. }
  204. }
  205. </style>