index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. isNew: false, //是否为新增
  5. ownerid: null,
  6. ownertable: null,
  7. sys_datafollowupid: 0, //数据ID
  8. type: "",
  9. content: "",
  10. user: {}, //联系人
  11. actions: [{
  12. name: "上门拜访"
  13. }, {
  14. name: "电话拜访"
  15. }, {
  16. name: "微信联系"
  17. }, {
  18. name: "QQ联系"
  19. }],
  20. show: false
  21. },
  22. onLoad(options) {
  23. if (options.ownertable) {
  24. this.setData({
  25. ...options
  26. })
  27. };
  28. if (!options.sys_datafollowupid) this.initTemplate();
  29. },
  30. /* 初始化模板 */
  31. initTemplate() {
  32. _Http.basic({
  33. "id": 20220930121601,
  34. content: {
  35. type: this.data.type,
  36. content: this.data.content,
  37. ownerid: this.data.ownerid,
  38. ownertable: this.data.ownertable,
  39. sys_datafollowupid: this.data.sys_datafollowupid
  40. }
  41. }).then(res => {
  42. console.log("新增初始化模板", res)
  43. this.setData({
  44. sys_datafollowupid: res.data.sys_datafollowupid,
  45. isNew: true
  46. })
  47. })
  48. },
  49. openSelect() {
  50. this.setData({
  51. show: true
  52. })
  53. },
  54. onCancel() {
  55. this.setData({
  56. show: false
  57. })
  58. },
  59. onSelect({
  60. detail
  61. }) {
  62. this.setData({
  63. type: detail.name
  64. })
  65. this.onCancel();
  66. },
  67. onInput(e) {
  68. this.setData({
  69. content: e.detail.value
  70. })
  71. },
  72. selectUser() {
  73. let result = this.data.user.userid ? [this.data.user.userid] : [];
  74. wx.navigateTo({
  75. url: `/packageA/group/select?data=${JSON.stringify({
  76. ownertable:this.data.ownertable,
  77. ownerid:this.data.ownerid
  78. })}&radio=true&obj=true&result=${result}`,
  79. })
  80. },
  81. handelSubmit(arr) {
  82. wx.navigateBack();
  83. this.setData({
  84. user: arr[0]
  85. })
  86. },
  87. submit() {
  88. const content = {
  89. type: this.data.type,
  90. content: this.data.content,
  91. ownerid: this.data.ownerid,
  92. ownertable: this.data.ownertable,
  93. sys_datafollowupid: this.data.sys_datafollowupid
  94. };
  95. if (!content.content) return;
  96. _Http.basic({
  97. "id": 20220930121601,
  98. content
  99. }).then(res => {
  100. console.log("新增或编辑", res)
  101. if (res.msg != '成功') return wx.showToast({
  102. title: res.data,
  103. icon: "none"
  104. });
  105. wx.showToast({
  106. title: '保存成功',
  107. icon: "none"
  108. });
  109. setTimeout(() => {
  110. getCurrentPages().forEach(v => {
  111. //详情界面更新数据
  112. if (['packageA/setclient/modules/trace/detail/index'].includes(v.__route__)) v.getDetail();
  113. //列表页更新数据
  114. if (["packageA/setclient/modules/contacts/detail/index", "packageA/setclient/detail"].includes(v.__route__)) {
  115. let page = v.selectComponent("#Trace"),
  116. list = page.data.list,
  117. index = list.findIndex(value => value.sys_datafollowupid == res.data.sys_datafollowupid);
  118. if (index != -1) {
  119. //列表中存在说明是编辑,返回上一级页面并更新数据
  120. list[index] = res.data;
  121. page.setData({
  122. list
  123. });
  124. wx.navigateBack();
  125. } else {
  126. //列表中不存在说明是新增,返回上一级页面更新数据 并进入详情
  127. list.push(res.data);
  128. page.setData({
  129. list,
  130. "content.total": page.data.content.total + 1
  131. });
  132. wx.navigateBack();
  133. wx.navigateTo({
  134. url: `/packageA/setclient/modules/trace/detail/index?data=` + JSON.stringify({
  135. "sys_datafollowupid": res.data.sys_datafollowupid,
  136. "ownertable": this.data.ownertable,
  137. "ownerid": this.data.ownerid
  138. }),
  139. })
  140. }
  141. };
  142. });
  143. }, 300)
  144. })
  145. },
  146. })