create.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. loading: false,
  5. disabled: true,
  6. form: [{
  7. label: "跟进日期",
  8. error: false,
  9. errMsg: "",
  10. type: "date",
  11. value: new Date().toISOString().split('T')[0],
  12. placeholder: "请选择跟进日期",
  13. valueName: "followDate",
  14. required: true,
  15. checking: "base"
  16. },
  17. {
  18. label: "跟进时间",
  19. error: false,
  20. errMsg: "",
  21. type: "time",
  22. value: new Date().toTimeString().substring(0, 8),
  23. placeholder: "请选择跟进时间",
  24. valueName: "followTime",
  25. required: true,
  26. checking: "base"
  27. },
  28. {
  29. label: "跟进方式",
  30. error: false,
  31. errMsg: "",
  32. type: "radio",
  33. value: "",
  34. radioList: [],
  35. valueName: "type",
  36. required: true,
  37. checking: "base"
  38. },
  39. {
  40. label: "跟进内容",
  41. error: false,
  42. errMsg: "",
  43. type: "textarea",
  44. value: "",
  45. placeholder: "请输入跟进内容",
  46. valueName: "content",
  47. required: true,
  48. checking: "base"
  49. },
  50. {
  51. label: "是否无效",
  52. error: false,
  53. errMsg: "",
  54. type: "radio",
  55. value: "true",
  56. radioList: [{
  57. id: "true",
  58. name: "有效"
  59. },
  60. {
  61. id: "false",
  62. name: "无效"
  63. }
  64. ],
  65. valueName: "isInvalid",
  66. required: false,
  67. checking: "base",
  68. interrupt: true
  69. }
  70. ],
  71. "content": {
  72. "sys_datafollowupid": 0,
  73. "ownertable": "sa_customers",
  74. "ownerid": "",
  75. "type": "",
  76. "content": "",
  77. "target": "",
  78. "results": "",
  79. "nextplan": "",
  80. "dataextend": ""
  81. }
  82. },
  83. onLoad(options) {
  84. // 获取客户ID
  85. if (options.ownerid) {
  86. this.setData({
  87. "content.ownerid": options.ownerid
  88. });
  89. }
  90. // 获取跟进方式列表
  91. this.getFollowTypeList();
  92. },
  93. // 获取跟进方式列表
  94. getFollowTypeList() {
  95. _Http.basic({
  96. "classname": "sysmanage.develop.optiontype.optiontype",
  97. "method": "optiontypeselect",
  98. "content": {
  99. "pageNumber": 1,
  100. "pageSize": 1000,
  101. "typename": "followType",
  102. "parameter": {}
  103. }
  104. }).then(res => {
  105. console.log("跟进方式列表", res);
  106. if (res.code == 1 && res.data && res.data.length) {
  107. let form = this.data.form;
  108. let typeField = form.find(v => v.valueName == 'type');
  109. typeField.radioList = res.data.map(item => ({
  110. id: item.value,
  111. name: item.value
  112. }));
  113. // 默认选择第一个
  114. if (typeField.radioList.length > 0) {
  115. typeField.value = typeField.radioList[0].id;
  116. }
  117. this.setData({
  118. form
  119. });
  120. }
  121. }).catch(err => {
  122. console.error("获取跟进方式列表失败", err);
  123. });
  124. },
  125. submit() {
  126. this.setData({
  127. loading: true
  128. });
  129. let formData = this.selectComponent("#Form").submit();
  130. // 合并跟进日期和时间
  131. let followDateTime = formData.followDate + ' ' + formData.followTime;
  132. // 构建dataextend
  133. let dataextend = {
  134. followTime: followDateTime,
  135. isInvalid: formData.isInvalid === 'false',
  136. invalidReason: formData.invalidReason || ""
  137. };
  138. let content = {
  139. ...this.data.content,
  140. ...formData,
  141. dataextend
  142. };
  143. // 删除不需要的字段
  144. delete content.followDate;
  145. delete content.followTime;
  146. delete content.invalidReason;
  147. _Http.basic({
  148. "id": "20220930121601",
  149. content
  150. }).then(res => {
  151. this.setData({
  152. loading: false
  153. });
  154. console.log("保存跟进记录", res);
  155. if (res.code == 1) {
  156. getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').partialRenewal(true);
  157. wx.navigateBack({
  158. success() {
  159. wx.showToast({
  160. title: "跟进成功",
  161. icon: "success"
  162. });
  163. }
  164. });
  165. } else {
  166. wx.showToast({
  167. title: res.msg || '保存失败',
  168. icon: 'none'
  169. });
  170. }
  171. }).catch(err => {
  172. this.setData({
  173. loading: false
  174. });
  175. console.error("保存跟进记录失败", err);
  176. wx.showToast({
  177. title: '网络错误',
  178. icon: 'none'
  179. });
  180. });
  181. },
  182. interrupt({
  183. detail
  184. }) {
  185. if (detail.data.label == '是否无效') {
  186. let form = detail.form;
  187. const invalidReasonFieldIndex = form.findIndex(v => v.valueName == 'invalidReason');
  188. if (detail.data.value == 'false') {
  189. if (invalidReasonFieldIndex === -1) {
  190. form.push({
  191. label: "无效原因",
  192. error: false,
  193. errMsg: "",
  194. type: "textarea",
  195. value: "",
  196. placeholder: "请输入无效原因",
  197. valueName: "invalidReason",
  198. required: true,
  199. checking: "base"
  200. });
  201. }
  202. } else {
  203. if (invalidReasonFieldIndex !== -1) {
  204. form.splice(invalidReasonFieldIndex, 1);
  205. }
  206. }
  207. this.setData({
  208. form
  209. });
  210. }
  211. },
  212. /* 表单必填项是否完成 */
  213. onConfirm({
  214. detail
  215. }) {
  216. this.setData({
  217. disabled: detail
  218. });
  219. },
  220. closePage() {
  221. wx.navigateBack({
  222. delta: 1
  223. });
  224. }
  225. });