project.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. year: new Date().getFullYear(),
  5. content: {
  6. "year": new Date().getFullYear(),
  7. "hrid": wx.getStorageSync('userMsg').hrid,
  8. "pageNumber": 1,
  9. "pageTotal": 1,
  10. "pageSize": 20,
  11. "where": {
  12. "condition": ""
  13. },
  14. },
  15. projectList: []
  16. },
  17. onLoad(options) {
  18. this.setData({
  19. year: options.year,
  20. 'content.year': options.year
  21. })
  22. this.getList();
  23. this.getProjectList();
  24. },
  25. /* 添加项目 */
  26. getResult({
  27. detail
  28. }) {
  29. let project = [];
  30. detail.forEach(v => {
  31. let data = this.data.projectList.find(value => value.sa_projectid == v);
  32. project.push({
  33. "target_l": '',
  34. "target_h": '',
  35. "month": '',
  36. ...data
  37. })
  38. });
  39. wx.navigateTo({
  40. url: './addProject?data=' + JSON.stringify(project) + '&year=' + this.data.year,
  41. })
  42. },
  43. /* 选择年份 */
  44. bindDateChange({
  45. detail
  46. }) {
  47. if (this.data.year == detail.value) return;
  48. this.setData({
  49. "year": detail.value,
  50. "content.year": detail.value
  51. });
  52. this.getList(true);
  53. },
  54. getList(init = false) {
  55. //init 用于初始化分页
  56. if (init.detail != undefined) init = init.detail;
  57. if (init) this.setData({
  58. ['content.pageNumber']: 1
  59. })
  60. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  61. _Http.basic({
  62. "id": 20220906104002,
  63. "content": this.data.content
  64. }).then(res => {
  65. if (res.msg != '成功') return wx.showToast({
  66. title: res.data,
  67. icon: "none"
  68. })
  69. this.setData({
  70. list: res.data,
  71. 'content.pageNumber': res.pageNumber + 1,
  72. 'content.pageTotal': res.pageTotal,
  73. total: res.total
  74. })
  75. })
  76. },
  77. getProjectList() {
  78. _Http.basic({
  79. "id": 20220905151902,
  80. "content": {
  81. pageSize: 99999,
  82. "where": {
  83. "condition": ""
  84. }
  85. },
  86. }).then(res => {
  87. if (res.msg != '成功') return wx.showToast({
  88. title: res.data,
  89. icon: "none"
  90. })
  91. this.setData({
  92. projectList: res.data
  93. })
  94. })
  95. },
  96. /* 删除项目 */
  97. deleteItem(e) {
  98. const {
  99. item
  100. } = e.currentTarget.dataset,
  101. that = this;
  102. wx.showModal({
  103. title: '提示',
  104. content: `是否确认删除${item.projectname}`,
  105. success({
  106. confirm
  107. }) {
  108. if (confirm) {
  109. _Http.basic({
  110. "id": 20220905165302,
  111. "content": {
  112. "sa_salestargetid": [
  113. item.sa_salestargetid
  114. ]
  115. },
  116. }).then(res => {
  117. if (res.msg != '成功') return wx.showToast({
  118. title: res.data,
  119. icon: "none"
  120. })
  121. that.setData({
  122. list: that.data.list.filter(v => v.sa_salestargetid != item.sa_salestargetid)
  123. })
  124. wx.showToast({
  125. title: '删除成功',
  126. icon: "none"
  127. })
  128. })
  129. }
  130. }
  131. })
  132. },
  133. /* 开启添加项目 */
  134. addProject() {
  135. this.selectComponent("#Plist").setData({
  136. show: true
  137. })
  138. },
  139. onReachBottom() {
  140. this.getList();
  141. },
  142. onShareAppMessage() {}
  143. })