ContactForm.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <Dialog :title="dialogTitle" v-model="dialogVisible" :width="820">
  3. <el-form
  4. ref="formRef"
  5. :model="formData"
  6. :rules="formRules"
  7. label-width="110px"
  8. v-loading="formLoading"
  9. >
  10. <el-row :gutter="20">
  11. <el-col :span="12">
  12. <el-form-item label="姓名" prop="name">
  13. <el-input input-style="width:190px;" v-model="formData.name" placeholder="请输入姓名" />
  14. </el-form-item>
  15. </el-col>
  16. <el-col :span="12">
  17. <el-form-item label="负责人" prop="ownerUserId">
  18. <el-select
  19. v-model="formData.ownerUserId"
  20. placeholder="请选择负责人"
  21. value-key="id"
  22. lable-key="nickname"
  23. >
  24. <el-option
  25. v-for="item in userList"
  26. :key="item.id"
  27. :label="item.nickname"
  28. :value="item.id"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. </el-col>
  33. </el-row>
  34. <el-row>
  35. <el-col :span="12">
  36. <el-form-item label="客户名称" prop="customerName">
  37. <el-select
  38. v-model="formData.customerId"
  39. placeholder="请选择客户"
  40. value-key="id"
  41. lable-key="name"
  42. >
  43. <el-option
  44. v-for="item in customerList"
  45. :key="item.id"
  46. :label="item.name"
  47. :value="item.id"
  48. />
  49. </el-select>
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="12">
  53. <el-form-item label="性别" prop="sex">
  54. <el-select v-model="formData.sex" placeholder="请选择">
  55. <el-option
  56. v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
  57. :key="dict.value"
  58. :label="dict.label"
  59. :value="dict.value"
  60. />
  61. </el-select>
  62. </el-form-item>
  63. </el-col>
  64. </el-row>
  65. <el-row>
  66. <el-col :span="12">
  67. <el-form-item label="手机号" prop="mobile">
  68. <el-input
  69. input-style="width:190px;"
  70. v-model="formData.mobile"
  71. placeholder="请输入手机号"
  72. />
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="12">
  76. <el-form-item label="电话" prop="telephone">
  77. <el-input v-model="formData.telephone" placeholder="请输入电话" style="width: 215px" />
  78. </el-form-item>
  79. </el-col>
  80. </el-row>
  81. <el-row>
  82. <el-col :span="12">
  83. <el-form-item label="邮箱" prop="email">
  84. <el-input
  85. input-style="width:190px;"
  86. v-model="formData.email"
  87. placeholder="请输入邮箱"
  88. />
  89. </el-form-item>
  90. </el-col>
  91. <el-col :span="12">
  92. <el-form-item label="QQ" prop="qq">
  93. <el-input v-model="formData.qq" placeholder="请输入QQ" style="width: 215px" />
  94. </el-form-item>
  95. </el-col>
  96. </el-row>
  97. <el-row>
  98. <el-col :span="12">
  99. <el-form-item label="微信" prop="wechat">
  100. <el-input
  101. input-style="width:190px;"
  102. v-model="formData.wechat"
  103. placeholder="请输入微信"
  104. />
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="12">
  108. <el-form-item label="下次联系时间" prop="contactNextTime">
  109. <el-date-picker
  110. v-model="formData.contactNextTime"
  111. type="datetime"
  112. value-format="x"
  113. placeholder="选择下次联系时间"
  114. />
  115. </el-form-item>
  116. </el-col>
  117. </el-row>
  118. <el-row>
  119. <el-col :span="12">
  120. <el-form-item label="所在地" prop="areaId">
  121. <el-tree-select
  122. v-model="formData.areaId"
  123. :data="areaList"
  124. :props="defaultProps"
  125. :render-after-expand="true"
  126. />
  127. </el-form-item>
  128. </el-col>
  129. <el-col :span="12">
  130. <el-form-item label="地址" prop="detailAddress">
  131. <el-input
  132. input-style="width:190px;"
  133. v-model="formData.detailAddress"
  134. placeholder="请输入地址"
  135. />
  136. </el-form-item>
  137. </el-col>
  138. </el-row>
  139. <el-row>
  140. <el-col :span="12">
  141. <el-form-item label="直属上级" prop="parentId">
  142. <el-select v-model="formData.parentId" placeholder="请选择">
  143. <el-option
  144. v-for="item in allContactList"
  145. :key="item.id"
  146. :label="item.name"
  147. :value="item.id"
  148. :disabled="item.id == formData.id"
  149. />
  150. </el-select>
  151. </el-form-item>
  152. </el-col>
  153. <el-col :span="12">
  154. <el-form-item label="职位" prop="post">
  155. <el-input input-style="width:190px;" v-model="formData.post" placeholder="请输入职位" />
  156. </el-form-item>
  157. </el-col>
  158. </el-row>
  159. <el-row>
  160. <el-col :span="12">
  161. <el-form-item label="关键决策人" prop="master" style="width: 400px">
  162. <el-radio-group v-model="formData.master">
  163. <el-radio
  164. v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  165. :key="dict.value"
  166. :label="dict.value"
  167. >
  168. {{ dict.label }}
  169. </el-radio>
  170. </el-radio-group>
  171. </el-form-item>
  172. </el-col>
  173. </el-row>
  174. <el-row>
  175. <el-col :span="24">
  176. <el-form-item label="备注" prop="remark">
  177. <el-input v-model="formData.remark" placeholder="请输入备注" />
  178. </el-form-item>
  179. </el-col>
  180. </el-row>
  181. </el-form>
  182. <template #footer>
  183. <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  184. <el-button @click="dialogVisible = false">取 消</el-button>
  185. </template>
  186. </Dialog>
  187. </template>
  188. <script setup lang="ts">
  189. import * as ContactApi from '@/api/crm/contact'
  190. import { DICT_TYPE, getIntDictOptions, getBoolDictOptions } from '@/utils/dict'
  191. import * as UserApi from '@/api/system/user'
  192. import * as CustomerApi from '@/api/crm/customer'
  193. import * as AreaApi from '@/api/system/area'
  194. import { defaultProps } from '@/utils/tree'
  195. const { t } = useI18n() // 国际化
  196. const message = useMessage() // 消息弹窗
  197. const dialogVisible = ref(false) // 弹窗的是否展示
  198. const dialogTitle = ref('') // 弹窗的标题
  199. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  200. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  201. const areaList = ref([]) // 地区列表
  202. const formData = ref({
  203. contactNextTime: undefined,
  204. mobile: undefined,
  205. telephone: undefined,
  206. email: undefined,
  207. customerId: undefined,
  208. customerName: undefined,
  209. detailAddress: undefined,
  210. remark: undefined,
  211. ownerUserId: undefined,
  212. lastTime: undefined,
  213. id: undefined,
  214. parentId: undefined,
  215. name: undefined,
  216. post: undefined,
  217. qq: undefined,
  218. wechat: undefined,
  219. sex: undefined,
  220. master: false,
  221. areaId: undefined
  222. })
  223. const formRules = reactive({
  224. name: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
  225. customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
  226. ownerUserId: [{ required: true, message: '负责人不能为空', trigger: 'blur' }]
  227. })
  228. const formRef = ref() // 表单 Ref
  229. const ownerUserList = ref<any[]>([])
  230. const userList = ref<UserApi.UserVO[]>([]) // 用户列表
  231. // TODO 芋艿:统一的客户选择面板
  232. const customerList = ref<CustomerApi.CustomerVO[]>([]) // 客户列表
  233. const allContactList = ref<ContactApi.ContactVO[]>([]) // 所有联系人列表
  234. /** 打开弹窗 */
  235. const open = async (type: string, id?: number) => {
  236. dialogVisible.value = true
  237. dialogTitle.value = t('action.' + type)
  238. formType.value = type
  239. resetForm()
  240. allContactList.value = await ContactApi.getSimpleContactList()
  241. userList.value = await UserApi.getSimpleUserList()
  242. customerList.value = await CustomerApi.queryAllList()
  243. areaList.value = await AreaApi.getAreaTree()
  244. // 修改时,设置数据
  245. if (id) {
  246. formLoading.value = true
  247. try {
  248. formData.value = await ContactApi.getContact(id)
  249. } finally {
  250. formLoading.value = false
  251. }
  252. }
  253. }
  254. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  255. /** 提交表单 */
  256. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  257. const submitForm = async () => {
  258. // owerSelectValue(ownerUserList)
  259. // 校验表单
  260. if (!formRef) return
  261. const valid = await formRef.value.validate()
  262. if (!valid) return
  263. // 提交请求
  264. formLoading.value = true
  265. try {
  266. const data = formData.value as unknown as ContactApi.ContactVO
  267. if (formType.value === 'create') {
  268. await ContactApi.createContact(data)
  269. message.success(t('common.createSuccess'))
  270. } else {
  271. await ContactApi.updateContact(data)
  272. message.success(t('common.updateSuccess'))
  273. }
  274. dialogVisible.value = false
  275. // 发送操作成功的事件
  276. emit('success')
  277. } finally {
  278. formLoading.value = false
  279. }
  280. }
  281. /** 重置表单 */
  282. const resetForm = () => {
  283. // TODO zyna:ide 告警,看看怎么去掉哈;
  284. formData.value = {
  285. contactNextTime: undefined,
  286. mobile: undefined,
  287. telephone: undefined,
  288. email: undefined,
  289. customerId: undefined,
  290. detailAddress: undefined,
  291. remark: undefined,
  292. ownerUserId: undefined,
  293. lastTime: undefined,
  294. id: undefined,
  295. parentId: undefined,
  296. name: undefined,
  297. post: undefined,
  298. qq: undefined,
  299. wechat: undefined,
  300. sex: undefined,
  301. master: false
  302. }
  303. formRef.value?.resetFields()
  304. ownerUserList.value = []
  305. }
  306. </script>