addAndEditor.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. let _Http = getApp().globalData.http,
  2. count = null;
  3. Page({
  4. data: {
  5. loading: false,
  6. showAll: false,
  7. repetitionShow: false,
  8. repetitionList: [],
  9. isSubmit: false,
  10. oldcontactsid: 0,
  11. sys_phonebookid: 0,
  12. content: {
  13. "sa_customersid": 0, //新增是传0
  14. "sys_enterpriseid": 0, //合作企业档案ID,新增是传0,更新
  15. "sa_customerpoolid": 0, //客户池(公海池)ID,默认或没有的时候传0
  16. phonenumber: "",
  17. ispublic: 0, //是否为公海客户
  18. },
  19. disabled: true,
  20. countDown: "", //查重倒计时
  21. },
  22. onLoad(options) {
  23. let form = [{
  24. label: "医院名称",
  25. error: false,
  26. errMsg: "",
  27. type: "textarea",
  28. value: "",
  29. placeholder: "医院名称",
  30. valueName: "enterprisename",
  31. checking: "base",
  32. slot: "info",
  33. required: true
  34. }, {
  35. label: "医院类型",
  36. error: false,
  37. errMsg: "",
  38. type: "option",
  39. optionNmae: "customertypemx",
  40. optionType: "radio", //复选 radio 单选
  41. value: "",
  42. placeholder: "医院类型",
  43. valueName: "type",
  44. checking: "base",
  45. required: true
  46. }, {
  47. label: "省市县",
  48. error: false,
  49. errMsg: "",
  50. type: "region",
  51. value: [],
  52. placeholder: "所在地区",
  53. valueName: "region",
  54. required: true
  55. }, {
  56. label: "详细地址",
  57. error: false,
  58. errMsg: "",
  59. type: "textarea",
  60. value: "",
  61. placeholder: "详细地址",
  62. valueName: "address",
  63. checking: "base",
  64. required: false
  65. }, {
  66. label: "上级企业",
  67. error: false,
  68. errMsg: "",
  69. type: "route",
  70. url: "/packageA/select/setclient/select",
  71. value: "",
  72. params: {
  73. id: 20221012164402,
  74. valueKey: "sa_customersid",
  75. content: {
  76. nocache: true,
  77. "type": 1,
  78. "isExport": 0,
  79. isend: 0,
  80. "where": {
  81. "condition": "",
  82. "status": "", //状态
  83. "startdate": "",
  84. "enddate": ""
  85. },
  86. "sort": [{
  87. sortname: "默认",
  88. sorted: 1,
  89. sortid: 67,
  90. reversed: 0
  91. }]
  92. },
  93. },
  94. query: "&radio=true",
  95. placeholder: "选择上级企业",
  96. valueName: "parentid",
  97. checking: "base",
  98. required: false
  99. }]
  100. if (options.data) {
  101. let data = JSON.parse(options.data);
  102. form = form.map(v => {
  103. if (v.valueName != 'region') {
  104. v.value = data[v.valueName] || "";
  105. if (v.valueName == "grade") v.value = data[v.valueName] + "";
  106. } else {
  107. v.value = data.province ? [data.province, data.city, data.county] : []
  108. };
  109. return v
  110. })
  111. this.setData({
  112. disabled: false,
  113. content: {
  114. sa_customersid: data.sa_customersid,
  115. sys_enterpriseid: data.sys_enterpriseid,
  116. sa_customerpoolid: data.sa_customerpoolid,
  117. },
  118. form
  119. })
  120. }
  121. this.setData({
  122. form
  123. })
  124. getApp().globalData.Language.getLanguagePackage(this, options.data ? '编辑医院' : '新建医院');
  125. },
  126. /* 表单必填项是否完成 */
  127. onConfirm({
  128. detail
  129. }) {
  130. this.setData({
  131. disabled: detail
  132. })
  133. },
  134. // 是否显示全部
  135. onChange({
  136. detail
  137. }) {
  138. this.setData({
  139. showAll: detail
  140. })
  141. },
  142. /* 查询是否重复 */
  143. async queryRepetition(e) {
  144. let data = this.selectComponent("#Form").query();
  145. data.province = data.region[0] || "";
  146. data.city = data.region[1] || "";
  147. data.county = data.region[2] || "";
  148. let res = await this.handleQueryRepetition({
  149. sa_customersid: this.data.content.sa_customersid,
  150. ...data
  151. });
  152. console.log("查询重复", res)
  153. if (res.code != '1') return wx.showToast({
  154. title: res.msg,
  155. icon: "none"
  156. });
  157. this.setData({
  158. countDown: 6
  159. });
  160. count = setInterval(() => {
  161. let countDown = this.data.countDown;
  162. if (countDown == 0) {
  163. clearInterval(count);
  164. this.setData({
  165. countDown: ""
  166. })
  167. } else {
  168. countDown--;
  169. this.setData({
  170. countDown
  171. })
  172. }
  173. }, 1000)
  174. if (res.total == 0) {
  175. getApp().globalData.Language.showToast('未查询到疑似重复的客户信息')
  176. } else {
  177. wx.showToast({
  178. title: getApp().globalData.Language.getMapText('查询到') + res.total + getApp().globalData.Language.getMapText('条疑似重复客户信息'),
  179. icon: "none"
  180. })
  181. this.setData({
  182. repetitionShow: true,
  183. repetitionList: res.data.map(v => {
  184. v.chars = v.chars.reduce((acc, item) => ({
  185. ...acc,
  186. ...item
  187. }), {});
  188. return v
  189. })
  190. })
  191. }
  192. },
  193. /* 处理查重 */
  194. handleQueryRepetition(content) {
  195. return _Http.basic({
  196. "id": 20221208172002,
  197. content
  198. })
  199. },
  200. async submit() {
  201. let data = this.selectComponent("#Form").submit(),
  202. that = this;
  203. data.province = data.region[0] || "";
  204. data.city = data.region[1] || "";
  205. data.county = data.region[2] || "";
  206. let query = await this.handleQueryRepetition({
  207. sa_customersid: this.data.content.sa_customersid,
  208. ...data
  209. });
  210. if (query.total != 0) {
  211. wx.showModal({
  212. content: getApp().globalData.Language.joint([{
  213. t: 1,
  214. v: '查询到',
  215. }, {
  216. v: query.total,
  217. f: "“",
  218. r: "”"
  219. }, {
  220. t: 1,
  221. v: '条疑似重复客户信息,不可',
  222. r: " "
  223. }, {
  224. t: 1,
  225. v: this.data.content.sa_customersid == 0 ? '创建' : '编辑',
  226. r: " "
  227. }, {
  228. t: 1,
  229. v: '客户',
  230. }]),
  231. confirmText: that.data.language['确定'] || '我知道了',
  232. showCancel: false
  233. })
  234. this.setData({
  235. repetitionShow: true,
  236. repetitionList: query.data.map(v => {
  237. v.chars = v.chars.reduce((acc, item) => ({
  238. ...acc,
  239. ...item
  240. }), {});
  241. return v
  242. }),
  243. isSubmit: true
  244. })
  245. } else {
  246. this.handleSubmit();
  247. }
  248. },
  249. handleSubmit(tag = false) {
  250. this.setData({
  251. loading: true
  252. })
  253. let data = this.selectComponent("#Form").submit();
  254. data.province = data.region[0] || "";
  255. data.city = data.region[1] || "";
  256. data.county = data.region[2] || "";
  257. data.parentid = data.parentid[1] ? data.parentid[1][0] : 0;
  258. data.sa_agentsid = data.sa_agentsid[1] ? data.sa_agentsid[1][0] : 0;
  259. delete(data.region);
  260. try {
  261. data.contactsinfo = {
  262. "name": data.name,
  263. "telephone": "",
  264. "phonenumber": data.isTelephone == 0 ? data.phonenumber || '' : data.telephone1.join("-") || '',
  265. oldcontactsid: this.data.oldcontactsid,
  266. sys_phonebookid: this.data.sys_phonebookid || 0,
  267. }
  268. } catch (error) {
  269. }
  270. _Http.basic({
  271. "id": 20221012163902,
  272. "content": {
  273. ...this.data.content,
  274. ...data,
  275. }
  276. }).then(res => {
  277. this.setData({
  278. loading: false
  279. })
  280. console.log("新建医院", res)
  281. if (res.code != '1') return wx.showToast({
  282. title: res.msg,
  283. icon: "none"
  284. })
  285. getApp().globalData.Language.showToast('保存成功')
  286. //绑定疑似重复标签
  287. if (tag) _Http.basic({
  288. "id": 20220929090901,
  289. "content": {
  290. "ownertable": "sa_customers",
  291. "ownerid": res.data.sa_customersid,
  292. "datatag": ["疑似重复"]
  293. }
  294. })
  295. setTimeout(() => {
  296. getCurrentPages().forEach(v => {
  297. switch (v.__route__) {
  298. case 'packageA/setclient/index':
  299. v.getList(true);
  300. break;
  301. case 'packageA/setclient/detail':
  302. v.getDetail();
  303. v.selectComponent("#Contacts").getList(this.data.content.sa_customersid, true)
  304. wx.navigateBack()
  305. break;
  306. }
  307. })
  308. let pages = getCurrentPages();
  309. if (pages[pages.length - 2].__route__ == 'packageA/setclient/index') wx.redirectTo({
  310. url: '/packageA/setclient/detail?id=' + res.data.sa_customersid,
  311. })
  312. }, tag ? 500 : 300)
  313. })
  314. },
  315. })