FollowAdd.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogFormVisible" @close="close">
  3. <el-form ref="form" label-width="96px" :model="form" :rules="rules">
  4. <el-row>
  5. <el-col :span="12">
  6. <el-form-item label="跟进时间" prop="followDate">
  7. <el-date-picker
  8. v-model="form.followDate"
  9. :picker-options="{
  10. // 时间不能大于当前时间
  11. disabledDate: (time) => {
  12. return time.getTime() > Date.now()
  13. },
  14. }"
  15. placeholder="选择日期"
  16. style="width: 100%"
  17. type="datetime"
  18. value-format="yyyy-MM-dd HH:mm:ss" />
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="12">
  22. <el-form-item label="跟进方式" prop="followType">
  23. <el-select v-model="form.followType" placeholder="请选择" style="width: 100%">
  24. <el-option v-for="item in followTypeOptions" :key="item.key" :label="item.value" :value="item.key" />
  25. </el-select>
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="24">
  29. <el-form-item label="本次跟进内容" prop="followContent">
  30. <el-input
  31. v-model="form.followContent"
  32. placeholder="请输入本次跟进内容"
  33. rows="4"
  34. show-word-limit
  35. type="textarea" />
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="24">
  39. <el-form-item label="达成效果" prop="effect">
  40. <el-input v-model="form.effect" placeholder="请输入达成效果" rows="4" show-word-limit type="textarea" />
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="24">
  44. <el-form-item label="问题或困难" prop="issue">
  45. <el-input v-model="form.issue" placeholder="请输入问题或困难" rows="4" show-word-limit type="textarea" />
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="24">
  49. <el-form-item label="下一步跟进计划和目标" prop="furtherPlan">
  50. <el-input
  51. v-model="form.furtherPlan"
  52. placeholder="请输入下一步跟进计划和目标"
  53. rows="5"
  54. show-word-limit
  55. type="textarea" />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item label="联系人" prop="contactsName">
  60. <el-input v-model="form.contactsName" readonly suffix-icon="el-icon-search" @focus="handleSelectContact" />
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="12">
  64. <el-form-item label="上传附件" prop="files">
  65. <el-upload
  66. ref="uploadRef"
  67. action="#"
  68. :before-upload="
  69. (file) => {
  70. return beforeAvatarUpload(file)
  71. }
  72. "
  73. :file-list="fileList"
  74. :http-request="uploadrequest">
  75. <el-button size="mini" type="primary">点击上传</el-button>
  76. </el-upload>
  77. </el-form-item>
  78. </el-col>
  79. </el-row>
  80. <el-row>
  81. <el-col :span="12">
  82. <el-form-item label="渠道" prop="distName">
  83. <el-input
  84. v-model="form.distName"
  85. placeholder="请选择渠道"
  86. readonly
  87. suffix-icon="el-icon-search"
  88. @focus="openDistributor" />
  89. </el-form-item>
  90. </el-col>
  91. <el-col :span="12">
  92. <el-form-item label="协访人员" prop="visitorName">
  93. <el-input v-model="form.visitorName" placeholder="请输入协访人员" />
  94. </el-form-item>
  95. </el-col>
  96. <!-- <el-col :span="12">-->
  97. <!-- <el-form-item label="提醒对象" prop="reminders">-->
  98. <!-- <el-input v-model="form.reminders" />-->
  99. <!-- </el-form-item>-->
  100. <!-- </el-col>-->
  101. <!-- <el-col :span="12">-->
  102. <!-- <el-form-item label="下次联系时间" prop="nextTime">-->
  103. <!-- <el-date-picker v-model="form.nextTime" placeholder="选择日期" style="width: 100%" type="datetime" />-->
  104. <!-- </el-form-item>-->
  105. <!-- </el-col>-->
  106. <!-- <el-col :span="24">-->
  107. <!-- <el-form-item label="备注" prop="remark">-->
  108. <!-- <el-input v-model="form.remark" placeholder="请输入备注信息" rows="5" show-word-limit type="textarea" />-->
  109. <!-- </el-form-item>-->
  110. <!-- </el-col>-->
  111. </el-row>
  112. </el-form>
  113. <div slot="footer" class="dialog-footer">
  114. <el-button @click="close">取 消</el-button>
  115. <el-button :loading="loading" type="primary" @click="save">确 定</el-button>
  116. </div>
  117. <!-- 选择项目联系人弹窗 -->
  118. <select-business-contact ref="selectBusinessContact" :query-params="queryContact" @save="selectContact" />
  119. <!-- 选择客户联系人弹窗 -->
  120. <select-customer-contact
  121. ref="selectCustomerContact"
  122. :default-customer="customerInfo"
  123. :query-params="queryContact"
  124. @save="selectContact" />
  125. <SelectDist ref="selectDist" :multiple="false" @save="getDistributor" />
  126. <select-distributor
  127. ref="selectDistributor"
  128. :query-params="queryContact"
  129. :title="distrTitle"
  130. @save="selectContact" />
  131. <select-user ref="selectUser" :query-params="queryContact" @save="selectContact" />
  132. </el-dialog>
  133. </template>
  134. <script>
  135. import axios from 'axios'
  136. import to from 'await-to-js'
  137. import followApi from '@/api/customer/follow'
  138. import SelectDistributor from '@/components/select/SelectDistributorContact'
  139. import SelectDist from '@/components/select/SelectDistributor'
  140. import SelectUser from '@/components/select/SelectUser'
  141. import asyncUploadFile from '@/utils/uploadajax'
  142. import SelectCustomerContact from '@/components/select/SelectCustomerContact'
  143. import SelectBusinessContact from '@/components/select/SelectBusinessContact'
  144. export default {
  145. name: 'FollowAdd',
  146. components: {
  147. SelectCustomerContact,
  148. SelectBusinessContact,
  149. SelectDistributor,
  150. SelectUser,
  151. SelectDist,
  152. },
  153. data() {
  154. return {
  155. distrTitle: '',
  156. loading: false,
  157. form: {
  158. followType: '',
  159. followDate: '',
  160. followContentType: '',
  161. effect: '',
  162. followContent: '',
  163. issue: '',
  164. furtherPlan: '',
  165. targetId: '',
  166. targetName: '',
  167. targetType: '',
  168. custId: null,
  169. custName: null,
  170. contactType: '',
  171. contactsId: '',
  172. contactsName: '',
  173. reminders: '',
  174. nextTime: '',
  175. remark: '',
  176. supportName: '',
  177. distId: null,
  178. distName: '',
  179. visitorName: '',
  180. files: [],
  181. },
  182. rules: {
  183. followType: [{ required: true, trigger: 'blur', message: '请输入跟进方式' }],
  184. followDate: [{ required: true, trigger: 'blur', message: '请输入跟进时间' }],
  185. followContentType: [{ required: true, trigger: 'blur', message: '请输入跟进内容类型' }],
  186. followContent: [{ required: true, trigger: 'blur', message: '请输入本次跟进内容' }],
  187. effect: [{ required: true, trigger: 'blur', message: '请输入达成效果' }],
  188. issue: [{ required: true, trigger: 'blur', message: '请输入问题或困难' }],
  189. furtherPlan: [{ required: true, trigger: 'blur', message: '请输入下一步跟进计划和目标' }],
  190. targetId: [{ required: true, trigger: 'blur', message: '请选择跟进对象' }],
  191. targetName: [{ required: true, trigger: 'blur', message: '跟进对象不能为空' }],
  192. targetType: [{ required: true, trigger: 'blur', message: '跟进对象类型不能为空' }],
  193. custId: [{ required: true, trigger: 'blur', message: '请选择关联客户' }],
  194. custName: [{ required: true, trigger: 'blur', message: '客户名称不能为空' }],
  195. contactsId: [{ required: true, trigger: 'blur', message: '请选择关联联系人' }],
  196. contactsName: [{ required: true, trigger: 'blur', message: '联系人姓名不能为空' }],
  197. supportName: [{ required: true, trigger: 'blur', message: '总部支持人员不能为空' }],
  198. },
  199. title: '',
  200. dialogFormVisible: false,
  201. fileList: [],
  202. fileSettings: {
  203. // 文件配置信息
  204. fileSize: 52428800,
  205. fileTypes: '.pdf,.doc,.docx,.zip,.xls,.xlsx,.rar,.jpg,.jpeg,.gif,.png,.jfif,.txt',
  206. pictureSize: 52428800,
  207. pictureTypes: '.jpg,.jpeg,.gif,.png,.jfif,.txt',
  208. types: '.pdf,.doc,.docx,.zip,.xls,.xlsx,.rar,.jpg,.jpeg,.gif,.png,.jfif,.mp4,.txt',
  209. videoSize: 104857600,
  210. videoType: '.mp4',
  211. },
  212. queryContact: {},
  213. customerInfo: {},
  214. followTypeOptions: [],
  215. followContentTypeOptions: [],
  216. }
  217. },
  218. watch: {},
  219. created() {},
  220. methods: {
  221. getOptions() {
  222. Promise.all([this.getDicts('plat_follow_type'), this.getDicts('plat_follow_content_type')]).then(
  223. ([followType, followContentType]) => {
  224. this.followTypeOptions = followType.data.values || []
  225. this.followContentTypeOptions = followContentType.data.values || []
  226. }
  227. )
  228. },
  229. handleSelectContact() {
  230. console.log(this.form.targetType)
  231. if (this.form.targetType == '10') {
  232. if (!this.queryContact.custId) {
  233. this.$message.warning('请先选择客户')
  234. return
  235. }
  236. this.$refs.selectCustomerContact.open()
  237. } else if (this.form.targetType == '20') {
  238. if (!this.queryContact.custId) {
  239. this.$message.warning('请先选择客户')
  240. return
  241. }
  242. if (!this.queryContact.busId) {
  243. this.$message.warning('请先选择项目')
  244. return
  245. }
  246. this.$refs.selectBusinessContact.open()
  247. } else if (this.form.targetType == '50') {
  248. this.$refs.selectDistributor.open()
  249. } else if (this.form.targetType == '70') {
  250. this.$refs.selectUser.open()
  251. } else {
  252. if (!this.queryContact.custId) {
  253. this.$message.warning('请先选择客户')
  254. return
  255. }
  256. this.$refs.selectCustomerContact.open()
  257. }
  258. },
  259. selectContact(val) {
  260. if (val && val.length > 0) {
  261. if (this.form.targetType == '20') {
  262. this.form.contactType = val[0].contactType
  263. this.form.contactsName = val.map((item) => item.cuctName).join()
  264. } else if (this.form.targetType == '50') {
  265. this.form.contactsName = val.map((item) => item.name).join()
  266. } else if (this.form.targetType == '70') {
  267. this.form.contactsName = val.map((item) => item.nickName).join()
  268. } else {
  269. this.form.contactsName = val.map((item) => item.cuctName).join()
  270. }
  271. this.form.contactsId = val[0].id
  272. }
  273. console.log(this.form)
  274. },
  275. showEdit(row, title = null) {
  276. this.getOptions()
  277. this.title = '添加跟进记录'
  278. this.form = Object.assign(this.form, row)
  279. console.log(this.form)
  280. if (this.form.targetType == '10' || this.form.targetType == '20' || this.form.targetType == '60') {
  281. if (this.form.targetType == '20') {
  282. this.queryContact.busId = this.form.targetId
  283. }
  284. this.queryContact.custId = this.form.custId
  285. this.customerInfo = {
  286. custId: this.form.custId,
  287. custName: this.form.custName,
  288. }
  289. } else if (this.form.targetType == '50') {
  290. this.queryContact.distId = this.form.targetId
  291. } else if (this.form.targetType == '70') {
  292. this.queryContact.distId = this.form.targetId
  293. this.form.custId = null
  294. this.form.custName = null
  295. }
  296. this.distrTitle = title
  297. this.dialogFormVisible = true
  298. },
  299. close() {
  300. this.$refs['form'].resetFields()
  301. this.form = this.$options.data().form
  302. this.fileList = []
  303. this.dialogFormVisible = false
  304. this.loading = false
  305. },
  306. save() {
  307. this.$refs['form'].validate(async (valid) => {
  308. if (valid) {
  309. this.loading = true
  310. const [err, res] = await to(followApi.addFollowUp(this.form))
  311. this.loading = false
  312. if (err) {
  313. this.$baseMessage(res.msg, 'error')
  314. } else {
  315. this.$baseMessage(res.msg, 'success')
  316. }
  317. this.$emit('fetch-data')
  318. this.close()
  319. } else {
  320. return false
  321. }
  322. })
  323. },
  324. // 打开选择经销商
  325. openDistributor() {
  326. this.$refs.selectDist.open()
  327. },
  328. // 关闭经销商获取经销商信息
  329. getDistributor(data) {
  330. let distributor = data[0] || null
  331. if (!distributor) return
  332. this.form.distName = distributor.distName
  333. this.form.distId = distributor.id
  334. },
  335. // 上传图片
  336. beforeAvatarUpload(file) {
  337. let flag1 = file.size < this.fileSettings.fileSize
  338. if (!flag1) {
  339. this.$message.warning('文件过大,请重新选择!')
  340. return false
  341. }
  342. let flag2 = this.fileSettings.fileTypes.split(',').includes('.' + file.name.split('.').pop())
  343. if (!flag2) {
  344. this.$message.warning('文件类型不符合,请重新选择!')
  345. return false
  346. }
  347. return true
  348. },
  349. // 上传
  350. uploadrequest(option) {
  351. let _this = this
  352. let url = process.env.VUE_APP_UPLOAD_WEED
  353. axios
  354. .post(url)
  355. .then(function (res) {
  356. if (res.data && res.data.fid && res.data.fid !== '') {
  357. option.action = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}`
  358. let file_name = option.file.name
  359. let index = file_name.lastIndexOf('.')
  360. let file_extend = ''
  361. if (index > 0) {
  362. // 截取名称中的扩展名
  363. file_extend = file_name.substr(index + 1)
  364. }
  365. let uploadform = {
  366. fileName: file_name, // 资料名称
  367. fileUrl: `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}`, // 资料存储url
  368. size: option.file.size.toString(), // 资料大小
  369. fileType: file_extend, // 资料文件类型
  370. }
  371. asyncUploadFile(option).then(() => {
  372. _this.form.files.push(uploadform)
  373. })
  374. } else {
  375. _this.$message({
  376. type: 'warning',
  377. message: '未上传成功!请刷新界面重新上传!',
  378. })
  379. }
  380. })
  381. .catch(function () {
  382. _this.$message({
  383. type: 'warning',
  384. message: '未上传成功!请重新上传!',
  385. })
  386. })
  387. },
  388. },
  389. }
  390. </script>