addFollowDialog.vue 7.9 KB

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