index.js 13 KB

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