row.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. getApp().globalData.Language.getLanguagePackage(this, '订单明细');
  38. },
  39. getList(init = false) {
  40. let content = this.data.content;
  41. if (init.detail != undefined) init = init.detail;
  42. if (init) {
  43. content.pageNumber = 1;
  44. content.pageTotal = 1;
  45. }
  46. if (content.pageNumber > content.pageTotal) return;
  47. _Http.basic({
  48. "id": 20230705145004,
  49. content
  50. }).then(res => {
  51. console.log("订单行列表", res)
  52. this.selectComponent('#ListBox').RefreshToComplete();
  53. this.selectComponent("#ListBox").setHeight(".total", this);
  54. if (res.code != '1') return wx.showToast({
  55. title: res.msg,
  56. icon: "none"
  57. })
  58. content.pageNumber = res.pageNumber + 1;
  59. content.pageTotal = res.pageTotal;
  60. let list = res.data.map(v => {
  61. v.showmarketprice = CNY(v.marketprice)
  62. v.showdefaultprice = CNY(v.defaultprice)
  63. v.showdefaultamount = CNY(v.defaultamount)
  64. v.showprice = CNY(v.price)
  65. v.showamount = CNY(v.amount)
  66. return v
  67. })
  68. this.setData({
  69. list: res.pageNumber == 1 ? list : this.data.list.concat(list)
  70. })
  71. })
  72. },
  73. startSearch({
  74. detail
  75. }) {
  76. this.data.content.where.condition = detail;
  77. this.getList(true)
  78. },
  79. onClear() {
  80. this.data.content.where.condition = '';
  81. this.getList(true)
  82. },
  83. toAdd() {
  84. getApp().globalData.handleSelect = this.onInsert.bind(this);
  85. wx.navigateTo({
  86. url: `/packageA/invoiceforecast/modules/orderForm/select?ids=${
  87. JSON.stringify({
  88. sa_salesforecastprojectid:this.data.content.sa_salesforecastprojectid,
  89. sa_orderid:this.data.sa_orderid
  90. })
  91. }`,
  92. })
  93. },
  94. updated() {
  95. let content = JSON.parse(JSON.stringify(this.data.content));
  96. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  97. content.pageNumber = 1;
  98. _Http.basic({
  99. "id": 20230705145004,
  100. content
  101. }).then(res => {
  102. console.log("订单行列表", res)
  103. this.selectComponent('#ListBox').RefreshToComplete();
  104. this.selectComponent("#ListBox").setHeight(".total", this);
  105. if (res.code != '1') return wx.showToast({
  106. title: res.msg,
  107. icon: "none"
  108. })
  109. let list = res.data.map(v => {
  110. v.showmarketprice = CNY(v.marketprice)
  111. v.showdefaultprice = CNY(v.defaultprice)
  112. v.showdefaultamount = CNY(v.defaultamount)
  113. v.showprice = CNY(v.price)
  114. v.showamount = CNY(v.amount)
  115. return v
  116. })
  117. this.setData({
  118. list
  119. })
  120. })
  121. },
  122. onInsert(list) {
  123. let that = this;
  124. wx.showModal({
  125. title: getApp().globalData.Language.getMapText('提示'),
  126. content: getApp().globalData.Language.joint([{
  127. t: 1,
  128. v: '是否确认添加',
  129. r: " "
  130. }, {
  131. v: list.length,
  132. r: " "
  133. }, {
  134. t: 1,
  135. v: '件产品',
  136. r: "?"
  137. }]),
  138. cancelText: getApp().globalData.Language.getMapText('取消'),
  139. confirmText: getApp().globalData.Language.getMapText('确定'),
  140. complete: ({
  141. confirm
  142. }) => {
  143. if (confirm) that.handleChange(list).then(res => {
  144. if (res.code != '1') return;
  145. this.updated();
  146. setTimeout(() => {
  147. wx.navigateBack()
  148. }, 800)
  149. })
  150. }
  151. })
  152. },
  153. handleChange(list) {
  154. return new Promise((resolve, reject) => {
  155. _Http.basic({
  156. "id": 20230705145204,
  157. "content": {
  158. "sa_salesforecastbillid": this.data.content.sa_salesforecastbillid,
  159. "sa_salesforecastprojectid": this.data.content.sa_salesforecastprojectid,
  160. "salesforecast": list.map(v => {
  161. return {
  162. "sa_salesforecastid": v.sa_salesforecastid || 0,
  163. "sa_orderitemsid": v.sa_orderitemsid,
  164. "deliverydate": v.plandeliverydate || v.deliverydate || ''
  165. }
  166. })
  167. },
  168. }).then(res => {
  169. console.log("设置产品", res)
  170. resolve(res)
  171. if (res.code != '1') wx.showToast({
  172. title: res.msg,
  173. icon: "none",
  174. mask: true
  175. });
  176. })
  177. })
  178. },
  179. pickerOnChange(e) {
  180. let value = e.detail.value,
  181. index = e.currentTarget.dataset.index;
  182. if (this.data.list[index].deliverydate == value) return;
  183. this.data.list[index].plandeliverydate = value;
  184. this.handleChange([this.data.list[index]]).then(res => {
  185. if (res.code == '1') {
  186. getApp().globalData.Language.showToast('设置成功')
  187. this.setData({
  188. [`list[${index}].plandeliverydate`]: value
  189. })
  190. }
  191. })
  192. },
  193. deleteItem({
  194. detail
  195. }) {
  196. let that = this;
  197. wx.showModal({
  198. title: getApp().globalData.Language.getMapText('提示'),
  199. content: getApp().globalData.Language.getMapText('是否确定删除') + `${detail.itemname}`,
  200. cancelText: getApp().globalData.Language.getMapText('取消'),
  201. confirmText: getApp().globalData.Language.getMapText('确定'),
  202. complete: ({
  203. confirm
  204. }) => {
  205. if (confirm) _Http.basic({
  206. "id": 20230705145404,
  207. "content": {
  208. "sa_salesforecastprojectid": this.data.content.sa_salesforecastprojectid,
  209. "sa_salesforecastbillid": that.data.content.sa_salesforecastbillid,
  210. "sa_salesforecastids": [detail.sa_salesforecastid]
  211. },
  212. }).then(res => {
  213. console.log("删除订单行", res)
  214. wx.showToast({
  215. title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg,
  216. icon: "none"
  217. })
  218. if (res.code == '1') that.updated();
  219. })
  220. }
  221. })
  222. },
  223. onUnload() {
  224. getCurrentPages()[getCurrentPages().length - 2].partialRenewal(true)
  225. }
  226. })