edit.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. const _Http = getApp().globalData.http,
  2. deleteMark = require("../../utils/deleteMark");
  3. Page({
  4. data: {
  5. sys_phonebookid: 0,
  6. from1: [{
  7. label: "姓名",
  8. error: false,
  9. errMsg: "",
  10. type: "text",
  11. value: "",
  12. placeholder: "请填写",
  13. valueName: "name", //绑定的字段名称
  14. required: true, //必填
  15. }, {
  16. label: "手机号码",
  17. error: false,
  18. errMsg: "",
  19. type: "text",
  20. value: "",
  21. placeholder: "请填写",
  22. valueName: "phonenumber", //绑定的字段名称
  23. required: true, //必填
  24. callback: null,
  25. }, {
  26. label: "性别",
  27. error: false,
  28. errMsg: "",
  29. type: "sex",
  30. value: "",
  31. placeholder: "请填写",
  32. valueName: "sex",
  33. required: false, //必填
  34. }, {
  35. label: "生日",
  36. error: false,
  37. errMsg: "",
  38. type: "date",
  39. value: "",
  40. placeholder: "请填写",
  41. valueName: "birthday",
  42. required: false, //必填
  43. }, {
  44. label: "家庭住址",
  45. error: false,
  46. errMsg: "",
  47. type: "text",
  48. value: "",
  49. placeholder: "请填写",
  50. valueName: "homeaddress",
  51. required: false, //必填
  52. }, {
  53. label: "邮箱",
  54. error: false,
  55. errMsg: "",
  56. type: "text",
  57. value: "",
  58. placeholder: "请填写",
  59. valueName: "email",
  60. required: false, //必填
  61. }],
  62. from2: [{
  63. label: "单位",
  64. error: false,
  65. errMsg: "",
  66. type: "text",
  67. value: "",
  68. placeholder: "请填写",
  69. valueName: "company",
  70. required: false, //必填
  71. }, {
  72. label: "部门",
  73. error: false,
  74. errMsg: "",
  75. type: "text",
  76. value: "",
  77. placeholder: "请填写",
  78. valueName: "depname",
  79. required: false, //必填
  80. }, {
  81. label: "职位",
  82. error: false,
  83. errMsg: "",
  84. type: "text",
  85. value: "",
  86. placeholder: "请填写",
  87. valueName: "position",
  88. required: false, //必填
  89. }],
  90. from3: [{
  91. label: "标签",
  92. error: false,
  93. errMsg: "",
  94. type: "slot",
  95. value: "",
  96. placeholder: "请填写",
  97. valueName: "tag",
  98. required: false, //必填
  99. }, {
  100. label: "群组",
  101. error: false,
  102. errMsg: "",
  103. type: "custom",
  104. value: "",
  105. placeholder: "请填写",
  106. valueName: "sys_phonebookgroupid",
  107. required: false, //必填
  108. }, {
  109. label: "备注",
  110. error: false,
  111. errMsg: "",
  112. type: "text",
  113. value: "",
  114. placeholder: "请填写",
  115. valueName: "remarks",
  116. required: false, //必填
  117. }],
  118. disabled: true, //按钮禁用
  119. groupList: [],
  120. groupNameList: [],
  121. groupName: null,
  122. popupShow: false,
  123. checked: false,
  124. radio: '',
  125. loading: false
  126. },
  127. onLoad(options) {
  128. if (options.group) {
  129. const group = JSON.parse(options.group);
  130. this.setData({
  131. groupName: group.groupname,
  132. 'from3[1].value': group.sys_phonebookgroupid
  133. })
  134. };
  135. if (options.data) {
  136. const item = JSON.parse(options.data);
  137. this.setData({
  138. 'from1[0].value': item.name,
  139. 'from1[1].value': item.phonenumber,
  140. 'from1[2].value': item.sex,
  141. 'from1[3].value': item.birthday,
  142. 'from1[4].value': item.homeaddress,
  143. 'from1[5].value': item.email,
  144. 'from2[0].value': item.company,
  145. 'from2[1].value': item.depname,
  146. 'from2[2].value': item.position,
  147. 'from3[0].value': item.tag1,
  148. 'from3[1].value': item.sys_phonebookgroupid,
  149. 'from3[2].value': item.remarks,
  150. groupName: item.groupname,
  151. sys_phonebookid: item.sys_phonebookid,
  152. disabled: false
  153. });
  154. if (item.tag1.length) {
  155. let checked = false,
  156. radio = '';
  157. item.tag1.forEach(v => {
  158. if (v == '关键决策人') {
  159. checked = true;
  160. } else {
  161. radio = v;
  162. }
  163. })
  164. this.setData({
  165. checked,
  166. radio
  167. })
  168. }
  169. };
  170. this.getGroup();
  171. wx.setNavigationBarTitle({
  172. title: this.data.sys_phonebookid == 0 ? '添加联系人' : '修改联系人',
  173. })
  174. },
  175. /* 监听表单必填项 */
  176. form1CompletedOrNot({
  177. detail
  178. }) {
  179. this.setData({
  180. disabled: !detail
  181. })
  182. },
  183. /* 提交表单 */
  184. submit() {
  185. if (this.data.disabled) return wx.showToast({
  186. title: '请完成必填项',
  187. icon: "none"
  188. })
  189. let from = {
  190. ...this.selectComponent("#from1").getData().returnData,
  191. ...this.selectComponent("#from2").getData().returnData,
  192. ...this.selectComponent("#from3").getData().returnData,
  193. }
  194. if (!deleteMark.CheckPhoneNumber(from.phonenumber)) return;
  195. if (from.email && !deleteMark.CheckEmail(from.email)) return;
  196. if (from.sys_phonebookgroupid == '') from.sys_phonebookgroupid = 0;
  197. if (from.tag == '') from.tag = [];
  198. this.setData({
  199. loading: true
  200. })
  201. _Http.basic({
  202. "id": "20220831164503",
  203. "version": 1,
  204. "content": {
  205. "sys_phonebookid": this.data.sys_phonebookid, //sys_phonebookid<=0时 为新增
  206. ...from
  207. }
  208. }).then(res => {
  209. console.log("新建联系人", res)
  210. this.setData({
  211. loading: false
  212. })
  213. if (res.msg != '成功') return wx.showToast({
  214. title: res.data,
  215. icon: "none"
  216. })
  217. res.data.tag1 = res.data.tag.length ? JSON.parse(res.data.tag) : ""
  218. getCurrentPages().forEach(v => {
  219. if (v.route === 'packageA/contacts/index') {
  220. v.getGroup();
  221. } else if (v.route === 'packageA/contacts/list') {
  222. let arr = v.data.phonebook,
  223. index = arr.findIndex(value => value.sys_phonebookid == res.data.sys_phonebookid);
  224. (index === -1) ? arr.push(res.data): arr[index] = res.data;
  225. v.setData({
  226. phonebook: arr
  227. })
  228. } else if (v.route === 'packageA/contacts/details') {
  229. v.handleData(res.data);
  230. }
  231. });
  232. wx.showToast({
  233. title: this.data.sys_phonebookid == 0 ? '添加成功' : '保存成功'
  234. })
  235. this.setData({
  236. disabled: true,
  237. })
  238. setTimeout(() => {
  239. wx.navigateBack({
  240. delta: 0
  241. })
  242. }, 700);
  243. })
  244. },
  245. /* 获取分组 */
  246. getGroup() {
  247. _Http.basic({
  248. "id": "20220831164603",
  249. "version": 1,
  250. "content": {
  251. "nocache": true,
  252. "where": {
  253. "condition": ""
  254. }
  255. }
  256. }).then(res => {
  257. if (res.msg != '成功') return wx.showToast({
  258. title: res.msg,
  259. icon: "none"
  260. })
  261. const data = res.data.filter(v => v.groupname != '客户联系人' && v.groupname != '项目联系人');
  262. this.setData({
  263. groupList: data,
  264. groupNameList: data.map(v => v.groupname)
  265. })
  266. });
  267. },
  268. /* 选择部门 */
  269. bindPickerChange(e) {
  270. const {
  271. returnData
  272. } = this.selectComponent("#from3").getData()
  273. this.setData({
  274. 'from3[1].value': this.data.groupList[e.detail.value - 0].sys_phonebookgroupid,
  275. groupName: this.data.groupNameList[e.detail.value - 0],
  276. 'from3[0].value': returnData.tag,
  277. 'from3[2].value': returnData.remarks
  278. });
  279. },
  280. /* 打开弹出层 */
  281. openPopup() {
  282. this.setData({
  283. popupShow: true
  284. })
  285. },
  286. /* 关闭弹出层 */
  287. closePopup() {
  288. this.setData({
  289. popupShow: false
  290. })
  291. },
  292. /* 确定标签 */
  293. handleTag() {
  294. let tagArr = [];
  295. if (this.data.checked) tagArr.push("关键决策人");
  296. if (this.data.radio) tagArr.push(this.data.radio);
  297. const {
  298. returnData
  299. } = this.selectComponent("#from3").getData()
  300. this.setData({
  301. 'from3[0].value': tagArr,
  302. 'from3[1].value': returnData.sys_phonebookgroupid,
  303. 'from3[2].value': returnData.remarks
  304. });
  305. this.closePopup()
  306. },
  307. /* 是否关键决策人 */
  308. changeChecked() {
  309. this.setData({
  310. checked: !this.data.checked
  311. })
  312. },
  313. /* 单选 */
  314. onChange(e) {
  315. this.setData({
  316. radio: e.currentTarget.dataset.name
  317. })
  318. },
  319. onShareAppMessage() {}
  320. })