index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. attached: function () {
  28. getApp().globalData.Language.getLanguagePackage(this)
  29. }
  30. },
  31. methods: {
  32. /* 获取产品列表 */
  33. getList(id, init) {
  34. let content = this.data.content;
  35. content.sa_aftersalesmagid = id;
  36. if (init) content.pageNumber = 1;
  37. _Http.basic({
  38. "id": "20230105111103",
  39. content
  40. }).then(res => {
  41. console.log("订货清单列表", res)
  42. if (res.code != '1') return wx.showToast({
  43. title: res.msg,
  44. icon: "none"
  45. })
  46. res.data = res.data.map(value => {
  47. if (value.attinfos.length != 0) {
  48. value.attinfos = file.fileList(value.attinfos)
  49. let image = value.attinfos.find(v => v.fileType == "image");
  50. value.cover = image ? image.cover : "";
  51. }
  52. return value;
  53. })
  54. this.setData({
  55. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  56. "content.pageNumber": res.pageNumber + 1,
  57. "content.pageSize": res.pageSize,
  58. "content.pageTotal": res.pageTotal,
  59. "content.total": res.total,
  60. sa_aftersalesmagid: id,
  61. })
  62. })
  63. },
  64. /* 修改 */
  65. changeProduct({
  66. detail
  67. }) {
  68. let obj = detail,
  69. index = this.data.list.findIndex(v => v.itemid == detail.itemid),
  70. data = this.data.list[index],
  71. page = getCurrentPages()[getCurrentPages().length - 1]
  72. if (data.qty == obj.qty && data.reason == obj.reason && data.price == obj.price) return;
  73. _Http.basic({
  74. "id": 20230105111003,
  75. "content": {
  76. "sa_aftersalesmagid": page.data.sa_aftersalesmagid,
  77. "iteminfos": [detail]
  78. }
  79. }).then(res => {
  80. console.log("产品修改", res)
  81. if (res.code != '1') {
  82. wx.showToast({
  83. title: res.msg,
  84. icon: "none"
  85. });
  86. obj = data;
  87. };
  88. data = {
  89. ...data,
  90. ...obj
  91. };
  92. data.amount = res.data[0].amount
  93. console.log(data);
  94. this.setData({
  95. [`list[${index}]`]: data
  96. })
  97. })
  98. },
  99. /* 删除 */
  100. deleteItem({
  101. detail
  102. }) {
  103. let that = this;
  104. wx.showModal({
  105. cancelText: getApp().globalData.Language.getMapText('取消'),
  106. confirmText: getApp().globalData.Language.getMapText('确定'),
  107. title: getApp().globalData.Language.getMapText('提示'),
  108. content: getApp().globalData.Language.getMapText('是否确认删除') + `“${detail.itemname}”?`,
  109. complete: (res) => {
  110. if (res.confirm) _Http.basic({
  111. "id": 20230105111203,
  112. "content": {
  113. sa_aftersalesmag_itemsids: [detail.sa_aftersalesmag_itemsid],
  114. }
  115. }).then(s => {
  116. if (s.code != '1') return wx.showToast({
  117. title: res.msg,
  118. icon: "none"
  119. });
  120. that.setData({
  121. list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
  122. });
  123. })
  124. }
  125. })
  126. },
  127. /* 去添加产品 */
  128. addProduct() {
  129. let detail = getCurrentPages().find(v => v.__route__ == 'packageA/toolBill/detail').data.detail;
  130. let id = ''
  131. wx.navigateTo({
  132. url: `/packageA/toolBill/modules/selectProduct/index?params=${JSON.stringify({
  133. "id":20230105110903,
  134. "content": {
  135. nocache:true,
  136. "sa_orderid": detail.sa_orderid, //订单ID
  137. "sa_aftersalesmagid": detail.sa_aftersalesmagid, //订单ID
  138. "pageNumber": 1,
  139. "pageTotal": 1,
  140. "total": 0,
  141. "pageSize": 20,
  142. "where": {
  143. "condition": ""
  144. }
  145. }
  146. })}`
  147. });
  148. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  149. },
  150. /* 处理新增产品 */
  151. handleSelect(detail) {
  152. let that = this;
  153. wx.showModal({
  154. cancelText: getApp().globalData.Language.getMapText('取消'),
  155. confirmText: getApp().globalData.Language.getMapText('确定'),
  156. title: getApp().globalData.Language.getMapText('提示'),
  157. content: getApp().globalData.Language.joint([{
  158. t: 1,
  159. v: '是否确认添加',
  160. }, {
  161. v: detail.result.length,
  162. f: "“",
  163. r: "”"
  164. }, {
  165. t: 1,
  166. v: '件商品',
  167. r: "?"
  168. }]),
  169. complete: (res) => {
  170. if (res.confirm) _Http.basic({
  171. "id": 20230105111003,
  172. "content": {
  173. sa_aftersalesmagid: that.data.sa_aftersalesmagid,
  174. "iteminfos": detail.list.map(v => {
  175. return {
  176. "sa_aftersalesmag_itemsid": 0,
  177. "sa_orderitemsid": v.sa_orderitemsid,
  178. "itemid": v.itemid,
  179. "reason": '',
  180. "qty": v.qty,
  181. "price": v.price
  182. }
  183. })
  184. }
  185. }).then(s => {
  186. console.log('新增产品', s)
  187. wx.showToast({
  188. title: s.code == '1' ? getApp().globalData.Language.getMapText('添加成功') : s.msg,
  189. icon: "none"
  190. });
  191. if (s.code == '1') setTimeout(() => {
  192. that.getList(that.data.sa_aftersalesmagid, true);
  193. wx.navigateBack();
  194. }, 300)
  195. })
  196. }
  197. });
  198. },
  199. }
  200. })