addFollowDialog22.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="container">
  3. <!-- 单据弹窗 -->
  4. <ele-modal
  5. :title="title"
  6. :before-close="handleClose"
  7. custom-class="ele-dialog-form long-dialog-form"
  8. :visible.sync="dialogVisible"
  9. :close-on-click-modal="false"
  10. :append-to-body="true"
  11. :maxable="true"
  12. :resizable="true"
  13. width="50%"
  14. >
  15. <el-form
  16. label-width="100px"
  17. ref="form"
  18. :model="form"
  19. :rules="rules"
  20. style="margin-top: 30px; padding-right: 20px"
  21. >
  22. <el-form-item label="客户联系人" prop="linkId">
  23. <el-select
  24. v-model="form.linkId"
  25. multiple
  26. placeholder="请选择"
  27. @change="onchangeLink"
  28. style="width: 100%"
  29. >
  30. <el-option
  31. v-for="item in linkNameOptions"
  32. :key="item.id"
  33. :label="item.linkName"
  34. :value="item.id"
  35. >
  36. </el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="商机名称" prop="opportunityId">
  40. <el-select
  41. clearable
  42. v-model="form.opportunityId"
  43. placeholder="请选择"
  44. style="width: 100%"
  45. @change="onchangeOpportunity"
  46. >
  47. <el-option
  48. v-for="item in opportunityList"
  49. :key="item.id"
  50. :label="item.name"
  51. :value="item.id"
  52. >
  53. </el-option>
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item label="跟进时间" prop="followupTime">
  57. <el-date-picker
  58. v-model="form.followupTime"
  59. value-format="yyyy-MM-dd HH:mm:ss"
  60. placeholder="结束时间"
  61. type="datetime"
  62. style="width: 100%"
  63. class="filter-item"
  64. ></el-date-picker>
  65. </el-form-item>
  66. <el-form-item label="跟进阶段" prop="stageCode">
  67. <DictSelection dictName="商机阶段" clearable v-model="form.stageCode">
  68. </DictSelection>
  69. </el-form-item>
  70. <el-form-item label="跟进内容" prop="content">
  71. <el-input
  72. placeholder="请输入"
  73. type="textarea"
  74. v-model="form.content"
  75. maxlength="500"
  76. ></el-input>
  77. </el-form-item>
  78. <el-form-item label="达成共识" prop="agreement">
  79. <el-input
  80. placeholder="请输入"
  81. type="textarea"
  82. v-model="form.agreement"
  83. maxlength="500"
  84. ></el-input>
  85. </el-form-item>
  86. <el-form-item label="下一步计划" prop="nextPlan">
  87. <el-input
  88. placeholder="请输入"
  89. v-model="form.nextPlan"
  90. type="textarea"
  91. maxlength="300"
  92. ></el-input>
  93. </el-form-item>
  94. <el-form-item prop="files" label="附件">
  95. <!-- <fileUpload
  96. v-model="form.files"
  97. module="main"
  98. :showLib="false"
  99. :limit="5"
  100. /> -->
  101. <fileMain v-model="form.files"></fileMain>
  102. </el-form-item>
  103. </el-form>
  104. <div slot="footer" class="dialog-footer">
  105. <el-button size="small" @click="handleClose">关 闭</el-button>
  106. <el-button size="small" @click="sumbit" type="primary" v-click-once
  107. >确 认</el-button
  108. >
  109. </div>
  110. </ele-modal>
  111. </div>
  112. </template>
  113. <script>
  114. import dictMixins from '@/mixins/dictMixins';
  115. import { copyObj } from '@/utils/util';
  116. import { deepClone } from '@/utils/index';
  117. // import fileMain from '@/components/upload/fileUpload';
  118. import { getTableList } from '@/api/saleManage/businessOpportunity';
  119. import {
  120. UpdateInformation,
  121. addInformation,
  122. getcontactlink
  123. } from '@/api/saleManage/businessFollow';
  124. export default {
  125. mixins: [dictMixins],
  126. components: {
  127. // fileUpload
  128. },
  129. data() {
  130. let formDef = {
  131. agreement: '',
  132. contactId: '',
  133. content: '',
  134. followupTime: '',
  135. linkId: '',
  136. linkName: '',
  137. nextPlan: '',
  138. opportunityId: '',
  139. stageCode: '',
  140. files: []
  141. };
  142. return {
  143. dialogVisible: false,
  144. currentDetail: {}, //选择的客户信息
  145. linkNameOptions: [],
  146. title: '',
  147. row: {},
  148. activeName: 'base',
  149. formDef,
  150. form: copyObj(formDef),
  151. rules: {
  152. linkId: [
  153. { required: true, message: '选择客户联系人', trigger: 'change' }
  154. ],
  155. content: [
  156. { required: true, message: '请输入跟进内容', trigger: 'blur' }
  157. ],
  158. followupTime: [
  159. { required: true, message: '请选择跟进时间', trigger: 'change' }
  160. ],
  161. stageCode: [
  162. { required: true, message: '请选择跟进阶段', trigger: 'change' }
  163. ],
  164. linkName: [
  165. {
  166. required: true,
  167. message: '请选择客户联系人名称',
  168. trigger: 'change'
  169. }
  170. ]
  171. },
  172. // 提交状态
  173. loading: false,
  174. // 是否是修改
  175. isUpdate: false,
  176. opportunityList: []
  177. };
  178. },
  179. created() {},
  180. methods: {
  181. //更改弹框状态
  182. async open(type, row, currentDetail) {
  183. console.log(row, currentDetail);
  184. this.title = type === 'add' ? '新增' : '修改';
  185. this.currentDetail = currentDetail;
  186. this.row = copyObj(row);
  187. this.dialogVisible = true;
  188. this.getInfo();
  189. if (type == 'add') {
  190. this.isUpdate = false;
  191. } else {
  192. this.isUpdate = true;
  193. this.row.linkId =
  194. (this.row.linkId && this.row.linkId.split(',')) || [];
  195. this.form = this.row;
  196. this.getOpportunityList();
  197. }
  198. },
  199. async getOpportunityList() {
  200. let res = await getTableList({
  201. pageNum: 1,
  202. size: 10,
  203. contactId: this.row.contactId
  204. });
  205. console.log(res);
  206. this.opportunityList = res.list;
  207. },
  208. //表单验证
  209. getValidate() {
  210. return new Promise((resolve, reject) => {
  211. this.$refs.form.validate((valid) => {
  212. if (!valid) {
  213. reject(false);
  214. } else {
  215. resolve(true);
  216. }
  217. });
  218. });
  219. },
  220. //初始数据
  221. async getInfo() {
  222. const data = await getcontactlink({
  223. contactId: this.currentDetail?.contactId
  224. });
  225. if (data && data?.length) {
  226. this.linkNameOptions = data;
  227. }
  228. },
  229. //选择下拉框
  230. onchangeLink(selectedOptions) {
  231. const selectedLabels = selectedOptions
  232. .map((optionId) => {
  233. const option = this.linkNameOptions.find(
  234. (opt) => opt.id === optionId
  235. );
  236. return option ? option.linkName : '';
  237. })
  238. .join(',');
  239. this.form.linkName = selectedLabels;
  240. },
  241. onchangeOpportunity(value) {
  242. if (!value) {
  243. this.form.opportunityName = '';
  244. return;
  245. }
  246. this.form.opportunityName = this.opportunityList.find(
  247. (item) => item.id === value
  248. )?.name;
  249. },
  250. //保存
  251. async sumbit() {
  252. try {
  253. await this.getValidate();
  254. // 表单验证通过,执行保存操作
  255. this.loading = true;
  256. if (!this.isUpdate) {
  257. delete this.form.id;
  258. }
  259. let _stageName = this.getDictValue('商机阶段', this.form.stageCode);
  260. let params = deepClone(this.form);
  261. let { contactId } = this.currentDetail;
  262. params = Object.assign({}, params, {
  263. contactId: contactId,
  264. linkId: params?.linkId?.join(',') || '',
  265. stageName: _stageName,
  266. files: this.form.files || []
  267. });
  268. console.log(params);
  269. if (this.isUpdate) {
  270. UpdateInformation(params)
  271. .then((res) => {
  272. this.loading = false;
  273. this.$message.success('修改成功');
  274. this.cancel();
  275. this.$emit('done');
  276. })
  277. .catch((e) => {
  278. //this.loading = false;
  279. });
  280. } else {
  281. addInformation(params)
  282. .then((res) => {
  283. this.loading = false;
  284. this.$message.success('新增成功');
  285. this.cancel();
  286. this.$emit('done');
  287. })
  288. .catch((e) => {
  289. //this.loading = false;
  290. });
  291. }
  292. } catch (error) {
  293. console.log(error);
  294. // 表单验证未通过,不执行保存操作
  295. }
  296. },
  297. cancel() {
  298. this.$nextTick(() => {
  299. // 关闭后,销毁所有的表单数据
  300. this.$refs['form'] && this.$refs['form'].resetFields();
  301. (this.form = copyObj(this.formDef)), (this.dialogVisible = false);
  302. });
  303. },
  304. handleClose() {
  305. this.cancel();
  306. }
  307. }
  308. };
  309. </script>
  310. <style lang="scss" scoped>
  311. .container {
  312. padding: 10px 0;
  313. }
  314. </style>