index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. viewIndex: 0
  56. })
  57. this.getProduct(true);
  58. }
  59. })
  60. },
  61. /* 获取产品清单 */
  62. getProduct(init = false) {
  63. let param = this.data.param;
  64. if (init) param.content.pageNumber = 1;
  65. if (param.content.pageNumber > param.content.pageTotal) return;
  66. _Http.basic(param).then(res => {
  67. console.log("产品列表", res)
  68. if (res.msg != '成功') return wx.showToast({
  69. title: res.msg,
  70. icon: "none"
  71. });
  72. if (res.data.length == 1 && !res.data[0].itemname) {
  73. res.data = []
  74. } else {
  75. res.data = res.data.map(value => {
  76. if (value.attinfos.length != 0) {
  77. value.attinfos = file.fileList(value.attinfos)
  78. let image = value.attinfos.find(v => v.fileType == "image");
  79. value.cover = image ? image.cover : "";
  80. }
  81. value.className = [];
  82. value.brandName = [];
  83. if (value.temclass.length != 0) value.temclass.forEach(v => {
  84. if (v.brandname != "") value.brandName.push(v.brandname);
  85. if (v.itemclassname != "") value.className.push(v.itemclassname);
  86. })
  87. return value;
  88. })
  89. }
  90. this.setData({
  91. productList: res.pageNumber == 1 ? res.data : this.data.productList.concat(res.data),
  92. "param.content.pageNumber": res.pageNumber + 1,
  93. "param.content.pageTotal": res.pageTotal,
  94. })
  95. })
  96. },
  97. /* 切换tab */
  98. onChange(e) {
  99. this.setData({
  100. "param.content.where.sa_projectid": e.detail.name,
  101. viewIndex: e.detail.index,
  102. });
  103. this.getProduct(true);
  104. },
  105. /* 添加产品 */
  106. addProduct() {
  107. wx.navigateTo({
  108. url: `/packageA/select/product/select?params=${JSON.stringify({
  109. id: 20221208105403,
  110. version: 1,
  111. model:'#Project',
  112. content: {
  113. nocache:true,
  114. sa_projectid: this.data.param.content.where.sa_projectid,
  115. sa_salesforecastbillid: this.data.sa_salesforecastbillid,
  116. pageSize: 20,
  117. pageNumber: 1,
  118. pageTotal: 1
  119. }
  120. })}`
  121. })
  122. },
  123. handleSelectProduct(itemclassinfos, oldList) {
  124. const that = this,
  125. page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
  126. wx.showModal({
  127. title: '提示',
  128. content: '是否确认添加产品',
  129. complete: ({
  130. confirm
  131. }) => {
  132. if (confirm) _Http.basic({
  133. "id": 20220906155003,
  134. "version": 1,
  135. "content": {
  136. "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
  137. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  138. "sa_projectid": that.data.param.content.where.sa_projectid,
  139. itemclassinfos
  140. }
  141. }).then(res => {
  142. console.log("项目添加产品", res)
  143. wx.showToast({
  144. title: res.msg == '成功' ? '添加成功' : res.msg,
  145. icon: "none"
  146. })
  147. if (res.msg != '成功') return;
  148. setTimeout(() => {
  149. that.getProduct(true);
  150. wx.navigateBack();
  151. }, 300)
  152. })
  153. }
  154. })
  155. },
  156. /* 生成修改队列 */
  157. changeQueue({
  158. detail
  159. }) {
  160. const that = this,
  161. page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
  162. _Http.basic({
  163. "id": 20220906155003,
  164. "version": 1,
  165. "content": {
  166. "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
  167. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  168. "sa_projectid": that.data.param.content.where.sa_projectid,
  169. itemclassinfos: detail
  170. }
  171. }).then(res => {
  172. console.log("项目修改产品", res)
  173. if (res.msg != '成功') return wx.showToast({
  174. title: res.msg,
  175. icon: "none"
  176. })
  177. let index = that.data.productList.findIndex(v => v.sa_salesforecastid == detail[0].sa_salesforecastid);
  178. if (index != -1) that.data.productList[index] = {
  179. ...that.data.productList[index],
  180. ...detail[0]
  181. }
  182. that.setData({
  183. [`productList[${index}]`]: that.data.productList[index],
  184. [`productList[0].sumamount`]: res.data[0].sumamount,
  185. })
  186. console.log(that.data.productList[index])
  187. })
  188. },
  189. /* 删除 */
  190. deleteItem({
  191. detail
  192. }) {
  193. _Http.basic({
  194. "id": 20220906155103,
  195. "version": 1,
  196. "content": detail
  197. }).then(res => {
  198. console.log("删除产品", res);
  199. if (res.msg != '成功') return wx.showToast({
  200. title: res.msg,
  201. icon: "none"
  202. });
  203. this.setData({
  204. productList: this.data.productList.filter(v => v.sa_salesforecastid != detail.sa_salesforecastid)
  205. });
  206. wx.showToast({
  207. title: '删除成功',
  208. icon: "none"
  209. })
  210. })
  211. }
  212. }
  213. })