reportForms.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. sourceData: null,
  5. isEdit: null,
  6. ProductList: null,
  7. disabled: false,
  8. loading: false
  9. },
  10. onLoad(options) {
  11. this.setData({
  12. sourceData: JSON.parse(options.item),
  13. isEdit: options.isEdit == 'true'
  14. })
  15. wx.setNavigationBarTitle({
  16. title: options.isEdit == 'true' ? '预测报表' : '预测填报',
  17. })
  18. this.getList();
  19. this.getProductList();
  20. },
  21. /* 提交 */
  22. submit() {
  23. if (this.data.disabled && this.data.loading) return;
  24. this.setData({
  25. loading: true
  26. })
  27. _Http.basic({
  28. "id": 20220906155003,
  29. "version": 1,
  30. "content": {
  31. "sa_salesforecastmodelid": this.data.sourceData.sa_salesforecastmodelid,
  32. "sa_salesforecastbillid": this.data.sourceData.sa_salesforecastbillid,
  33. "sa_projectid": this.data.sourceData.sa_projectid,
  34. "itemclassinfos": this.data.list
  35. }
  36. }).then(res => {
  37. this.setData({
  38. loading: false
  39. })
  40. if (res.msg != '成功') return wx.showToast({
  41. title: res.data,
  42. icon: "none"
  43. });
  44. this.setData({
  45. disabled: true
  46. })
  47. this.randerData()
  48. setTimeout(() => {
  49. wx.navigateBack({
  50. delta: 0,
  51. })
  52. }, 500)
  53. wx.showToast({
  54. title: '保存成功',
  55. icon: "none"
  56. });
  57. })
  58. },
  59. randerData() {
  60. let pages = getCurrentPages();
  61. pages[pages.length - 2].getList(true);
  62. },
  63. /* 获取列表 */
  64. getList() {
  65. let parem = {
  66. "id": 20220906154703,
  67. "version": 1,
  68. "content": {
  69. "nocheca": true,
  70. "sa_salesforecastbillid": this.data.sourceData.sa_salesforecastbillid,
  71. 'pageSize': 9999,
  72. "where": {}
  73. }
  74. };
  75. if (this.data.sourceData.sa_projectid != 0) parem.content.where = {
  76. "sa_projectid": this.data.sourceData.sa_projectid
  77. }
  78. _Http.basic(parem).then(res => {
  79. console.log(321321321,res)
  80. if (res.msg != '成功') return wx.showToast({
  81. title: res.msg,
  82. icon: "none"
  83. })
  84. for (let i = 0; i < res.data.length; i++) {
  85. res.data[i].complete = true;
  86. }
  87. this.setData({
  88. list: res.data.filter(v => v.itemclassname)
  89. });
  90. })
  91. },
  92. /* 获取产品列表 */
  93. getProductList() {
  94. _Http.basic({
  95. "id": 20220906154903,
  96. "version": 1,
  97. "content": {}
  98. }).then(res => {
  99. console.log("产品列表", res)
  100. if (res.msg != '成功') return wx.showToast({
  101. title: res.data,
  102. icon: "none"
  103. })
  104. this.setData({
  105. ProductList: res.data
  106. })
  107. })
  108. },
  109. /* 打开添加产品 */
  110. addProduct() {
  111. let list = this.data.ProductList.filter(v => !this.data.list.some(value => value.itemclassnum == v.itemclassnum))
  112. this.selectComponent('#Product').setData({
  113. show: true,
  114. list
  115. })
  116. },
  117. /* 得到添加产品 */
  118. getResult({
  119. detail
  120. }) {
  121. const list = detail.map(v => {
  122. const data = this.data.ProductList.find(value => value.itemclassnum == v);
  123. return {
  124. "sa_salesforecastid": 0,
  125. "itemclassnum": data.itemclassnum,
  126. "itemclassname": data.itemclassname,
  127. "orderqty": 0,
  128. "orderamount": 0,
  129. "invoiceqty": 0,
  130. "invoiceamount": 0,
  131. "outqty": 0,
  132. "outamount": 0,
  133. "complete": false
  134. }
  135. })
  136. this.setData({
  137. list: list.concat(this.data.list)
  138. });
  139. wx.pageScrollTo({
  140. scrollTop: 0,
  141. })
  142. this.isDisabled();
  143. },
  144. /* 输入框改变 */
  145. inputChange(e) {
  146. const {
  147. index,
  148. name
  149. } = e.currentTarget.dataset,
  150. value = e.detail.value.trim();
  151. this.setData({
  152. [`list[${index}].${name}`]: value
  153. })
  154. if (['orderamount', 'outamount', 'invoiceamount'].includes(name)) {
  155. const data = this.data.list[index];
  156. this.setData({
  157. [`list[${index}].complete`]: data.orderamount != "" && data.outamount != "" && data.invoiceamount != ""
  158. })
  159. };
  160. this.isDisabled();
  161. },
  162. /* 删除产品 */
  163. deleteProduct(e) {
  164. const {
  165. item
  166. } = e.currentTarget.dataset,
  167. that = this;
  168. wx.showModal({
  169. title: "提示",
  170. content: `是否确认删除${item.itemclassname}`,
  171. success({
  172. confirm
  173. }) {
  174. if (confirm) {
  175. if (item.sa_salesforecastid == 0) {
  176. that.setData({
  177. list: that.data.list.filter(v => v.itemclassnum != item.itemclassnum)
  178. })
  179. wx.showToast({
  180. title: '删除成功',
  181. icon: "none"
  182. })
  183. that.isDisabled();
  184. that.randerData()
  185. } else {
  186. _Http.basic({
  187. "id": 20220906155103,
  188. "version": 1,
  189. "content": {
  190. "sa_salesforecastid": item.sa_salesforecastid,
  191. "sa_projectid": 0,
  192. "sa_salesforecastbillid": item.sa_salesforecastbillid
  193. }
  194. }).then(res => {
  195. if (res.msg != '成功') return wx.showToast({
  196. title: res.data,
  197. icon: "none"
  198. });
  199. that.setData({
  200. list: that.data.list.filter(v => v.itemclassnum != item.itemclassnum)
  201. })
  202. that.isDisabled();
  203. that.randerData()
  204. wx.showToast({
  205. title: '删除成功',
  206. icon: "none"
  207. })
  208. })
  209. }
  210. }
  211. }
  212. })
  213. },
  214. /* 判断是否禁用保存按钮 */
  215. isDisabled() {
  216. let count = 0;
  217. this.data.list.forEach(v => v.complete ? count += 1 : '')
  218. this.setData({
  219. disabled: !(count == this.data.list.length)
  220. })
  221. },
  222. onShareAppMessage() {}
  223. })