addOrEditCustomer.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  4. <!-- <el-form-item label="客户编码" prop="customerCode">
  5. <el-input v-model="form.customerCode" :disabled="form.customerId!=null" placeholder="请输入客户编码" />
  6. </el-form-item> -->
  7. <el-form-item label="客户名称" prop="customerName">
  8. <el-input v-model="form.customerName" placeholder="请输入客户名称" />
  9. </el-form-item>
  10. <el-form-item label="手机" prop="mobile">
  11. <el-input maxlength="11" v-model="form.mobile" placeholder="请输入手机" />
  12. </el-form-item>
  13. <el-form-item label="性别" prop="sex">
  14. <el-radio-group v-model="form.sex">
  15. <el-radio :label="item.dictValue" v-for="item in sexOptions" >{{item.dictLabel}}</el-radio>
  16. </el-radio-group>
  17. </el-form-item>
  18. <el-form-item label="微信号" prop="weixin">
  19. <el-input v-model="form.weixin" placeholder="请输入微信号" />
  20. </el-form-item>
  21. <el-form-item label="所在地区" prop="address">
  22. <el-cascader
  23. ref="citySelect"
  24. v-model="cityIds"
  25. :options="citys"
  26. @change="handleCityChange"></el-cascader>
  27. </el-form-item>
  28. <el-form-item label="详细地址" prop="detailAddress">
  29. <el-input v-model="form.detailAddress" placeholder="请输入详细地址" />
  30. </el-form-item>
  31. <el-form-item label="客户类型" prop="customerLevel">
  32. <el-select v-model="form.customerLevel" placeholder="请选择客户类型" clearable size="small">
  33. <el-option
  34. v-for="item in customerLevelOptions"
  35. :key="item.dictValue"
  36. :label="item.dictLabel"
  37. :value="item.dictValue"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. <!-- <el-form-item label="客户状态">
  42. <el-radio-group v-model="form.status">
  43. <el-radio :label="item.dictValue" v-for="item in statusOptions">{{item.dictLabel}}</el-radio>
  44. </el-radio-group>
  45. </el-form-item> -->
  46. <el-form-item label="客户来源" prop="source">
  47. <el-select v-model="form.source" placeholder="请选择客户来源" clearable size="small">
  48. <el-option
  49. v-for="item in sourceOptions"
  50. :key="item.dictValue"
  51. :label="item.dictLabel"
  52. :value="item.dictValue"
  53. />
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item label="标签" prop="tags">
  57. <el-tag
  58. :key="tag"
  59. v-for="tag in tags"
  60. closable
  61. :disable-transitions="false"
  62. @close="handleClose(tag)">
  63. {{tag}}
  64. </el-tag>
  65. <el-input
  66. class="input-new-tag"
  67. v-if="inputVisible"
  68. v-model="inputValue"
  69. ref="saveTagInput"
  70. size="small"
  71. @keyup.enter.native="handleInputConfirm"
  72. @blur="handleInputConfirm"
  73. >
  74. </el-input>
  75. <el-button v-else class="button-new-tag" size="small" @click="showInput">添加标签+</el-button>
  76. <el-select v-model="tagId" @change="tagsChange" style="width:140px;margin-left: 5px;" placeholder="请选择客户标签" clearable size="small">
  77. <el-option
  78. v-for="item in tagsOptions"
  79. :key="item.dictValue"
  80. :label="item.dictLabel"
  81. :value="item.dictValue"
  82. />
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="进线日期" prop="registerDate">
  86. <el-date-picker
  87. value-format="yyyy-MM-dd"
  88. v-model="form.registerDate"
  89. type="date"
  90. placeholder="请选择进线日期">
  91. </el-date-picker>
  92. </el-form-item>
  93. <el-form-item label="进线链接" prop="registerLinkUrl">
  94. <el-input v-model="form.registerLinkUrl" placeholder="请输入进线链接" />
  95. </el-form-item>
  96. <el-form-item label="进线客户详情" prop="registerDesc">
  97. <el-input v-model="form.registerDesc" placeholder="请输入进线客户详情" />
  98. </el-form-item>
  99. <el-form-item label="进线填写时间" prop="registerSubmitTime">
  100. <el-date-picker
  101. value-format="yyyy-MM-dd HH:mm:ss"
  102. v-model="form.registerSubmitTime"
  103. type="datetime"
  104. placeholder="请选择进线填写时间">
  105. </el-date-picker>
  106. </el-form-item>
  107. <el-form-item label="进线方式" prop="registerType">
  108. <el-input v-model="form.registerType" placeholder="请输入进线方式" />
  109. </el-form-item>
  110. <el-form-item label="来源渠道编码" prop="sourceCode">
  111. <el-input v-model="form.sourceCode" placeholder="请输入来源渠道编码" />
  112. </el-form-item>
  113. <el-form-item label="推线时间" prop="pushTime">
  114. <el-input v-model="form.pushTime" placeholder="请输入推线时间" />
  115. </el-form-item>
  116. <el-form-item label="推线编码" prop="pushCode">
  117. <el-input v-model="form.pushCode" placeholder="请输入推线编码" />
  118. </el-form-item>
  119. <el-form-item :label="ext.name" v-for="ext in exts" >
  120. <el-input v-model="ext.value" />
  121. </el-form-item>
  122. <el-form-item label="备注" prop="remark">
  123. <el-input :rows="2" v-model="form.remark" type="textarea" placeholder="请输入内容" />
  124. </el-form-item>
  125. </el-form>
  126. <div class="footer">
  127. <el-button type="primary" @click="submitForm">确 定</el-button>
  128. </div>
  129. </div>
  130. </template>
  131. <script>
  132. import { listCustomerExt } from "@/api/crm/customerExt";
  133. import { updateCustomer,addCustomer,addMyCustomer,getCustomerDetails } from "@/api/crm/customer";
  134. import {getCitys} from "@/api/store/city";
  135. import {customerLevelOptions} from "@/api/crm/customerLevel";
  136. export default {
  137. name: "remark",
  138. data() {
  139. return {
  140. addType:1,//添加类型 1线索客户 2我的客户
  141. tagId:null,
  142. tagsOptions:[],
  143. cityIds:[],
  144. citys:[],
  145. tags:[],
  146. inputVisible: false,
  147. inputValue: '',
  148. statusOptions:[],
  149. typeOptions:[],
  150. sourceOptions:[],
  151. sexOptions:[],
  152. customerExts:[],
  153. // 表单参数
  154. form: {
  155. province:null,
  156. city:null,
  157. district:null,
  158. customerLevel: null
  159. },
  160. exts:[],
  161. // 表单校验
  162. rules: {
  163. // customerName: [
  164. // { required: true, message: "客户名称不能为空", trigger: "blur" }
  165. // ],
  166. mobile: [
  167. { required: true, message: "手机号不能为空", trigger: "blur" }
  168. ],
  169. source: [
  170. { required: true, message: "客户来源不能为空", trigger: "blur" }
  171. ],
  172. },
  173. customerLevelOptions: []
  174. };
  175. },
  176. created() {
  177. this.getDicts("crm_customer_source").then((response) => {
  178. this.sourceOptions = response.data;
  179. });
  180. this.getDicts("common_sex").then((response) => {
  181. this.sexOptions = response.data;
  182. });
  183. this.getDicts("crm_customer_tag").then((response) => {
  184. this.tagsOptions = response.data;
  185. });
  186. this.getDicts("crm_customer_status").then((response) => {
  187. this.statusOptions = response.data;
  188. });
  189. this.getDicts("crm_customer_type").then((response) => {
  190. this.typeOptions = response.data;
  191. });
  192. this.getCitys()
  193. this.getCustomerLevelOptions()
  194. },
  195. methods: {
  196. getCustomerLevelOptions(){
  197. customerLevelOptions({status: 0}).then((response) => {
  198. this.customerLevelOptions = response.data;
  199. });
  200. },
  201. tagsChange(e){
  202. var item=this.tagsOptions.find(val => val.dictValue === e);
  203. console.log(item);
  204. this.tags.push(item.dictLabel);
  205. this.form.tags=this.tags.toString();
  206. },
  207. closeTag(){
  208. this.addTag.open=false;
  209. this.getDetails(this.customerId)
  210. },
  211. handleAddTag(){
  212. this.addTag.open=true;
  213. var that=this;
  214. setTimeout(() => {
  215. that.$refs.tag.reset(this.item);
  216. }, 500);
  217. },
  218. handleCityChange(value) {
  219. console.log(value);
  220. var nodes=this.$refs.citySelect.getCheckedNodes();
  221. this.form.address=nodes[0].pathLabels[0]+"-"+nodes[0].pathLabels[1]+"-"+nodes[0].pathLabels[2];
  222. this.form.cityIds=value.toString();
  223. console.log(this.form.address);
  224. },
  225. getCitys(){
  226. getCitys().then(res => {
  227. this.loading = false;
  228. this.citys=res.data;
  229. })
  230. },
  231. handleClose(tag) {
  232. this.tags.splice(this.tags.indexOf(tag), 1);
  233. this.form.tags=this.tags.toString();
  234. },
  235. showInput() {
  236. this.inputVisible = true;
  237. this.$nextTick(_ => {
  238. this.$refs.saveTagInput.focus();
  239. });
  240. },
  241. handleInputConfirm() {
  242. let inputValue = this.inputValue;
  243. if (inputValue) {
  244. this.tags.push(inputValue);
  245. }
  246. this.inputVisible = false;
  247. this.inputValue = '';
  248. this.form.tags=this.tags.toString();
  249. },
  250. // 表单重置
  251. reset() {
  252. this.form = {
  253. customerId: null,
  254. customerCode: null,
  255. customerName: null,
  256. mobile: null,
  257. sex: null,
  258. weixin: null,
  259. remark: null,
  260. userId: null,
  261. createUserId: null,
  262. receiveUserId: null,
  263. customerUserId: null,
  264. address: null,
  265. location: null,
  266. detailAddress: null,
  267. lng: null,
  268. lat: null,
  269. createTime: null,
  270. updateTime: null,
  271. status: 0,
  272. isReceive: null,
  273. deptId: null,
  274. isDel: null,
  275. customerType: null,
  276. receiveTime: null,
  277. poolTime: null,
  278. companyId: null,
  279. isLine: null,
  280. source: null,
  281. tags: null,
  282. customerLevel: null
  283. };
  284. this.exts=[];
  285. this.tags=[];
  286. this.cityIds=[];
  287. this.resetForm("form");
  288. },
  289. handleAdd(addType) {
  290. this.addType=addType;
  291. this.reset();
  292. console.log(this.customerExts)
  293. var data={status:1}
  294. listCustomerExt(data).then(response => {
  295. this.customerExts = response.data;
  296. this.customerExts.forEach(element => {
  297. var data={extId:element.extId,name:element.name,value:""};
  298. this.exts.push(data)
  299. });
  300. });
  301. console.log(this.exts)
  302. },
  303. /** 修改按钮操作 */
  304. handleUpdate(customerId) {
  305. this.reset();
  306. var that=this;
  307. var data={customerId:customerId}
  308. getCustomerDetails(data).then(response => {
  309. this.form = response.customer;
  310. if(this.form.status!=null){
  311. this.form.status = this.form.status.toString();
  312. }
  313. if(this.form.customerType!=null){
  314. this.form.customerType = this.form.customerType.toString();
  315. }
  316. if(this.form.sex!=null){
  317. this.form.sex = this.form.sex.toString();
  318. }
  319. if(this.form.source!=null){
  320. this.form.source = this.form.source.toString();
  321. }
  322. if(this.form.tags!=null){
  323. this.tags = this.form.tags.split(",")
  324. }
  325. if(this.form.cityIds!=null){
  326. var ids=this.form.cityIds.split(",");
  327. this.cityIds=[];
  328. ids.forEach(element => {
  329. var id=parseInt(element);
  330. that.cityIds.push(id)
  331. });
  332. }
  333. listCustomerExt(data).then(response => {
  334. this.customerExts = response.data;
  335. this.customerExts.forEach(element => {
  336. var data={extId:element.extId,name:element.name,value:""};
  337. this.exts.push(data)
  338. });
  339. if(this.form.extJson!=null){
  340. var extList=JSON.parse(this.form.extJson);
  341. that.exts.forEach(item => {
  342. extList.forEach(element => {
  343. if(item.extId==element.extId){
  344. item.value=element.value
  345. }
  346. });
  347. });
  348. }
  349. });
  350. this.open = true;
  351. this.title = "修改客户";
  352. });
  353. },
  354. /** 提交按钮 */
  355. submitForm() {
  356. this.$refs["form"].validate(valid => {
  357. if (valid) {
  358. if (this.form.customerId != null) {
  359. this.form.extJson=JSON.stringify(this.exts);
  360. updateCustomer(this.form).then(response => {
  361. if (response.code === 200) {
  362. this.msgSuccess("操作成功");
  363. this.$emit('close');
  364. }
  365. });
  366. } else {
  367. this.form.extJson=JSON.stringify(this.exts);
  368. if(this.addType==1){
  369. addCustomer(this.form).then(response => {
  370. if (response.code === 200) {
  371. this.msgSuccess("操作成功");
  372. this.$emit('close');
  373. }
  374. });
  375. }
  376. else if(this.addType==2){
  377. addMyCustomer(this.form).then(response => {
  378. if (response.code === 200) {
  379. this.msgSuccess("操作成功");
  380. this.$emit('close');
  381. }
  382. });
  383. }
  384. }
  385. }
  386. });
  387. },
  388. }
  389. };
  390. </script>
  391. <style lang="scss" scoped>
  392. .contents{
  393. height: 100%;
  394. background-color: #fff;
  395. padding: 20px;
  396. }
  397. .footer{
  398. display: flex;
  399. align-items: center;
  400. justify-content: flex-end;
  401. }
  402. </style>