| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- loading: false,
- disabled: true,
- showAll: false,
- form: [{
- label: "客户名称",
- error: false,
- errMsg: "",
- type: "text",
- value: "",
- placeholder: "请输入客户名称",
- valueName: "name",
- required: true,
- checking: "base"
- }, {
- label: "手机",
- error: false,
- errMsg: "",
- type: "number",
- value: "",
- placeholder: "请输入手机号码",
- valueName: "phonenumber",
- required: true
- }, {
- label: "性别",
- error: false,
- errMsg: "",
- type: "radio",
- value: "",
- radioList: [{
- id: "男",
- name: "男"
- },
- {
- id: "女",
- name: "女"
- }
- ],
- valueName: "sex",
- required: false,
- checking: "base",
- direction: "horizontal"
- }, {
- label: "生日",
- error: false,
- errMsg: "",
- type: "date",
- value: "",
- placeholder: "请选择生日",
- valueName: "birthday",
- required: false
- }, {
- label: "客户来源",
- error: false,
- errMsg: "",
- type: "radio",
- value: "",
- radioList: [],
- valueName: "source",
- required: true,
- checking: "base"
- }, {
- label: "选择线索",
- error: false,
- errMsg: "",
- type: "route",
- url: "/select/lead/index",
- params: {
- "id": 20221101094502,
- "content": {
- "pageNumber": 1,
- "pageSize": 20,
- "where": {
- "condition": "",
- },
- },
- },
- query: '&radio=true',
- value: "",
- placeholder: "选择线索",
- valueName: "sat_orderclueid",
- required: false,
- interrupt: false
- }, {
- label: "外部订单号",
- error: false,
- errMsg: "",
- type: "text",
- value: "",
- placeholder: "请输入外部订单号",
- valueName: "ext_no",
- required: false,
- checking: "base"
- }, {
- label: "省市县",
- error: false,
- errMsg: "",
- type: "region",
- value: [],
- placeholder: "省,市,县",
- valueName: "region",
- required: true
- }, {
- label: "地址",
- error: false,
- errMsg: "",
- type: "textarea",
- value: "",
- placeholder: "请输入详细地址",
- valueName: "address",
- required: true,
- checking: "base"
- }, {
- label: "小区及门牌号",
- error: false,
- errMsg: "",
- type: "text",
- value: "",
- placeholder: "请输入小区及门牌号",
- valueName: "community",
- required: true,
- checking: "base"
- }, {
- label: "备注",
- error: false,
- errMsg: "",
- type: "textarea",
- value: "",
- placeholder: "请输入备注",
- valueName: "remarks",
- required: false,
- checking: "base"
- }],
- "content": {
- "sa_customersid": "0",
- sat_orderclueid: 0
- }
- },
- onLoad(options) {
- // 检查是否是选择模式
- this.setData({
- selectMode: options.selectMode === 'true'
- });
- // 检查是否是从线索详情页面跳转过来的
- if (options.clueId && options.clueInfo) {
- try {
- const clueInfo = JSON.parse(decodeURIComponent(options.clueInfo));
- let form = this.data.form;
- // 填充线索信息到表单
- form = form.map(v => {
- switch (v.valueName) {
- case "name":
- v.value = clueInfo.name || '';
- break;
- case "phonenumber":
- v.value = clueInfo.phonenumber || '';
- break;
- case "sex":
- v.value = clueInfo.sex || '';
- break;
- case "source":
- // 设置客户来源为线索转化
- v.radioList = [{
- name: '线索转化',
- id: '线索转化'
- }];
- v.disabled = true;
- v.value = '线索转化';
- break;
- case "sat_orderclueid":
- // 禁用选择线索字段
- v.disabled = true;
- v.value = [clueInfo.name, [clueInfo.sat_orderclueid]] || '';
- break;
- case "ext_no":
- v.value = clueInfo.ext_no || '';
- break;
- case "region":
- v.value = clueInfo.province ? [clueInfo.province, clueInfo.city, clueInfo.county] : [];
- break;
- case "address":
- v.value = clueInfo.address || '';
- break;
- case "community":
- v.value = clueInfo.community || '';
- break;
- case "remarks":
- v.value = clueInfo.notes || '';
- break;
- default:
- v.value = v.value;
- break;
- }
- return v
- });
- this.setData({
- "content.sat_orderclueid": [options.clueId, [options.clueId]],
- form
- });
- this.selectComponent("#Form").confirm()
- // 设置页面标题为转化客户
- wx.setNavigationBarTitle({
- title: '转化客户'
- })
- } catch (error) {
- console.error('解析线索信息失败', error);
- this.getCustomerSourceList();
- }
- } else if (options.edit) {
- // 如果是编辑模式,获取客户详情
- let data = _Http.detail;
- let form = this.data.form.filter(v => v.label != '选择线索');
- data.region = data.province ? [data.province, data.city, data.county] : [];
- form = form.map(v => {
- switch (v.valueName) {
- case "source":
- if (data.source == '线索转化') {
- v.radioList = [{
- name: '线索转化',
- id: '线索转化'
- }];
- v.disabled = true;
- } else {
- this.getCustomerSourceList();
- }
- v.value = data[v.valueName] || ''
- break;
- default:
- v.value = data[v.valueName] || ''
- break;
- }
- return v
- })
- this.setData({
- "content.sa_customersid": data.sa_customersid,
- "content.sat_orderclueid": data.sat_orderclueid,
- form
- });
- this.selectComponent("#Form").confirm()
- wx.setNavigationBarTitle({
- title: '编辑客户'
- })
- } else {
- this.getCustomerSourceList();
- }
- },
- // 获取客户来源列表
- getCustomerSourceList() {
- _Http.basic({
- "classname": "sysmanage.develop.optiontype.optiontype",
- "method": "optiontypeselect",
- "content": {
- "pageNumber": 1,
- "pageSize": 1000,
- "typename": "customersource",
- "parameter": {}
- }
- }).then(res => {
- console.log("客户来源列表", res);
- if (res.code == 1 && res.data && res.data.length) {
- let form = this.data.form;
- let sourceField = form.find(v => v.valueName == 'source');
- sourceField.radioList = res.data.map(item => ({
- id: item.value,
- name: item.value
- }));
- this.setData({
- form
- });
- }
- }).catch(err => {
- console.error("获取客户来源列表失败", err);
- });
- },
- submit() {
- this.setData({
- loading: true
- })
- let content = {
- ...this.data.content,
- ...this.selectComponent("#Form").submit()
- };
- // 处理省市县数据
- if (content.region && content.region.length) {
- content.province = content.region[0] || "";
- content.city = content.region[1] || "";
- content.county = content.region[2] || "";
- delete content.region;
- }
- content.sat_orderclueid = content.sat_orderclueid ? content.sat_orderclueid[1][0] : ''
- _Http.basic({
- "id": "2026030916370001",
- content
- }).then(res => {
- this.setData({
- loading: false
- })
- console.log("创建客户", res)
- if (res.code == 1) {
- if (this.data.selectMode) {
- // 选择模式下,创建客户后返回并设置客户信息
- // 这里需要获取客户详情,因为创建成功后只返回了客户ID
- _Http.basic({
- "id": "2026030916272601",
- "content": {
- "sa_customersid": res.data
- }
- }).then(customerRes => {
- if (customerRes.code == 1) {
- const customerInfo = customerRes.data[0];
- // 调用全局回调函数,设置客户信息
- if (getApp().globalData.setCustomer) {
- getApp().globalData.setCustomer(customerInfo);
- }
- // 返回上一页
- wx.navigateBack({
- delta: 2,
- success: (result) => {
- wx.showToast({
- title: "创建成功",
- icon: "none"
- })
- },
- })
- }
- });
- } else if (content.sa_customersid == 0) {
- // 刷新线索相关页面
- const pages = getCurrentPages();
- const detailPage = pages.find(v => v.__route__ == 'CRM/lead/detail');
- const listPage = pages.find(v => v.__route__ == 'CRM/lead/index');
- if (detailPage) {
- detailPage.selectComponent("#FollowRecord").getList("", true);
- }
- if (listPage) {
- listPage.getList(true);
- }
- // 非选择模式,跳转到客户详情
- wx.redirectTo({
- url: '/CRM/customer/detail?id=' + res.data,
- success: (result) => {
- wx.showToast({
- title: "创建成功",
- icon: "none"
- })
- },
- })
- } else {
- // 编辑模式,返回上一页
- getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').getDetail()
- wx.navigateBack({
- success: (res) => {
- wx.showToast({
- title: "编辑成功",
- icon: "none"
- })
- },
- })
- }
- } else {
- wx.showToast({
- title: res.msg || "创建失败",
- icon: "none"
- })
- }
- })
- },
- interrupt({
- detail
- }) {
- // 处理表单中断事件
- },
- /* 表单必填项是否完成 */
- onConfirm({
- detail
- }) {
- this.setData({
- disabled: detail
- })
- },
- closePage() {
- wx.navigateBack({
- delta: 1
- });
- },
- // 是否显示全部
- onChange({
- detail
- }) {
- this.setData({
- showAll: detail
- })
- }
- });
|