index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. if (options.data) {
  116. let item = JSON.parse(options.data),
  117. form = this.data.form.map(v => {
  118. if (v.valueName == 'region') {
  119. v.value = [item.province, item.city, item.county]
  120. } else {
  121. v.value = Object.hasOwn(item, v.valueName) ? item[v.valueName] : v.value;
  122. }
  123. return v
  124. });
  125. this.setData({
  126. form,
  127. "disabled": false,
  128. "content.contactsid": item.contactsid
  129. })
  130. }
  131. },
  132. /* 提交数据 */
  133. submit() {
  134. let data = this.selectComponent("#Form").submit();
  135. if (!data || this.data.disabled) return;
  136. const content = {
  137. ...this.data.content,
  138. ...data,
  139. "province": data.region[0] || "",
  140. "city": data.region[1] || "",
  141. "county": data.region[2] || "",
  142. };
  143. delete(content.region);
  144. let pages = getCurrentPages();
  145. content.sys_enterpriseid = pages[pages.length - 2].data.detail.sys_enterpriseid;
  146. _Http.basic({
  147. "id": "20221018141802",
  148. content
  149. }).then(res => {
  150. console.log("编辑联系人", res)
  151. if (res.msg != '成功') return wx.showToast({
  152. title: res.data,
  153. icon: "none"
  154. });
  155. wx.showToast({
  156. title: '保存成功',
  157. icon: "none"
  158. });
  159. setTimeout(() => {
  160. let pages = getCurrentPages();
  161. pages[pages.length - 2].partialRenewal(true);
  162. wx.navigateBack();
  163. }, 500)
  164. });
  165. },
  166. /* 表单是否填写完成 */
  167. onConfirm({
  168. detail
  169. }) {
  170. this.setData({
  171. disabled: detail
  172. })
  173. },
  174. /* 是否显示全部 */
  175. changefromShowAll({
  176. detail
  177. }) {
  178. this.setData({
  179. fromShowAll: detail
  180. })
  181. },
  182. })