create.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. loading: false,
  5. disabled: true,
  6. showAll: false,
  7. form: [{
  8. label: "客户名称",
  9. error: false,
  10. errMsg: "",
  11. type: "text",
  12. value: "",
  13. placeholder: "请输入客户名称",
  14. valueName: "name",
  15. required: true,
  16. checking: "base"
  17. }, {
  18. label: "手机",
  19. error: false,
  20. errMsg: "",
  21. type: "number",
  22. value: "",
  23. placeholder: "请输入手机号码",
  24. valueName: "phonenumber",
  25. required: true
  26. }, {
  27. label: "性别",
  28. error: false,
  29. errMsg: "",
  30. type: "radio",
  31. value: "",
  32. radioList: [{
  33. id: "男",
  34. name: "男"
  35. },
  36. {
  37. id: "女",
  38. name: "女"
  39. }
  40. ],
  41. valueName: "sex",
  42. required: false,
  43. checking: "base",
  44. direction: "horizontal"
  45. }, {
  46. label: "生日",
  47. error: false,
  48. errMsg: "",
  49. type: "date",
  50. value: "",
  51. placeholder: "请选择生日",
  52. valueName: "birthday",
  53. required: false
  54. }, {
  55. label: "客户来源",
  56. error: false,
  57. errMsg: "",
  58. type: "radio",
  59. value: "",
  60. radioList: [],
  61. valueName: "source",
  62. required: true,
  63. checking: "base"
  64. }, {
  65. label: "选择线索",
  66. error: false,
  67. errMsg: "",
  68. type: "route",
  69. url: "/select/lead/index",
  70. params: {
  71. "id": 20221101094502,
  72. "content": {
  73. "pageNumber": 1,
  74. "pageSize": 20,
  75. "where": {
  76. "condition": "",
  77. },
  78. },
  79. },
  80. query: '&radio=true',
  81. value: "",
  82. placeholder: "选择线索",
  83. valueName: "sat_orderclueid",
  84. required: false,
  85. interrupt: false
  86. }, {
  87. label: "外部订单号",
  88. error: false,
  89. errMsg: "",
  90. type: "text",
  91. value: "",
  92. placeholder: "请输入外部订单号",
  93. valueName: "ext_no",
  94. required: false,
  95. checking: "base"
  96. }, {
  97. label: "省市县",
  98. error: false,
  99. errMsg: "",
  100. type: "region",
  101. value: [],
  102. placeholder: "省,市,县",
  103. valueName: "region",
  104. required: true
  105. }, {
  106. label: "地址",
  107. error: false,
  108. errMsg: "",
  109. type: "textarea",
  110. value: "",
  111. placeholder: "请输入详细地址",
  112. valueName: "address",
  113. required: true,
  114. checking: "base"
  115. }, {
  116. label: "小区及门牌号",
  117. error: false,
  118. errMsg: "",
  119. type: "text",
  120. value: "",
  121. placeholder: "请输入小区及门牌号",
  122. valueName: "community",
  123. required: true,
  124. checking: "base"
  125. }, {
  126. label: "备注",
  127. error: false,
  128. errMsg: "",
  129. type: "textarea",
  130. value: "",
  131. placeholder: "请输入备注",
  132. valueName: "remarks",
  133. required: false,
  134. checking: "base"
  135. }],
  136. "content": {
  137. "sa_customersid": "0",
  138. sat_orderclueid: 0
  139. }
  140. },
  141. onLoad(options) {
  142. // 检查是否是选择模式
  143. this.setData({
  144. selectMode: options.selectMode === 'true'
  145. });
  146. // 检查是否是从线索详情页面跳转过来的
  147. if (options.clueId && options.clueInfo) {
  148. try {
  149. const clueInfo = JSON.parse(decodeURIComponent(options.clueInfo));
  150. let form = this.data.form;
  151. // 填充线索信息到表单
  152. form = form.map(v => {
  153. switch (v.valueName) {
  154. case "name":
  155. v.value = clueInfo.name || '';
  156. break;
  157. case "phonenumber":
  158. v.value = clueInfo.phonenumber || '';
  159. break;
  160. case "sex":
  161. v.value = clueInfo.sex || '';
  162. break;
  163. case "source":
  164. // 设置客户来源为线索转化
  165. v.radioList = [{
  166. name: '线索转化',
  167. id: '线索转化'
  168. }];
  169. v.disabled = true;
  170. v.value = '线索转化';
  171. break;
  172. case "sat_orderclueid":
  173. // 禁用选择线索字段
  174. v.disabled = true;
  175. v.value = [clueInfo.name, [clueInfo.sat_orderclueid]] || '';
  176. break;
  177. case "ext_no":
  178. v.value = clueInfo.ext_no || '';
  179. break;
  180. case "region":
  181. v.value = clueInfo.province ? [clueInfo.province, clueInfo.city, clueInfo.county] : [];
  182. break;
  183. case "address":
  184. v.value = clueInfo.address || '';
  185. break;
  186. case "community":
  187. v.value = clueInfo.community || '';
  188. break;
  189. case "remarks":
  190. v.value = clueInfo.notes || '';
  191. break;
  192. default:
  193. v.value = v.value;
  194. break;
  195. }
  196. return v
  197. });
  198. this.setData({
  199. "content.sat_orderclueid": [options.clueId, [options.clueId]],
  200. form
  201. });
  202. this.selectComponent("#Form").confirm()
  203. // 设置页面标题为转化客户
  204. wx.setNavigationBarTitle({
  205. title: '转化客户'
  206. })
  207. } catch (error) {
  208. console.error('解析线索信息失败', error);
  209. this.getCustomerSourceList();
  210. }
  211. } else if (options.edit) {
  212. // 如果是编辑模式,获取客户详情
  213. let data = _Http.detail;
  214. let form = this.data.form.filter(v => v.label != '选择线索');
  215. data.region = data.province ? [data.province, data.city, data.county] : [];
  216. form = form.map(v => {
  217. switch (v.valueName) {
  218. case "source":
  219. if (data.source == '线索转化') {
  220. v.radioList = [{
  221. name: '线索转化',
  222. id: '线索转化'
  223. }];
  224. v.disabled = true;
  225. } else {
  226. this.getCustomerSourceList();
  227. }
  228. v.value = data[v.valueName] || ''
  229. break;
  230. default:
  231. v.value = data[v.valueName] || ''
  232. break;
  233. }
  234. return v
  235. })
  236. this.setData({
  237. "content.sa_customersid": data.sa_customersid,
  238. "content.sat_orderclueid": data.sat_orderclueid,
  239. form
  240. });
  241. this.selectComponent("#Form").confirm()
  242. wx.setNavigationBarTitle({
  243. title: '编辑客户'
  244. })
  245. } else {
  246. this.getCustomerSourceList();
  247. }
  248. },
  249. // 获取客户来源列表
  250. getCustomerSourceList() {
  251. _Http.basic({
  252. "classname": "sysmanage.develop.optiontype.optiontype",
  253. "method": "optiontypeselect",
  254. "content": {
  255. "pageNumber": 1,
  256. "pageSize": 1000,
  257. "typename": "customersource",
  258. "parameter": {}
  259. }
  260. }).then(res => {
  261. console.log("客户来源列表", res);
  262. if (res.code == 1 && res.data && res.data.length) {
  263. let form = this.data.form;
  264. let sourceField = form.find(v => v.valueName == 'source');
  265. sourceField.radioList = res.data.map(item => ({
  266. id: item.value,
  267. name: item.value
  268. }));
  269. this.setData({
  270. form
  271. });
  272. }
  273. }).catch(err => {
  274. console.error("获取客户来源列表失败", err);
  275. });
  276. },
  277. submit() {
  278. this.setData({
  279. loading: true
  280. })
  281. let content = {
  282. ...this.data.content,
  283. ...this.selectComponent("#Form").submit()
  284. };
  285. // 处理省市县数据
  286. if (content.region && content.region.length) {
  287. content.province = content.region[0] || "";
  288. content.city = content.region[1] || "";
  289. content.county = content.region[2] || "";
  290. delete content.region;
  291. }
  292. content.sat_orderclueid = content.sat_orderclueid ? content.sat_orderclueid[1][0] : ''
  293. _Http.basic({
  294. "id": "2026030916370001",
  295. content
  296. }).then(res => {
  297. this.setData({
  298. loading: false
  299. })
  300. console.log("创建客户", res)
  301. if (res.code == 1) {
  302. if (this.data.selectMode) {
  303. // 选择模式下,创建客户后返回并设置客户信息
  304. // 这里需要获取客户详情,因为创建成功后只返回了客户ID
  305. _Http.basic({
  306. "id": "2026030916272601",
  307. "content": {
  308. "sa_customersid": res.data
  309. }
  310. }).then(customerRes => {
  311. if (customerRes.code == 1) {
  312. const customerInfo = customerRes.data[0];
  313. // 调用全局回调函数,设置客户信息
  314. if (getApp().globalData.setCustomer) {
  315. getApp().globalData.setCustomer(customerInfo);
  316. }
  317. // 返回上一页
  318. wx.navigateBack({
  319. delta: 2,
  320. success: (result) => {
  321. wx.showToast({
  322. title: "创建成功",
  323. icon: "none"
  324. })
  325. },
  326. })
  327. }
  328. });
  329. } else if (content.sa_customersid == 0) {
  330. // 刷新线索相关页面
  331. const pages = getCurrentPages();
  332. const detailPage = pages.find(v => v.__route__ == 'CRM/lead/detail');
  333. const listPage = pages.find(v => v.__route__ == 'CRM/lead/index');
  334. if (detailPage) {
  335. detailPage.selectComponent("#FollowRecord").getList("", true);
  336. }
  337. if (listPage) {
  338. listPage.getList(true);
  339. }
  340. // 非选择模式,跳转到客户详情
  341. wx.redirectTo({
  342. url: '/CRM/customer/detail?id=' + res.data,
  343. success: (result) => {
  344. wx.showToast({
  345. title: "创建成功",
  346. icon: "none"
  347. })
  348. },
  349. })
  350. } else {
  351. // 编辑模式,返回上一页
  352. getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').getDetail()
  353. wx.navigateBack({
  354. success: (res) => {
  355. wx.showToast({
  356. title: "编辑成功",
  357. icon: "none"
  358. })
  359. },
  360. })
  361. }
  362. } else {
  363. wx.showToast({
  364. title: res.msg || "创建失败",
  365. icon: "none"
  366. })
  367. }
  368. })
  369. },
  370. interrupt({
  371. detail
  372. }) {
  373. // 处理表单中断事件
  374. },
  375. /* 表单必填项是否完成 */
  376. onConfirm({
  377. detail
  378. }) {
  379. this.setData({
  380. disabled: detail
  381. })
  382. },
  383. closePage() {
  384. wx.navigateBack({
  385. delta: 1
  386. });
  387. },
  388. // 是否显示全部
  389. onChange({
  390. detail
  391. }) {
  392. this.setData({
  393. showAll: detail
  394. })
  395. }
  396. });