telephoneFollowEdit.js 11 KB

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