index.js 10 KB

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