index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/FormatTheAttachment");
  3. let queue = [],
  4. downCounter = null;
  5. Component({
  6. properties: {
  7. disabled: {
  8. type: Boolean
  9. }, //禁用
  10. },
  11. data: {
  12. sa_aftersalesmagid: 0,
  13. "content": {
  14. nocache: true,
  15. "pageNumber": 1,
  16. pageTotal: 1,
  17. total: null
  18. }
  19. },
  20. lifetimes: {
  21. detached: function () {
  22. if (downCounter) {
  23. clearTimeout(downCounter);
  24. this.changeItem(queue)
  25. }
  26. },
  27. },
  28. methods: {
  29. /* 获取产品列表 */
  30. getList(id, init) {
  31. let content = this.data.content;
  32. content.sa_aftersalesmagid = id;
  33. if (init) content.pageNumber = 1;
  34. _Http.basic({
  35. "id": "20230105111103",
  36. content
  37. }).then(res => {
  38. console.log("订货清单列表", res)
  39. if (res.msg != '成功') return wx.showToast({
  40. title: res.msg,
  41. icon: "none"
  42. })
  43. res.data = res.data.map(value => {
  44. if (value.attinfos.length != 0) {
  45. value.attinfos = file.fileList(value.attinfos)
  46. let image = value.attinfos.find(v => v.fileType == "image");
  47. value.cover = image ? image.cover : "";
  48. }
  49. return value;
  50. })
  51. this.setData({
  52. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  53. "content.pageNumber": res.pageNumber + 1,
  54. "content.pageSize": res.pageSize,
  55. "content.pageTotal": res.pageTotal,
  56. "content.total": res.total,
  57. sa_aftersalesmagid: id,
  58. })
  59. })
  60. },
  61. /* 修改 */
  62. changeProduct({
  63. detail
  64. }) {
  65. let obj = detail,
  66. index = this.data.list.findIndex(v => v.itemid == detail.itemid),
  67. data = this.data.list[index],
  68. page = getCurrentPages()[getCurrentPages().length - 1]
  69. if (data.qty == obj.qty && data.reason == obj.reason && data.price == obj.price) return;
  70. _Http.basic({
  71. "id": 20230105111003,
  72. "content": {
  73. "sa_aftersalesmagid": page.data.sa_aftersalesmagid,
  74. "iteminfos": [detail]
  75. }
  76. }).then(res => {
  77. console.log("产品修改", res)
  78. if (res.msg != '成功') {
  79. wx.showToast({
  80. title: res.msg,
  81. icon: "none"
  82. });
  83. obj = data;
  84. };
  85. data = {
  86. ...data,
  87. ...obj
  88. };
  89. data.amount = res.data[0].amount
  90. console.log(data);
  91. this.setData({
  92. [`list[${index}]`]: data
  93. })
  94. })
  95. },
  96. /* 删除 */
  97. deleteItem({
  98. detail
  99. }) {
  100. let that = this;
  101. wx.showModal({
  102. title: '提示',
  103. content: `是否确认删除“${detail.itemname}”?`,
  104. complete: (res) => {
  105. if (res.confirm) _Http.basic({
  106. "id": 20230105111203,
  107. "content": {
  108. sa_aftersalesmag_itemsids: [detail.sa_aftersalesmag_itemsid],
  109. }
  110. }).then(s => {
  111. if (s.msg != '成功') return wx.showToast({
  112. title: res.msg,
  113. icon: "none"
  114. });
  115. that.setData({
  116. list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
  117. });
  118. })
  119. }
  120. })
  121. },
  122. /* 去添加产品 */
  123. addProduct() {
  124. let detail = getCurrentPages().find(v => v.__route__ == 'packageA/toolBill/detail').data.detail;
  125. let id = ''
  126. wx.navigateTo({
  127. url: `/packageA/toolBill/modules/selectProduct/index?params=${JSON.stringify({
  128. "id":20230105110903,
  129. "content": {
  130. nocache:true,
  131. "sa_orderid": detail.sa_orderid, //订单ID
  132. "sa_aftersalesmagid": detail.sa_aftersalesmagid, //订单ID
  133. "pageNumber": 1,
  134. "pageTotal": 1,
  135. "total": 0,
  136. "pageSize": 20,
  137. "where": {
  138. "condition": ""
  139. }
  140. }
  141. })}`
  142. });
  143. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  144. },
  145. /* 处理新增产品 */
  146. handleSelect(detail) {
  147. let that = this;
  148. console.log(detail);
  149. wx.showModal({
  150. title: '提示',
  151. content: `是否确认添加${detail.result.length}件商品?`,
  152. complete: (res) => {
  153. if (res.confirm) _Http.basic({
  154. "id": 20230105111003,
  155. "content": {
  156. sa_aftersalesmagid: that.data.sa_aftersalesmagid,
  157. "iteminfos": detail.list.map(v => {
  158. return {
  159. "sa_aftersalesmag_itemsid": 0,
  160. "sa_orderitemsid": v.sa_orderitemsid,
  161. "itemid": v.itemid,
  162. "reason": '',
  163. "qty": v.qty,
  164. "price": v.price
  165. }
  166. })
  167. }
  168. }).then(s => {
  169. console.log('新增产品', s)
  170. wx.showToast({
  171. title: s.msg == '成功' ? '添加成功' : s.msg,
  172. icon: "none"
  173. });
  174. if (s.msg == '成功') setTimeout(() => {
  175. that.getList(that.data.sa_aftersalesmagid, true);
  176. wx.navigateBack();
  177. }, 300)
  178. })
  179. }
  180. });
  181. },
  182. }
  183. })