index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/FormatTheAttachment"),
  3. currency = require("../../../../utils/currency");
  4. let queue = [],
  5. downCounter = null,
  6. sa_orderid = 0,
  7. CNY = num => currency(num, {
  8. symbol: "¥",
  9. precision: 2
  10. }).format();
  11. Component({
  12. properties: {
  13. sa_order_v: {
  14. type: String
  15. },
  16. disabled: {
  17. type: Boolean
  18. }, //禁用
  19. returnProductCount: {
  20. type: Function
  21. }
  22. },
  23. data: {
  24. content: {
  25. nocache: true,
  26. pageNumber: 1,
  27. pageTotal: 1,
  28. total: null
  29. }
  30. },
  31. lifetimes: {
  32. detached: function () {
  33. if (downCounter) {
  34. clearTimeout(downCounter);
  35. this.changeItem(queue)
  36. }
  37. },
  38. },
  39. methods: {
  40. /* 获取产品列表 */
  41. getList(id, init) {
  42. let content = this.data.content;
  43. content.sa_orderid = id;
  44. sa_orderid = id;
  45. if (init) content.pageNumber = 1;
  46. _Http.basic({
  47. "id": "20221109093902",
  48. content
  49. }).then(res => {
  50. console.log("订货清单列表", res)
  51. if (res.msg != '成功') return wx.showToast({
  52. title: res.msg,
  53. icon: "none"
  54. })
  55. res.data = res.data.map(v => {
  56. if (v.attinfos.length != 0) {
  57. v.attinfos = file.fileList(v.attinfos)
  58. let image = v.attinfos.find(v => v.fileType == "image");
  59. v.cover = image ? image.cover : "";
  60. };
  61. v.price = CNY(v.price)
  62. v.marketprice = CNY(v.marketprice)
  63. v.amount = CNY(v.amount)
  64. return v;
  65. })
  66. let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail;
  67. let base = {
  68. sa_orderid: page.sa_orderid,
  69. sys_enterpriseid: page.sys_enterpriseid,
  70. sa_contractid: page.sa_contractid,
  71. type: page.type,
  72. };
  73. this.triggerEvent("returnProductCount", res.total)
  74. this.setData({
  75. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  76. "content.pageNumber": res.pageNumber + 1,
  77. "content.pageSize": res.pageSize,
  78. "content.pageTotal": res.pageTotal,
  79. "content.total": res.total,
  80. base
  81. })
  82. })
  83. },
  84. /* 修改 */
  85. changeProduct({
  86. detail
  87. }) {
  88. let obj = detail,
  89. index = this.data.list.findIndex(v => v.itemid == detail.itemid),
  90. data = this.data.list[index];
  91. if (data.qty == obj.qty && data.remarks == obj.remarks && data.needdate == obj.needdate) return;
  92. detail.sa_order_v = this.data.sa_order_v - 0;
  93. _Http.basic({
  94. "id": 20221109093602,
  95. "content": {
  96. ...this.data.base,
  97. "items": [detail],
  98. sa_order_v: this.data.sa_order_v - 0
  99. }
  100. }).then(res => {
  101. console.log("产品修改", res)
  102. if (res.msg != '成功') {
  103. wx.showToast({
  104. title: res.msg,
  105. icon: "none"
  106. });
  107. obj = data;
  108. };
  109. data = {
  110. ...data,
  111. ...obj
  112. };
  113. data.amount = CNY(currency(data.price).multiply(data.qty).format());
  114. data.price = CNY(data.price)
  115. this.setData({
  116. [`list[${index}]`]: data
  117. })
  118. this.updateThePrice();
  119. })
  120. },
  121. /* 删除 */
  122. deleteItem({
  123. detail
  124. }) {
  125. let that = this;
  126. wx.showModal({
  127. title: '提示',
  128. content: `是否确认删除“${detail.itemname}”?`,
  129. complete: (res) => {
  130. if (res.confirm) _Http.basic({
  131. "id": 20221109093702,
  132. "content": {
  133. sa_orderid,
  134. "sa_orderitemsids": [
  135. detail.sa_orderitemsid
  136. ],
  137. sa_order_v: that.data.sa_order_v
  138. }
  139. }).then(s => {
  140. if (s.msg != '成功') return wx.showToast({
  141. title: res.msg,
  142. icon: "none"
  143. });
  144. that.setData({
  145. list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
  146. });
  147. this.triggerEvent("returnProductCount", this.data.content.total - 1)
  148. this.updateThePrice();
  149. })
  150. }
  151. })
  152. },
  153. /* 去添加产品 */
  154. addProduct() {
  155. let detail = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail,
  156. id = '';
  157. switch (detail.type) {
  158. case '促销订单':
  159. id = 20230107182302;
  160. break;
  161. case '标准订单':
  162. id = 20221109153502;
  163. break;
  164. case '特殊订单':
  165. id = 20221109153502;
  166. break;
  167. }
  168. wx.navigateTo({
  169. url: `${detail.type=='促销订单'?'/packageA/activity/selectProduct/index':'/select/product/index'}?params=${JSON.stringify({
  170. "id":id,
  171. "content": {
  172. nocache:true,
  173. sa_orderid, //订单ID
  174. "total": 0,
  175. "where": {
  176. "condition": ""
  177. }
  178. }
  179. })}&butText=添加产品`
  180. });
  181. this.setData({
  182. type: detail.type
  183. })
  184. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  185. },
  186. /* 处理新增产品 */
  187. handleSelect(detail) {
  188. let that = this;
  189. wx.showModal({
  190. title: '提示',
  191. content: `是否确认添加${detail.result.length}件商品?`,
  192. complete: (res) => {
  193. if (res.confirm) _Http.basic({
  194. "id": 20221109093602,
  195. "content": {
  196. ...that.data.base,
  197. "items": detail.list.map(v => {
  198. return {
  199. sa_orderitemsid: 0,
  200. "itemid": v.itemid, //商品ID
  201. "qty": v.qty, //数量
  202. "width": v.width || 0,
  203. "length": v.length || 0,
  204. price: this.data.type == '工具订单' ? v.marketprice : v.contractprice,
  205. sa_promotion_itemsid: v.sa_promotion_itemsid || 0
  206. }
  207. })
  208. }
  209. }).then(s => {
  210. console.log('新增产品', s)
  211. wx.showToast({
  212. title: s.msg == '成功' ? '添加成功' : s.msg,
  213. icon: "none"
  214. });
  215. if (s.msg == '成功') setTimeout(() => {
  216. that.getList(sa_orderid, true);
  217. wx.navigateBack();
  218. that.updateThePrice();
  219. }, 300)
  220. })
  221. }
  222. });
  223. },
  224. /* 使用接口更新总价 */
  225. updateThePrice() {
  226. // _Http.basic({
  227. // "id": 20230105101102,
  228. // "content": {
  229. // sa_orderid
  230. // },
  231. // }).then(res => {
  232. // console.log("修改列表总价", res)
  233. // if (res.msg != '成功') return wx.showToast({
  234. // title: `产品总价更新失败`,
  235. // icon: "none"
  236. // });
  237. // let page = getCurrentPages()[getCurrentPages().length - 1];
  238. // if (page) {
  239. // this.setData({
  240. // "detail.amount": CNY(res.data.amount)
  241. // })
  242. // page.setLogisticsMsg();
  243. // }
  244. // })
  245. let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail');
  246. page.getDetail();
  247. }
  248. }
  249. })