addFollowDialog.vue 7.8 KB

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