index.js 6.7 KB

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