index.js 8.3 KB

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