index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. detail.custamount = 0;
  107. detail.customcheek = '';
  108. detail.customcolors = '';
  109. detail.custommaterial = '';
  110. _Http.basic({
  111. "id": 20221109093602,
  112. "content": {
  113. ...this.data.base,
  114. "items": [detail],
  115. sa_order_v: this.data.sa_order_v - 0
  116. }
  117. }).then(res => {
  118. console.log("产品修改", res)
  119. if (res.msg != '成功') {
  120. wx.showToast({
  121. title: res.msg,
  122. icon: "none"
  123. });
  124. obj = data;
  125. };
  126. data = {
  127. ...data,
  128. ...obj
  129. };
  130. data.showAmount = CNY(currency(data.price).multiply(data.qty).format());
  131. data.showPrice = CNY(data.price)
  132. this.setData({
  133. [`list[${index}]`]: data
  134. })
  135. this.updateThePrice();
  136. })
  137. },
  138. /* 删除 */
  139. deleteItem({
  140. detail
  141. }) {
  142. let that = this;
  143. wx.showModal({
  144. title: '提示',
  145. content: that.data.packagetype ? '该商品为套餐商品,删除后该套餐下所有商品都会被删除,确认删除吗?' : `是否确认删除“${detail.itemname}”?`,
  146. complete: (res) => {
  147. if (res.confirm) _Http.basic({
  148. "id": 20221109093702,
  149. "content": {
  150. sa_orderid,
  151. "sa_orderitemsids": [
  152. detail.sa_orderitemsid
  153. ],
  154. sa_order_v: that.data.sa_order_v
  155. }
  156. }).then(s => {
  157. if (s.msg != '成功') return wx.showToast({
  158. title: res.msg,
  159. icon: "none"
  160. });
  161. if (that.data.packagetype) {
  162. that.getList(sa_orderid, true)
  163. } else {
  164. that.setData({
  165. list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
  166. });
  167. that.triggerEvent("returnProductCount", that.data.content.total - 1)
  168. }
  169. that.updateThePrice();
  170. })
  171. }
  172. })
  173. },
  174. /* 去添加产品 */
  175. addProduct() {
  176. if (this.data.packagetype) {
  177. wx.navigateTo({
  178. url: '/packageA/activity/bindingProduct/index?params=' + JSON.stringify({
  179. "id": 20230107182302,
  180. "version": 1,
  181. "content": {
  182. nocache: true,
  183. sa_orderid, //订单ID
  184. packagetype: this.data.packagetype,
  185. sa_promotionid: this.data.sa_promotionid,
  186. "where": {
  187. "condition": "",
  188. packagetypemx: "",
  189. }
  190. }
  191. }) + `&butText=添加套餐&packagetypemxrows=${JSON.stringify(this.data.packagetypemxrows)}&getListPa=` + JSON.stringify({
  192. "id": "20221109093902",
  193. content: this.data.content
  194. }),
  195. });
  196. getApp().globalData.handleSelect = this.handleInsert.bind(this);
  197. } else {
  198. let detail = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail,
  199. id = '';
  200. switch (detail.type) {
  201. case '促销订单':
  202. id = 20230107182302;
  203. break;
  204. case '标准订单':
  205. id = 20221109153502;
  206. break;
  207. case '特殊订单':
  208. id = 20221109153502;
  209. break;
  210. }
  211. wx.navigateTo({
  212. url: `${detail.type=='促销订单'?'/packageA/activity/selectProduct/index':'/select/product/index'}?params=${JSON.stringify({
  213. "id":id,
  214. "content": {
  215. nocache:true,
  216. sa_orderid, //订单ID
  217. "total": 0,
  218. "where": {
  219. "condition": ""
  220. }
  221. }
  222. })}&butText=添加产品`
  223. });
  224. this.setData({
  225. type: detail.type
  226. })
  227. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  228. }
  229. },
  230. /* 去修改 */
  231. editProduct() {
  232. wx.navigateTo({
  233. url: '/packageA/activity/bindingProduct/index?params=' + JSON.stringify({
  234. "id": 20230107182302,
  235. "version": 1,
  236. "content": {
  237. nocache: true,
  238. sa_orderid, //订单ID
  239. packagetype: this.data.packagetype,
  240. "where": {
  241. "condition": "",
  242. packagetypemx: "",
  243. }
  244. }
  245. }) + `&butText=调整套数&packagetypemxrows=${JSON.stringify(this.data.packagetypemxrows)}&getListPa=` + JSON.stringify({
  246. "id": "20221109093902",
  247. content: this.data.content
  248. }),
  249. });
  250. getApp().globalData.handleSelect = this.handleInsert.bind(this);
  251. },
  252. /* 处理新增产品 */
  253. handleSelect(detail) {
  254. let that = this;
  255. _Http.basic({
  256. "id": 2024020201095102,
  257. "content": {
  258. ...that.data.base,
  259. "items": detail.list
  260. },
  261. }).then(res => {
  262. console.log("查询重复产品", res)
  263. if (res.msg != '成功') return wx.showToast({
  264. title: res.msg,
  265. icon: "none"
  266. });
  267. if (res.data.items.length) {
  268. if (res.data.isrepeat) {
  269. wx.showModal({
  270. title: '提示',
  271. content: `本单已存在【${res.data.items[0].itemname}】商品,确认继续添加吗?`,
  272. complete: (res) => {
  273. if (res.confirm) handle()
  274. }
  275. })
  276. } else {
  277. wx.showModal({
  278. title: '提示',
  279. content: `本单已存在【${res.data.items[0].itemname}】商品,禁止重复添加!`,
  280. showCancel: false
  281. })
  282. }
  283. } else {
  284. handle()
  285. }
  286. })
  287. function handle() {
  288. wx.showModal({
  289. title: '提示',
  290. content: `是否确认添加${detail.result.length}件商品?`,
  291. complete: (res) => {
  292. if (res.confirm) that.handleInsert(detail).bind(that)
  293. }
  294. });
  295. }
  296. },
  297. handleInsert({
  298. list
  299. }) {
  300. return new Promise((resolve) => {
  301. _Http.basic({
  302. "id": 20221109093602,
  303. content: {
  304. ...this.data.base,
  305. "items": list.map(v => {
  306. return {
  307. sa_orderitemsid: v.sa_orderitemsid || 0,
  308. itemid: v.itemid, //商品ID
  309. qty: v.qty, //数量
  310. width: v.width || 0,
  311. length: v.length || 0,
  312. cheek: v.cheek,
  313. color: v.color,
  314. material: v.material,
  315. spec: v.spec,
  316. custom: v.custom,
  317. price: this.data.type == '工具订单' ? v.marketprice : v.contractprice,
  318. sa_promotion_itemsid: v.sa_promotion_itemsid || 0,
  319. custamount: 0,
  320. customcheek: '',
  321. customcolors: '',
  322. custommaterial: '',
  323. }
  324. })
  325. }
  326. }).then(s => {
  327. console.log('新增产品', s)
  328. resolve(s.msg == '成功')
  329. wx.showToast({
  330. title: s.msg == '成功' ? '操作成功' : s.msg,
  331. icon: "none",
  332. mask: s.msg == '成功'
  333. });
  334. if (s.msg == '成功') {
  335. this.getList(sa_orderid, true);
  336. this.updateThePrice();
  337. setTimeout(() => {
  338. wx.navigateBack();
  339. }, 300)
  340. }
  341. })
  342. })
  343. },
  344. /* 使用接口更新总价 */
  345. updateThePrice() {
  346. getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').getDetail();
  347. }
  348. }
  349. })