index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. sys_phonebookid: null, //是否为快捷选择创建的账号
  5. fromShowAll: true,
  6. form: [{
  7. label: "姓名",
  8. error: false,
  9. errMsg: "",
  10. type: "text",
  11. value: "",
  12. placeholder: "联系人名称",
  13. valueName: "name",
  14. required: true,
  15. checking: "base"
  16. }, {
  17. label: "手机号",
  18. error: false,
  19. errMsg: "",
  20. type: "number",
  21. value: "",
  22. placeholder: "联系人手机号码",
  23. valueName: "phonenumber",
  24. required: true,
  25. checking: "phone"
  26. }, {
  27. label: "部门",
  28. error: false,
  29. errMsg: "",
  30. type: "text",
  31. value: "",
  32. placeholder: "联系人所属部门",
  33. valueName: "depname",
  34. required: false,
  35. checking: "base"
  36. }, {
  37. label: "职位",
  38. error: false,
  39. errMsg: "",
  40. type: "text",
  41. value: "",
  42. placeholder: "联系人职位",
  43. valueName: "position",
  44. required: false,
  45. checking: "base"
  46. }, {
  47. label: "性别",
  48. error: false,
  49. errMsg: "",
  50. type: "sex",
  51. value: "",
  52. placeholder: "联系人性别",
  53. valueName: "sex",
  54. required: false,
  55. checking: "base"
  56. }, {
  57. label: "生日",
  58. error: false,
  59. errMsg: "",
  60. type: "date",
  61. value: "",
  62. placeholder: "联系人生日",
  63. valueName: "birthday",
  64. required: false
  65. }, {
  66. label: "邮箱",
  67. error: false,
  68. errMsg: "",
  69. type: "textarea",
  70. value: "",
  71. placeholder: "请填写",
  72. valueName: "email",
  73. required: false,
  74. checking: "mail"
  75. }, {
  76. label: "地区",
  77. error: false,
  78. errMsg: "",
  79. type: "region",
  80. value: [],
  81. placeholder: "省,市,区",
  82. valueName: "region",
  83. required: false
  84. }, {
  85. label: "详细地址",
  86. error: false,
  87. errMsg: "",
  88. type: "textarea",
  89. value: "",
  90. placeholder: "例: 科创园11栋1103室",
  91. valueName: "address",
  92. required: false,
  93. checking: "base"
  94. }, {
  95. label: "备注",
  96. error: false,
  97. errMsg: "",
  98. type: "textarea",
  99. value: "",
  100. placeholder: "请填写",
  101. valueName: "remarks",
  102. required: false,
  103. checking: "base"
  104. }],
  105. disabled: true,
  106. "content": {
  107. "contactsid": 0, //地址id
  108. "sys_enterpriseid": 0, //绑定数据
  109. "isleader": 0, //默认0
  110. "workaddress": 0,
  111. "isdefault": 0, //是否默认地址
  112. "isprimary": 0 //是否为主地址
  113. }
  114. },
  115. onLoad(options) {
  116. this.setData({
  117. "content.sys_enterpriseid": options.sys_enterpriseid
  118. });
  119. if (options.data) {
  120. let item = JSON.parse(options.data),
  121. form = this.data.form.map(v => {
  122. if (v.valueName == 'region') {
  123. v.value = item.province ? [item.province, item.city, item.county] : []
  124. } else {
  125. v.value = Object.hasOwn(item, v.valueName) ? item[v.valueName] : v.value;
  126. }
  127. return v
  128. });
  129. this.setData({
  130. form,
  131. "disabled": false,
  132. "content.contactsid": item.contactsid
  133. });
  134. if (item.sys_phonebookid) this.setData({
  135. sys_phonebookid: item.sys_phonebookid
  136. })
  137. };
  138. },
  139. /* 提交数据 */
  140. submit() {
  141. let data = this.selectComponent("#Form").submit();
  142. if (!data || this.data.disabled) return;
  143. const content = {
  144. ...this.data.content,
  145. ...data,
  146. "province": data.region[0] || "",
  147. "city": data.region[1] || "",
  148. "county": data.region[2] || "",
  149. sys_phonebookid: ""
  150. };
  151. delete(content.region);
  152. if (this.data.sys_phonebookid == null) {
  153. this.handleSubmit(content);
  154. } else {
  155. let that = this;
  156. wx.showModal({
  157. title: '提示',
  158. content: '是否删除原通讯录联系人信息',
  159. complete({
  160. confirm
  161. }) {
  162. content.sys_phonebookid = confirm ? that.data.sys_phonebookid : "";
  163. that.handleSubmit(content);
  164. }
  165. })
  166. }
  167. },
  168. handleSubmit(content) {
  169. _Http.basic({
  170. "id": "20221018141802",
  171. content
  172. }).then(res => {
  173. console.log("编辑联系人", res)
  174. if (res.msg != '成功') return wx.showToast({
  175. title: res.data,
  176. icon: "none"
  177. });
  178. wx.showToast({
  179. title: '保存成功',
  180. icon: "none"
  181. });
  182. setTimeout(() => {
  183. getCurrentPages().forEach(v => {
  184. if (v.__route__ == 'packageA/setclient/modules/contacts/detail/index') {
  185. v.getDetail();
  186. } else if (v.selectComponent("#Contacts")) {
  187. let page = v.selectComponent("#Contacts"),
  188. list = page.data.list,
  189. index = list.findIndex(value => value.contactsid == res.data.contactsid);
  190. if (index != -1) {
  191. //列表中存在说明是编辑,返回上一级页面并更新数据
  192. list[index] = res.data;
  193. page.setData({
  194. list
  195. });
  196. } else {
  197. //列表中不存在说明是新增,返回上一级页面更新数据 并进入详情
  198. list.push(res.data);
  199. page.setData({
  200. list,
  201. "content.total": page.data.content.total + 1
  202. });
  203. wx.navigateTo({
  204. url: '/packageA/setclient/modules/contacts/detail/index?contactsid=' + res.data.contactsid
  205. })
  206. }
  207. } else if (v.__route__ == 'packageA/project/modules/contacts/search/index') {
  208. let index = v.data.list.findIndex(value => value.contactsid == res.data.contactsid);
  209. console.log(index)
  210. if (index != -1) v.setData({
  211. [`list[${index}]`]: res.data
  212. })
  213. }
  214. });
  215. wx.navigateBack();
  216. }, 500)
  217. });
  218. },
  219. /* 表单是否填写完成 */
  220. onConfirm({
  221. detail
  222. }) {
  223. this.setData({
  224. disabled: detail
  225. })
  226. },
  227. /* 是否显示全部 */
  228. changefromShowAll({
  229. detail
  230. }) {
  231. this.setData({
  232. fromShowAll: detail
  233. })
  234. },
  235. })