| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- loading: false,
- disabled: true,
- form: [{
- label: "跟进日期",
- error: false,
- errMsg: "",
- type: "date",
- value: new Date().toISOString().split('T')[0],
- placeholder: "请选择跟进日期",
- valueName: "followDate",
- required: true,
- checking: "base"
- },
- {
- label: "跟进时间",
- error: false,
- errMsg: "",
- type: "time",
- value: new Date().toTimeString().substring(0, 8),
- placeholder: "请选择跟进时间",
- valueName: "followTime",
- required: true,
- checking: "base"
- },
- {
- label: "跟进方式",
- error: false,
- errMsg: "",
- type: "radio",
- value: "",
- radioList: [],
- valueName: "type",
- required: true,
- checking: "base"
- },
- {
- label: "跟进内容",
- error: false,
- errMsg: "",
- type: "textarea",
- value: "",
- placeholder: "请输入跟进内容",
- valueName: "content",
- required: true,
- checking: "base"
- },
- {
- label: "是否无效",
- error: false,
- errMsg: "",
- type: "radio",
- value: "true",
- radioList: [{
- id: "true",
- name: "有效"
- },
- {
- id: "false",
- name: "无效"
- }
- ],
- valueName: "isInvalid",
- required: false,
- checking: "base",
- interrupt: true
- }
- ],
- "content": {
- "sys_datafollowupid": 0,
- "ownertable": "sa_customers",
- "ownerid": "",
- "type": "",
- "content": "",
- "target": "",
- "results": "",
- "nextplan": "",
- "dataextend": ""
- }
- },
- onLoad(options) {
- // 获取客户ID
- if (options.ownerid) {
- this.setData({
- "content.ownerid": options.ownerid
- });
- }
- // 获取跟进方式列表
- this.getFollowTypeList();
- },
- // 获取跟进方式列表
- getFollowTypeList() {
- _Http.basic({
- "classname": "sysmanage.develop.optiontype.optiontype",
- "method": "optiontypeselect",
- "content": {
- "pageNumber": 1,
- "pageSize": 1000,
- "typename": "followType",
- "parameter": {}
- }
- }).then(res => {
- console.log("跟进方式列表", res);
- if (res.code == 1 && res.data && res.data.length) {
- let form = this.data.form;
- let typeField = form.find(v => v.valueName == 'type');
- typeField.radioList = res.data.map(item => ({
- id: item.value,
- name: item.value
- }));
- // 默认选择第一个
- if (typeField.radioList.length > 0) {
- typeField.value = typeField.radioList[0].id;
- }
- this.setData({
- form
- });
- }
- }).catch(err => {
- console.error("获取跟进方式列表失败", err);
- });
- },
- submit() {
- this.setData({
- loading: true
- });
- let formData = this.selectComponent("#Form").submit();
- // 合并跟进日期和时间
- let followDateTime = formData.followDate + ' ' + formData.followTime;
- // 构建dataextend
- let dataextend = {
- followTime: followDateTime,
- isInvalid: formData.isInvalid === 'false',
- invalidReason: formData.invalidReason || ""
- };
- let content = {
- ...this.data.content,
- ...formData,
- dataextend
- };
- // 删除不需要的字段
- delete content.followDate;
- delete content.followTime;
- delete content.invalidReason;
- _Http.basic({
- "id": "20220930121601",
- content
- }).then(res => {
- this.setData({
- loading: false
- });
- console.log("保存跟进记录", res);
- if (res.code == 1) {
- getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').partialRenewal(true);
- wx.navigateBack({
- success() {
- wx.showToast({
- title: "跟进成功",
- icon: "success"
- });
- }
- });
- } else {
- wx.showToast({
- title: res.msg || '保存失败',
- icon: 'none'
- });
- }
- }).catch(err => {
- this.setData({
- loading: false
- });
- console.error("保存跟进记录失败", err);
- wx.showToast({
- title: '网络错误',
- icon: 'none'
- });
- });
- },
- interrupt({
- detail
- }) {
- if (detail.data.label == '是否无效') {
- let form = detail.form;
- const invalidReasonFieldIndex = form.findIndex(v => v.valueName == 'invalidReason');
- if (detail.data.value == 'false') {
- if (invalidReasonFieldIndex === -1) {
- form.push({
- label: "无效原因",
- error: false,
- errMsg: "",
- type: "textarea",
- value: "",
- placeholder: "请输入无效原因",
- valueName: "invalidReason",
- required: true,
- checking: "base"
- });
- }
- } else {
- if (invalidReasonFieldIndex !== -1) {
- form.splice(invalidReasonFieldIndex, 1);
- }
- }
- this.setData({
- form
- });
- }
- },
- /* 表单必填项是否完成 */
- onConfirm({
- detail
- }) {
- this.setData({
- disabled: detail
- });
- },
- closePage() {
- wx.navigateBack({
- delta: 1
- });
- }
- });
|