row.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. list: [],
  10. content: {
  11. nocache: true,
  12. "sa_salesforecastprojectid": 0,
  13. "sa_salesforecastbillid": 0,
  14. "pageSize": 20,
  15. "where": {
  16. "condition": ""
  17. }
  18. },
  19. disabled: false
  20. },
  21. onLoad(options) {
  22. let {
  23. periodend,
  24. periodstart,
  25. sa_salesforecastbillid
  26. } = getCurrentPages()[getCurrentPages().length - 2].data.detail;
  27. this.setData({
  28. "content.sa_salesforecastprojectid": options.id,
  29. sa_orderid: options.sa_orderid,
  30. disabled: options.disabled == 'true',
  31. "content.sa_salesforecastbillid": sa_salesforecastbillid,
  32. periodend,
  33. periodstart,
  34. unoutamount: options.unoutamount
  35. });
  36. this.getList(true)
  37. },
  38. getList(init = false) {
  39. let content = this.data.content;
  40. if (init.detail != undefined) init = init.detail;
  41. if (init) {
  42. content.pageNumber = 1;
  43. content.pageTotal = 1;
  44. }
  45. if (content.pageNumber > content.pageTotal) return;
  46. _Http.basic({
  47. "id": 20230705145004,
  48. content
  49. }).then(res => {
  50. console.log("订单行列表", res)
  51. this.selectComponent('#ListBox').RefreshToComplete();
  52. this.selectComponent("#ListBox").setHeight(".total", this);
  53. if (res.msg != '成功') return wx.showToast({
  54. title: res.msg,
  55. icon: "none"
  56. })
  57. content.pageNumber = res.pageNumber + 1;
  58. content.pageTotal = res.pageTotal;
  59. let list = res.data.map(v => {
  60. v.showmarketprice = CNY(v.marketprice)
  61. v.showdefaultprice = CNY(v.defaultprice)
  62. v.showdefaultamount = CNY(v.defaultamount)
  63. v.showprice = CNY(v.price)
  64. v.showamount = CNY(v.amount)
  65. return v
  66. })
  67. this.setData({
  68. list: res.pageNumber == 1 ? list : this.data.list.concat(list)
  69. })
  70. })
  71. },
  72. startSearch({
  73. detail
  74. }) {
  75. this.data.content.where.condition = detail;
  76. this.getList(true)
  77. },
  78. onClear() {
  79. this.data.content.where.condition = '';
  80. this.getList(true)
  81. },
  82. toAdd() {
  83. getApp().globalData.handleSelect = this.onInsert.bind(this);
  84. wx.navigateTo({
  85. url: `/packageA/invoiceforecast/modules/orderForm/select?ids=${
  86. JSON.stringify({
  87. sa_salesforecastprojectid:this.data.content.sa_salesforecastprojectid,
  88. sa_orderid:this.data.sa_orderid
  89. })
  90. }`,
  91. })
  92. },
  93. updated() {
  94. let content = JSON.parse(JSON.stringify(this.data.content));
  95. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  96. content.pageNumber = 1;
  97. _Http.basic({
  98. "id": 20230705145004,
  99. content
  100. }).then(res => {
  101. console.log("订单行列表", res)
  102. this.selectComponent('#ListBox').RefreshToComplete();
  103. this.selectComponent("#ListBox").setHeight(".total", this);
  104. if (res.msg != '成功') return wx.showToast({
  105. title: res.msg,
  106. icon: "none"
  107. })
  108. let list = res.data.map(v => {
  109. v.showmarketprice = CNY(v.marketprice)
  110. v.showdefaultprice = CNY(v.defaultprice)
  111. v.showdefaultamount = CNY(v.defaultamount)
  112. v.showprice = CNY(v.price)
  113. v.showamount = CNY(v.amount)
  114. return v
  115. })
  116. this.setData({
  117. list
  118. })
  119. })
  120. },
  121. onInsert(list) {
  122. let that = this;
  123. wx.showModal({
  124. title: '提示',
  125. content: `是否确定添加${list.length}件产品?`,
  126. complete: ({
  127. confirm
  128. }) => {
  129. if (confirm) that.handleChange(list).then(res => {
  130. if (res.msg != '成功') return;
  131. this.updated();
  132. setTimeout(() => {
  133. wx.navigateBack()
  134. }, 800)
  135. })
  136. }
  137. })
  138. },
  139. handleChange(list) {
  140. return new Promise((resolve, reject) => {
  141. _Http.basic({
  142. "id": 20230705145204,
  143. "content": {
  144. "sa_salesforecastbillid": this.data.content.sa_salesforecastbillid,
  145. "sa_salesforecastprojectid": this.data.content.sa_salesforecastprojectid,
  146. "salesforecast": list.map(v => {
  147. return {
  148. "sa_salesforecastid": v.sa_salesforecastid || 0,
  149. "sa_orderitemsid": v.sa_orderitemsid,
  150. "deliverydate": v.plandeliverydate || v.deliverydate || ''
  151. }
  152. })
  153. },
  154. }).then(res => {
  155. console.log("设置产品", res)
  156. resolve(res)
  157. if (res.msg != '成功') wx.showToast({
  158. title: res.msg,
  159. icon: "none",
  160. mask: true
  161. });
  162. })
  163. })
  164. },
  165. pickerOnChange(e) {
  166. let value = e.detail.value,
  167. index = e.currentTarget.dataset.index;
  168. if (this.data.list[index].deliverydate == value) return;
  169. this.data.list[index].plandeliverydate = value;
  170. this.handleChange([this.data.list[index]]).then(res => {
  171. if (res.msg == '成功') {
  172. wx.showToast({
  173. title: '设置成功',
  174. icon: "none"
  175. });
  176. this.setData({
  177. [`list[${index}].plandeliverydate`]: value
  178. })
  179. }
  180. })
  181. },
  182. deleteItem({
  183. detail
  184. }) {
  185. let that = this;
  186. wx.showModal({
  187. title: '提示',
  188. content: `是否确定删除${detail.itemname}`,
  189. complete: ({
  190. confirm
  191. }) => {
  192. if (confirm) _Http.basic({
  193. "id": 20230705145404,
  194. "content": {
  195. "sa_salesforecastprojectid": this.data.content.sa_salesforecastprojectid,
  196. "sa_salesforecastbillid": that.data.content.sa_salesforecastbillid,
  197. "sa_salesforecastids": [detail.sa_salesforecastid]
  198. },
  199. }).then(res => {
  200. console.log("删除订单行", res)
  201. wx.showToast({
  202. title: res.msg == '成功' ? '删除成功' : res.msg,
  203. icon: "none"
  204. })
  205. if (res.msg == '成功') that.updated();
  206. })
  207. }
  208. })
  209. },
  210. onUnload() {
  211. getCurrentPages()[getCurrentPages().length - 2].partialRenewal(true)
  212. }
  213. })