project.js 4.5 KB

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