index.js 13 KB

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