|
|
@@ -1,8 +1,7 @@
|
|
|
-const _Http = getApp().globalData.http,
|
|
|
- deleteMark = require("../../utils/deleteMark");
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
Page({
|
|
|
data: {
|
|
|
- sys_phonebookid: 0,
|
|
|
+ isEdit: false,
|
|
|
form: [{
|
|
|
label: "姓名",
|
|
|
error: false,
|
|
|
@@ -125,25 +124,6 @@ Page({
|
|
|
placeholder: "请填写",
|
|
|
valueName: "homeaddress",
|
|
|
required: false, //必填
|
|
|
- }],
|
|
|
- from3: [{
|
|
|
- label: "标签",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "slot",
|
|
|
- value: "",
|
|
|
- placeholder: "请填写",
|
|
|
- valueName: "tag",
|
|
|
- required: false, //必填
|
|
|
- }, {
|
|
|
- label: "群组",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "custom",
|
|
|
- value: "",
|
|
|
- placeholder: "请填写",
|
|
|
- valueName: "sys_phonebookgroupid",
|
|
|
- required: false, //必填
|
|
|
}, {
|
|
|
label: "备注",
|
|
|
error: false,
|
|
|
@@ -152,26 +132,29 @@ Page({
|
|
|
value: "",
|
|
|
placeholder: "请填写",
|
|
|
valueName: "remarks",
|
|
|
- required: false, //必填
|
|
|
+ required: false,
|
|
|
}],
|
|
|
+ content: {
|
|
|
+ sys_phonebookid: 0
|
|
|
+ },
|
|
|
disabled: true, //按钮禁用
|
|
|
- groupList: [],
|
|
|
- groupNameList: [],
|
|
|
- groupName: null,
|
|
|
- popupShow: false,
|
|
|
- checked: false,
|
|
|
- radio: '',
|
|
|
+ groupname: null,
|
|
|
loading: false
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: '添加联系人'
|
|
|
+ })
|
|
|
if (options.group) {
|
|
|
const group = JSON.parse(options.group);
|
|
|
this.setData({
|
|
|
- groupName: group.groupname,
|
|
|
- 'from3[1].value': group.sys_phonebookgroupid
|
|
|
+ groupname: group.groupname
|
|
|
+ })
|
|
|
+ this.getGroup();
|
|
|
+ } else if (options.data) {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: '修改联系人'
|
|
|
})
|
|
|
- };
|
|
|
- if (options.data) {
|
|
|
let item = JSON.parse(options.data),
|
|
|
disabled = false,
|
|
|
arr = item.phonenumber.split("-");
|
|
|
@@ -208,59 +191,30 @@ Page({
|
|
|
disabled
|
|
|
});
|
|
|
this.data.content = item;
|
|
|
- if (item.sys_phonebookid) this.setData({
|
|
|
- sys_phonebookid: item.sys_phonebookid
|
|
|
- })
|
|
|
-
|
|
|
this.setData({
|
|
|
- 'from3[0].value': item.tag1,
|
|
|
- 'from3[1].value': item.sys_phonebookgroupid,
|
|
|
- 'from3[2].value': item.remarks,
|
|
|
- groupName: item.groupname,
|
|
|
- sys_phonebookid: item.sys_phonebookid,
|
|
|
- disabled: false
|
|
|
+ groupname: item.groupname,
|
|
|
+ disabled: false,
|
|
|
+ isEdit: true
|
|
|
});
|
|
|
- if (item.tag1.length) {
|
|
|
- let checked = false,
|
|
|
- radio = '';
|
|
|
- item.tag1.forEach(v => {
|
|
|
- if (v == '关键决策人') {
|
|
|
- checked = true;
|
|
|
- } else {
|
|
|
- radio = v;
|
|
|
- }
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- checked,
|
|
|
- radio
|
|
|
- })
|
|
|
- }
|
|
|
- };
|
|
|
- this.getGroup();
|
|
|
- wx.setNavigationBarTitle({
|
|
|
- title: this.data.sys_phonebookid == 0 ? '添加联系人' : '修改联系人',
|
|
|
- })
|
|
|
+ if (item.groupname != '客户联系人' && item.groupname != '项目联系人') this.getGroup();
|
|
|
+ } else {
|
|
|
+ this.getGroup();
|
|
|
+ }
|
|
|
},
|
|
|
/* 提交表单 */
|
|
|
submit() {
|
|
|
- let from = Object.assign(this.selectComponent("#from3").getData().returnData, this.selectComponent("#Form").submit())
|
|
|
- if (this.data.loading) return;
|
|
|
- if (from.telephone) {
|
|
|
- from.phonenumber = from.telephone.join("-");
|
|
|
- delete(from.telephone)
|
|
|
+ let content = Object.assign(this.data.content, this.selectComponent("#Form").submit());
|
|
|
+ if (content.telephone) {
|
|
|
+ content.phonenumber = content.telephone.join("-");
|
|
|
+ delete(content.telephone)
|
|
|
}
|
|
|
- if (from.sys_phonebookgroupid == '') from.sys_phonebookgroupid = 0;
|
|
|
- if (from.tag == '') from.tag = [];
|
|
|
this.setData({
|
|
|
loading: true
|
|
|
})
|
|
|
_Http.basic({
|
|
|
- "id": "20220831164503",
|
|
|
+ "id": content.groupname == '客户联系人' || content.groupname == '项目联系人' ? '20221018141802' : "20220831164503",
|
|
|
"version": 1,
|
|
|
- "content": {
|
|
|
- "sys_phonebookid": this.data.sys_phonebookid, //sys_phonebookid<=0时 为新增
|
|
|
- ...from
|
|
|
- }
|
|
|
+ content
|
|
|
}).then(res => {
|
|
|
console.log("新建联系人", res)
|
|
|
this.setData({
|
|
|
@@ -270,31 +224,33 @@ Page({
|
|
|
title: res.data,
|
|
|
icon: "none"
|
|
|
})
|
|
|
- res.data.tag1 = res.data.tag.length ? JSON.parse(res.data.tag) : ""
|
|
|
getCurrentPages().forEach(v => {
|
|
|
if (v.route === 'packageA/contacts/index') {
|
|
|
v.getGroup();
|
|
|
} else if (v.route === 'packageA/contacts/list') {
|
|
|
- let arr = v.data.phonebook,
|
|
|
- index = arr.findIndex(value => value.sys_phonebookid == res.data.sys_phonebookid);
|
|
|
- (index === -1) ? arr.push(res.data): arr[index] = res.data;
|
|
|
- v.setData({
|
|
|
- phonebook: arr
|
|
|
- })
|
|
|
+ v.getGroup();
|
|
|
} else if (v.route === 'packageA/contacts/details') {
|
|
|
v.handleData(res.data);
|
|
|
}
|
|
|
});
|
|
|
+ let isEdit = this.data.isEdit;
|
|
|
wx.showToast({
|
|
|
- title: this.data.sys_phonebookid == 0 ? '添加成功' : '保存成功'
|
|
|
- })
|
|
|
+ title: isEdit ? '保存成功' : '添加成功',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
this.setData({
|
|
|
disabled: true,
|
|
|
})
|
|
|
setTimeout(() => {
|
|
|
- wx.navigateBack({
|
|
|
- delta: 0
|
|
|
- })
|
|
|
+ if (isEdit) {
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 0
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.redirectTo({
|
|
|
+ url: '/packageA/contacts/details?item=' + JSON.stringify(res.data),
|
|
|
+ })
|
|
|
+ }
|
|
|
}, 700);
|
|
|
})
|
|
|
},
|
|
|
@@ -337,13 +293,15 @@ Page({
|
|
|
this.setData({
|
|
|
form
|
|
|
})
|
|
|
+ } else if (data.label == '群组') {
|
|
|
+ this.data.content.sys_phonebookgroupid = data.range.find(v => v.groupname == data.value).sys_phonebookgroupid;
|
|
|
}
|
|
|
},
|
|
|
/* 监听表单必填项 */
|
|
|
onConfirm({
|
|
|
detail
|
|
|
}) {
|
|
|
- if (detail !== this.data.disabled) this.setData({
|
|
|
+ this.setData({
|
|
|
disabled: detail
|
|
|
})
|
|
|
},
|
|
|
@@ -363,62 +321,31 @@ Page({
|
|
|
title: res.msg,
|
|
|
icon: "none"
|
|
|
})
|
|
|
- const data = res.data.filter(v => v.groupname != '客户联系人' && v.groupname != '项目联系人');
|
|
|
+ const range = res.data.filter(v => v.groupname != '客户联系人' && v.groupname != '项目联系人').map(v => {
|
|
|
+ delete(v.count)
|
|
|
+ delete(v.phonebook)
|
|
|
+ delete(v.rowindex)
|
|
|
+ return v
|
|
|
+ }),
|
|
|
+ groupname = this.data.groupname || '默认群组';
|
|
|
+ let form = this.data.form;
|
|
|
+ form.splice(form.length - 1, 0, {
|
|
|
+ label: "群组",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "selector",
|
|
|
+ range,
|
|
|
+ rangeKey: "groupname",
|
|
|
+ rangeIndex: range.findIndex(v => v.groupname == groupname),
|
|
|
+ value: groupname,
|
|
|
+ placeholder: "选择群组",
|
|
|
+ valueName: "groupname",
|
|
|
+ required: false, //必填
|
|
|
+ interrupt: true
|
|
|
+ })
|
|
|
this.setData({
|
|
|
- groupList: data,
|
|
|
- groupNameList: data.map(v => v.groupname)
|
|
|
+ form
|
|
|
})
|
|
|
});
|
|
|
- },
|
|
|
- /* 选择群组 */
|
|
|
- bindPickerChange(e) {
|
|
|
- const {
|
|
|
- returnData
|
|
|
- } = this.selectComponent("#from3").getData()
|
|
|
- this.setData({
|
|
|
- 'from3[1].value': this.data.groupList[e.detail.value - 0].sys_phonebookgroupid,
|
|
|
- groupName: this.data.groupNameList[e.detail.value - 0],
|
|
|
- 'from3[0].value': returnData.tag,
|
|
|
- 'from3[2].value': returnData.remarks
|
|
|
- });
|
|
|
- },
|
|
|
- /* 打开弹出层 */
|
|
|
- openPopup() {
|
|
|
- this.setData({
|
|
|
- popupShow: true
|
|
|
- })
|
|
|
- },
|
|
|
- /* 关闭弹出层 */
|
|
|
- closePopup() {
|
|
|
- this.setData({
|
|
|
- popupShow: false
|
|
|
- })
|
|
|
- },
|
|
|
- /* 确定标签 */
|
|
|
- handleTag() {
|
|
|
- let tagArr = [];
|
|
|
- if (this.data.checked) tagArr.push("关键决策人");
|
|
|
- if (this.data.radio) tagArr.push(this.data.radio);
|
|
|
- const {
|
|
|
- returnData
|
|
|
- } = this.selectComponent("#from3").getData()
|
|
|
- this.setData({
|
|
|
- 'from3[0].value': tagArr,
|
|
|
- 'from3[1].value': returnData.sys_phonebookgroupid,
|
|
|
- 'from3[2].value': returnData.remarks
|
|
|
- });
|
|
|
- this.closePopup()
|
|
|
- },
|
|
|
- /* 是否关键决策人 */
|
|
|
- changeChecked() {
|
|
|
- this.setData({
|
|
|
- checked: !this.data.checked
|
|
|
- })
|
|
|
- },
|
|
|
- /* 单选 */
|
|
|
- onChange(e) {
|
|
|
- this.setData({
|
|
|
- radio: e.currentTarget.dataset.name
|
|
|
- })
|
|
|
}
|
|
|
})
|