telephoneFollowAdd.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. var util = require('../../../utils/util.js')
  2. const app = getApp();
  3. Page({
  4. data: {
  5. allDisabled:true,//有客户下拉时临时用来控制其他下拉不显示
  6. c_txt_Show:false,
  7. customerShow:false,
  8. customerNameList: [
  9. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  10. ],
  11. customerIndex:'',
  12. customerId:'',
  13. receiverNameList: [
  14. // {id: 56, name: "苗舒怡"},{id: 57, name: "颛孙洋洋"},{id: 58, name: "李涛"}
  15. ],
  16. receiverIndex:'',
  17. receiverId:'',
  18. nextNameList: [
  19. // {id: 222, name: "拜访"}, {id: 223, name: "远程服务"}, {id: 224, name: "现场服务"}
  20. ],
  21. nextIndex:'',
  22. nextId:'',
  23. groupId: '',
  24. groupName: '',
  25. typeNameList: [
  26. // {id: 225, name: "定时回访",checked:true,disabled:false},
  27. // {id: 226, name: "服务回访",checked:false,disabled:false},
  28. // {id: 227, name: "投诉回访",checked:false,disabled:false}
  29. ],
  30. receiverShow:false,
  31. r_txt_Show:false,
  32. receiverChoose:'false',
  33. telephone:"",
  34. rules: {
  35. customerName: [{ required: true, message: '客户必填', trigger: 'blur' }],
  36. tdate: [{ required: true, message: '日期必填', trigger: 'blur' }],
  37. visiterName: [{ required: true, message: '回访人必填', trigger: 'blur' }],
  38. receiverName: [{ required: true, message: '被回访人必填', trigger: 'blur' }],
  39. receiverTel: [{ required: true, message: '电话必填', trigger: 'blur' }],
  40. typeIdsArr: [{ required: true, message: '回访类型必填', trigger: 'blur' }],
  41. statusName: [{ required: true, message: '回访状态必填', trigger: 'blur' }],
  42. content: [{ required: true, message: '情况说明必填', trigger: 'blur' }],
  43. },
  44. // 新增/编辑
  45. create: {
  46. dialogStatus: '',
  47. temp: {
  48. customerId: '',
  49. customerName: '',
  50. groupId: '',
  51. groupName: '',
  52. tdate: util.getToday(),
  53. visiterId: '',
  54. visiterName: '',
  55. receiverId: '',
  56. receiverName: '',
  57. receiverTel: '',
  58. remark: '',
  59. content: '',
  60. nextId: '',
  61. nextName: '',
  62. statusName: '',
  63. typeIdsArr:'',
  64. typeIds:'',
  65. created: util.getToday(),
  66. receiverChoose: 'true'
  67. },
  68. }
  69. },
  70. onLoad: function (options) {
  71. // 表单初始化
  72. wx.lin.initValidateForm(this)
  73. console.log(app.globalData.g_lgName)
  74. this.setData({
  75. ['create.temp.visiterId']: app.globalData.g_userId,
  76. ['create.temp.visiterName']: app.globalData.g_lgName
  77. })
  78. //客户下拉
  79. //util.getDataByName({ name:'getCustomerSelect',parammaps: {} }, this.getPickerList1)
  80. //下一步
  81. util.getDataByName({ name: 'getDictListSelect4', parammaps: { "pid": "55" } }, this.getPickerList3)
  82. //回访类型
  83. util.getDataByName({ name: 'getDictListSelect2', parammaps: { "pid": "56" } }, this.getPickerList4)
  84. },
  85. getPickerList1: function (res) {
  86. console.log('客户下拉数据======>', res.data.list)
  87. var customerNameList = res.data.list
  88. this.setData({
  89. customerShow:true,
  90. allDisabled:false,
  91. customerNameList: customerNameList
  92. })
  93. if(customerNameList !== null){
  94. this.setData({c_txt_Show:false})
  95. } else {
  96. this.setData({c_txt_Show:true})
  97. }
  98. },
  99. // getPickerList2: function (res) {
  100. // console.log('被回访人下拉数据======>', res.data.list)
  101. // this.setData({
  102. // receiverNameList: res.data.list
  103. // })
  104. // },
  105. getPickerList3: function (res) {
  106. console.log('下一步下拉数据======>', res.data.list)
  107. this.setData({
  108. nextNameList: res.data.list
  109. })
  110. },
  111. getPickerList4: function (res) {
  112. console.log('回访类型下拉数据======>', res.data.list)
  113. res.data.list.map(function(i){
  114. return i.checked = false
  115. })
  116. res.data.list.map(function(i){
  117. return i.disabled = false
  118. })
  119. this.setData({
  120. typeNameList: res.data.list
  121. })
  122. },
  123. //客户文本框输入
  124. change_customer_input:function(e){
  125. var value =e.detail.value
  126. console.log(value)
  127. //客户列表框
  128. util.getDataByName({ name:'getCustomerNameFuzzy',parammaps: {"inputvalue":value} }, this.getPickerList1)
  129. },
  130. //客户列表点击
  131. on_cust_tap: function (e) {
  132. console.log("客户列表点击")
  133. var newId = e.currentTarget.dataset.id;
  134. var name = e.currentTarget.dataset.name;
  135. var that = this
  136. this.setData({
  137. customerShow:false,
  138. allDisabled:true,
  139. customerId: newId,
  140. ['create.temp.customerName']: name,
  141. ['create.temp.customerId']: newId,
  142. })
  143. //获取集团
  144. util.getDataByName({name: 'getgroupNameById',returntype: 'Map',parammaps: { id: newId }
  145. }, function(e){
  146. var groupId = e.data.list[0].groupId
  147. var groupName = e.data.list[0].groupName
  148. that.setData({
  149. ['create.temp.groupName']: groupName,
  150. ['create.temp.groupId']: groupId,
  151. groupName: groupName,
  152. groupId: groupId
  153. })
  154. })
  155. //获取被回访人
  156. //util.getDataByName({name: 'getContacts',returntype: 'Map',parammaps: { customerId: newId }}, this.getPickerList2)
  157. },
  158. // //下拉框:客户
  159. // change_customer:function(e){
  160. // var that = this
  161. // console.log('customer的选项', e.detail.value)
  162. // var newId = this.data.customerNameList[e.detail.value]['id']
  163. // this.setData({
  164. // customerIndex: e.detail.value,
  165. // customerId: newId,
  166. // ['create.temp.customerId']: newId,
  167. // })
  168. // //获取集团
  169. // util.getDataByName({name: 'getgroupNameById',returntype: 'Map',parammaps: { id: newId }
  170. // }, function(e){
  171. // var groupId = e.data.list[0].groupId
  172. // var groupName = e.data.list[0].groupName
  173. // that.setData({
  174. // ['create.temp.groupName']: groupName,
  175. // ['create.temp.groupId']: groupId,
  176. // groupName: groupName,
  177. // groupId: groupId
  178. // })
  179. // })
  180. // //获取被回访人
  181. // util.getDataByName({name: 'getContacts',returntype: 'Map',parammaps: { customerId: newId }}, this.getPickerList2)
  182. // },
  183. //接待人文本框输入
  184. change_receiver_input:function(e){
  185. var value =e.detail.value
  186. var customerId = this.data.customerId
  187. console.log(value)
  188. //接待人列表框
  189. util.getDataByName({ name:'getContactsByNameApp',parammaps: {"customerId":customerId,"contactName":value,} }, this.getPickerList2)
  190. },
  191. getPickerList2: function (res) {
  192. console.log('接待人下拉数据======>', res.data.list)
  193. var receiverNameList = res.data.list
  194. this.setData({
  195. receiverShow:true,
  196. allDisabled:false,
  197. receiverNameList: receiverNameList
  198. })
  199. if(receiverNameList !== null){
  200. this.setData({r_txt_Show:false})
  201. } else {
  202. this.setData({r_txt_Show:true})
  203. }
  204. },
  205. //接待人列表点击
  206. on_rece_tap: function (e) {
  207. console.log("接待人列表点击")
  208. var newId = e.currentTarget.dataset.id;
  209. var name = e.currentTarget.dataset.name;
  210. var that = this
  211. this.setData({
  212. receiverShow:false,
  213. allDisabled:true,
  214. ['create.temp.receiverName']: name,
  215. ['create.temp.receiverId']: newId,
  216. receiverChoose: 'true'
  217. })
  218. //获取电话
  219. util.getDataByName({name: 'getTelById',returntype: 'Map',parammaps: { id: newId }
  220. }, function(e){
  221. console.log(e)
  222. var telephone = e.data.list[0].telephone
  223. that.setData({
  224. ['create.temp.receiverTel']: telephone,
  225. telephone: telephone
  226. })
  227. })
  228. },
  229. //接待人完成
  230. confirm_receiver_input:function(e){
  231. console.log("接收人直接输入")
  232. this.setData({
  233. receiverShow:false,
  234. allDisabled:true,
  235. receiverChoose: 'false'
  236. })
  237. },
  238. //日期选择触发
  239. on_tdate_tap:function(e){
  240. this.setData({
  241. ['create.temp.tdate']:e.detail.value
  242. })
  243. },
  244. //下拉框:被回访人
  245. change_receiver:function(e){
  246. console.log('receiver的选项', e.detail.value)
  247. var newId = this.data.receiverNameList[e.detail.value]['id']
  248. this.setData({
  249. receiverIndex: e.detail.value,
  250. receiverId: newId,
  251. ['create.temp.receiverId']: newId,
  252. })
  253. },
  254. //多选:回访类型
  255. change_typeName:function(e){
  256. const status = e.detail.checked
  257. const id = e.detail.key
  258. var typeNameList = this.data.typeNameList
  259. typeNameList.map(function(i){
  260. if(i.id == id){
  261. return i.checked = status
  262. }
  263. })
  264. this.setData({
  265. typeNameList:typeNameList
  266. })
  267. },
  268. //下拉框:下一步计划
  269. change_next:function(e){
  270. console.log('next的选项', e.detail.value)
  271. var newId = this.data.nextNameList[e.detail.value]['id']
  272. this.setData({
  273. nextIndex: e.detail.value,
  274. nextId: newId,
  275. ['create.temp.nextId']: newId,
  276. })
  277. },
  278. //保存
  279. submit:function(e){
  280. var detail_value = e.detail.values
  281. var detail_errors = e.detail.errors
  282. var detail_errors = e.detail.errors
  283. console.log("detail_value",detail_value)
  284. console.log("create.temp",this.data.create.temp)
  285. const submit_data = Object.assign({}, this.data.create.temp, detail_value)
  286. const typeNameList = this.data.typeNameList
  287. console.log("保存发送:",submit_data)
  288. console.log("保存typeNameList:",typeNameList)
  289. var typeIdsArr = []
  290. typeNameList.forEach(function(i){
  291. if(i.checked == true){
  292. typeIdsArr.push(i.id)
  293. }
  294. })
  295. var typeIds = typeIdsArr.join(",")
  296. console.log("typeIds",typeIds)
  297. submit_data.typeIds = typeIds
  298. submit_data.createrId = app.globalData.g_createrId
  299. submit_data.receiverChoose = this.data.receiverChoose
  300. var send_data = {
  301. "common": { "returnmap": "0" },
  302. "data": [
  303. {
  304. "name": "insertContactsNewApp", "type": "e",
  305. "parammaps": {
  306. "customerId":submit_data.customerId,
  307. "contactName": submit_data.receiverName,
  308. "telephone": submit_data.receiverTel,
  309. "address": "",
  310. "remark": submit_data.remark,
  311. "receiverChoose": this.data.receiverChoose
  312. }
  313. },
  314. {
  315. "name": "insertTelvisitApp",
  316. "resultmaps": {
  317. "list": [submit_data]
  318. },
  319. "children": [{
  320. "name": "insertTelvisitApp",
  321. "type": "e",
  322. "parammaps": {
  323. "customerId": "@insertTelvisitApp.customerId",
  324. "groupId": "@insertTelvisitApp.groupId",
  325. "tdate": "@insertTelvisitApp.tdate",
  326. "visiterId": "@insertTelvisitApp.visiterId",
  327. "receiverName": "@insertTelvisitApp.receiverName",
  328. "receiverTel": "@insertTelvisitApp.receiverTel",
  329. "typeIds": "@insertTelvisitApp.typeIds",
  330. "statusName": "@insertTelvisitApp.statusName",
  331. "remark": "@insertTelvisitApp.remark",
  332. "content": "@insertTelvisitApp.content",
  333. "nextId": "@insertTelvisitApp.nextId",
  334. "createrId": "@insertTelvisitApp.createrId"
  335. }
  336. }]
  337. }
  338. ]
  339. }
  340. console.log('send_data',JSON.stringify(send_data))
  341. //验证必填项是否为空
  342. if(submit_data.customerId == ""){
  343. wx.showToast({title: '客户名称必填',icon: 'none',duration: 2000})
  344. } else if(submit_data.tdate == ""){
  345. wx.showToast({title: '回访日期必填',icon: 'none',duration: 2000})
  346. } else if(submit_data.receiverName == ""){
  347. wx.showToast({title: '被回访人必填',icon: 'none',duration: 2000})
  348. } else if(submit_data.receiverTel == ""){
  349. wx.showToast({title: '被回访人电话必填',icon: 'none',duration: 2000})
  350. } else if(submit_data.typeIds == ""){
  351. wx.showToast({title: '回访类型必填',icon: 'none',duration: 2000})
  352. } else if(submit_data.statusName == ""){
  353. wx.showToast({title: '回访状态必填',icon: 'none',duration: 2000})
  354. } else if(submit_data.content == ""){
  355. wx.showToast({title: '情况说明必填',icon: 'none',duration: 2000})
  356. } else {
  357. if( wx.getStorageSync('isLoading') == "true"){
  358. wx.showToast({
  359. title: '正在保存中,请稍等!',
  360. icon: 'none',
  361. duration: 2000
  362. })
  363. } else {
  364. util.execDataByConfig(send_data, this.getListSuccess)
  365. }
  366. }
  367. },
  368. getListSuccess: function (res) {
  369. console.log('table数据======>', res)
  370. if (res.msg !== 'fail') {
  371. wx.showToast({
  372. title: '保存成功',
  373. icon: 'success',
  374. duration: 2000,
  375. success: function(){
  376. wx.redirectTo({ url:"../telephoneFollow/telephoneFollow"})
  377. }
  378. })
  379. } else {
  380. wx.showToast({
  381. title: '保存失败'+res.data,
  382. icon: 'error',
  383. duration: 2000,
  384. })
  385. }
  386. },
  387. onReady: function () {
  388. },
  389. onShow: function () {
  390. },
  391. onHide: function () {
  392. },
  393. onUnload: function () {
  394. },
  395. /**
  396. * 页面相关事件处理函数--监听用户下拉动作
  397. */
  398. onPullDownRefresh: function () {
  399. },
  400. /**
  401. * 页面上拉触底事件的处理函数
  402. */
  403. onReachBottom: function () {
  404. },
  405. onShareAppMessage: function () {
  406. }
  407. })