index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/matchingFeilType");
  3. Component({
  4. data: {
  5. viewIndex: 0,
  6. sa_salesforecastbillid: 0,
  7. "content": {
  8. nocache: true,
  9. pageSize: 999,
  10. total: null,
  11. "where": {
  12. "condition": ""
  13. }
  14. },
  15. param: {
  16. "id": 20220906154703,
  17. "version": 1,
  18. "content": {
  19. nocache: true,
  20. "sa_salesforecastbillid": "",
  21. pageNumber: 1,
  22. pageTotal: 1,
  23. "where": {
  24. "condition": "",
  25. "sa_projectid": ""
  26. }
  27. }
  28. },
  29. productList: [], //产品列表
  30. },
  31. methods: {
  32. /* 获取产品列表 */
  33. getList(id) {
  34. let content = this.data.content;
  35. content.sa_salesforecastbillid = id;
  36. _Http.basic({
  37. "id": "20220916115203",
  38. "version": 1,
  39. content
  40. }).then(res => {
  41. console.log("项目清单", res)
  42. if (res.msg != '成功') return wx.showToast({
  43. title: res.data,
  44. icon: "none"
  45. })
  46. this.setData({
  47. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  48. "content.total": res.total,
  49. sa_salesforecastbillid: id
  50. });
  51. if (res.data.length) {
  52. this.setData({
  53. 'param.content.where.sa_projectid': res.data[0].sa_projectid,
  54. 'param.content.sa_salesforecastbillid': id,
  55. })
  56. this.getProduct(true);
  57. }
  58. })
  59. },
  60. /* 获取产品清单 */
  61. getProduct(init = false) {
  62. let param = this.data.param;
  63. if (init) param.content.pageNumber = 1;
  64. if (param.content.pageNumber > param.content.pageTotal) return;
  65. _Http.basic(param).then(res => {
  66. console.log("产品列表", res)
  67. if (res.msg != '成功') return wx.showToast({
  68. title: res.msg,
  69. icon: "none"
  70. });
  71. if (res.data.length == 1 && !res.data[0].itemname) {
  72. res.data = []
  73. } else {
  74. res.data = res.data.map(value => {
  75. if (value.attinfos.length != 0) {
  76. value.attinfos = file.fileList(value.attinfos)
  77. let image = value.attinfos.find(v => v.fileType == "image");
  78. value.cover = image ? image.cover : "";
  79. }
  80. // value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
  81. // value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
  82. return value;
  83. })
  84. }
  85. this.setData({
  86. productList: res.pageNumber == 1 ? res.data : this.data.productList.concat(res.data),
  87. "param.content.pageNumber": res.pageNumber + 1,
  88. "param.content.pageTotal": res.pageTotal,
  89. })
  90. })
  91. },
  92. /* 切换tab */
  93. onChange(e) {
  94. this.setData({
  95. "param.content.where.sa_projectid": e.detail.name,
  96. viewIndex: e.detail.index,
  97. });
  98. this.getProduct(true);
  99. },
  100. /* 添加产品 */
  101. addProduct() {
  102. wx.navigateTo({
  103. url: `/packageA/select/product/select?params=${JSON.stringify({
  104. id: 20221208105403,
  105. version: 1,
  106. model:'#Project',
  107. content: {
  108. nocache:true,
  109. sa_projectid: this.data.param.content.where.sa_projectid,
  110. sa_salesforecastbillid: this.data.sa_salesforecastbillid,
  111. pageSize: 20,
  112. pageNumber: 1,
  113. pageTotal: 1
  114. }
  115. })}`
  116. })
  117. },
  118. handleSelectProduct(itemclassinfos, oldList) {
  119. const that = this,
  120. page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
  121. wx.showModal({
  122. title: '提示',
  123. content: '是否确认添加产品',
  124. complete: ({
  125. confirm
  126. }) => {
  127. if (confirm) _Http.basic({
  128. "id": 20220906155003,
  129. "version": 1,
  130. "content": {
  131. "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
  132. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  133. "sa_projectid": that.data.param.content.where.sa_projectid,
  134. itemclassinfos
  135. }
  136. }).then(res => {
  137. console.log("项目添加产品", res)
  138. wx.showToast({
  139. title: res.msg == '成功' ? '添加成功' : res.msg,
  140. icon: "none"
  141. })
  142. if (res.msg != '成功') return;
  143. setTimeout(() => {
  144. that.getProduct(true);
  145. wx.navigateBack();
  146. }, 300)
  147. })
  148. }
  149. })
  150. },
  151. /* 生成修改队列 */
  152. changeQueue({
  153. detail
  154. }) {
  155. const that = this,
  156. page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
  157. _Http.basic({
  158. "id": 20220906155003,
  159. "version": 1,
  160. "content": {
  161. "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
  162. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  163. "sa_projectid": that.data.param.content.where.sa_projectid,
  164. itemclassinfos: detail
  165. }
  166. }).then(res => {
  167. console.log("项目修改产品", res)
  168. if (res.msg != '成功') return wx.showToast({
  169. title: res.msg,
  170. icon: "none"
  171. })
  172. let index = that.data.productList.findIndex(v => v.sa_salesforecastid == detail[0].sa_salesforecastid);
  173. if (index != -1) that.data.productList[index] = {
  174. ...that.data.productList[index],
  175. ...detail[0]
  176. }
  177. that.setData({
  178. [`productList[${index}]`]: that.data.productList[index],
  179. [`productList[0].sumamount`]: res.data[0].sumamount,
  180. })
  181. console.log(that.data.productList[index])
  182. })
  183. },
  184. /* 删除 */
  185. deleteItem({
  186. detail
  187. }) {
  188. _Http.basic({
  189. "id": 20220906155103,
  190. "version": 1,
  191. "content": detail
  192. }).then(res => {
  193. console.log("删除产品", res);
  194. if (res.msg != '成功') return wx.showToast({
  195. title: res.msg,
  196. icon: "none"
  197. });
  198. this.setData({
  199. productList: this.data.productList.filter(v => v.sa_salesforecastid != detail.sa_salesforecastid)
  200. });
  201. wx.showToast({
  202. title: '删除成功',
  203. icon: "none"
  204. })
  205. })
  206. }
  207. }
  208. })