reportForms.js 7.0 KB

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