index.js 8.6 KB

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