index.js 13 KB

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