detail.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. const _Http = getApp().globalData.http;
  2. let figure = null; //免运费额度
  3. import currency from "../../utils/currency";
  4. Page({
  5. data: {
  6. loading: true,
  7. sa_orderid: null,
  8. tabsActive: 0,
  9. tabsList: [{
  10. label: "产品明细",
  11. icon: "icon-tabchanpin",
  12. model: "#Product"
  13. }, {
  14. label: "订单进度",
  15. icon: "icon-tabcaozuojilu1",
  16. model: "#Progress"
  17. }, {
  18. label: "出库单",
  19. icon: "icon-tabrenwu",
  20. model: "#Consignment"
  21. }, {
  22. label: "物流单",
  23. icon: "icon-shouhuo",
  24. model: "#Shipments"
  25. }],
  26. specialProductQuantity: 0
  27. },
  28. onLoad(options) {
  29. this.setData({
  30. options: wx.getStorageSync('auth').worderform.options,
  31. sa_orderid: options.id,
  32. order_rebate_used: wx.getStorageSync('siteP').order_rebate_used,
  33. userrole: wx.getStorageSync('userrole')
  34. });
  35. this.getDetail(true);
  36. try {
  37. let privacyFieldC = wx.getStorageSync('auth').worderform.forms.detail.formcols.map(v => v.title);
  38. this.setData({
  39. privacyFieldC
  40. })
  41. } catch (error) {
  42. console.error(error)
  43. }
  44. },
  45. /* 获取详情 */
  46. getDetail(init = false, show = true) {
  47. _Http.basic({
  48. "id": 20221108151302,
  49. "content": {
  50. nocache: true,
  51. "sa_orderid": this.data.sa_orderid
  52. }
  53. }, show).then(res => {
  54. console.log("订单详情", res.data)
  55. if (res.msg != '成功') return wx.showToast({
  56. title: res.msg,
  57. icon: "none"
  58. });
  59. let CNY = value => currency(value, {
  60. symbol: "¥",
  61. precision: 2
  62. }).format();
  63. if (res.data.sa_accountclassinfos) res.data.sa_accountclassinfos = res.data.sa_accountclassinfos.map(v => {
  64. v.amount = CNY(v.amount)
  65. v.text = `\n(实时余额:${CNY(v.realbalance)},当时余额:${CNY(v.balance)},信用额度:${CNY(v.creditquota)})`
  66. return v
  67. })
  68. this.setData({
  69. detail: res.data,
  70. loading: false,
  71. amount: CNY(res.data.amount)
  72. });
  73. if (init) {
  74. this.partialRenewal(true)
  75. let content = wx.getStorageSync('userrole') == '业务员' ? {
  76. sys_enterpriseid: this.data.detail.sys_enterpriseid
  77. } : {};
  78. //业务员根据指定经销商的免运费
  79. _Http.basic({
  80. "id": 20220920084001,
  81. content
  82. }, false).then(res => {
  83. console.log("查询企业档案获取企业免邮额度", res)
  84. if (res.msg != '成功') return wx.showToast({
  85. title: res.msg,
  86. icon: "none"
  87. })
  88. figure = res.data.freefreightamount;
  89. this.setLogisticsMsg();
  90. })
  91. } else {
  92. this.setLogisticsMsg();
  93. }
  94. })
  95. },
  96. /* 特殊订单使用,获取产品数量 */
  97. getProductCount({
  98. detail
  99. }) {
  100. this.setData({
  101. specialProductQuantity: detail
  102. })
  103. },
  104. /* 免运费信息 */
  105. setLogisticsMsg() {
  106. let logistics = null;
  107. if (figure == -1) {
  108. logistics = '到付'
  109. } else if (figure == 0) {
  110. logistics = '预付'
  111. } else {
  112. let amount = this.data.detail.amount;
  113. logistics = amount >= figure ? '免运费' : '差' + currency(figure).subtract(amount).value + '元免运费';
  114. }
  115. this.setData({
  116. logistics
  117. })
  118. },
  119. /* 选择结算人 */
  120. selectAgent() {
  121. if (this.isEdit()) return;
  122. if (this.data.detail.type == '项目订单') return;
  123. wx.navigateTo({
  124. url: `/select/agent/index?params=${JSON.stringify({
  125. "id":20230104103702,
  126. "content": {
  127. "pageNumber": 1,
  128. "pageTotal": 1,
  129. "pageSize": 20,
  130. "where": {
  131. "condition": "",
  132. },
  133. }
  134. })}&radio=true`,
  135. });
  136. getApp().globalData.handleSelect = this.setAgeant.bind(this);
  137. },
  138. /* 设置结算人 */
  139. setAgeant({
  140. item
  141. }) {
  142. let that = this;
  143. console.log("选择经销商", item)
  144. wx.showModal({
  145. title: '提示',
  146. content: `是否确认设置"${item.enterprisename}"为结算人?`,
  147. complete: (res) => {
  148. if (res.confirm) {
  149. let pay_enterpriseid = that.data.detail.pay_enterpriseid,
  150. sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid,
  151. sa_accountclassid = that.data.detail.accountclass.sa_accountclassid;
  152. that.setData({
  153. "detail.pay_enterpriseid": item.sys_enterpriseid,
  154. "detail.sys_enterprise_financeid": item.finance[0] ? item.finance[0].sys_enterprise_financeid : 0,
  155. "detail.accountclass.sa_accountclassid": item.accounts[0] ? item.accounts[0].sa_accountclassid : 0,
  156. });
  157. that.changeDetail().then(s => {
  158. if (s.msg == '成功') {
  159. wx.showToast({
  160. title: '设置成功',
  161. icon: "none"
  162. });
  163. setTimeout(() => {
  164. wx.navigateBack();
  165. that.getDetail();
  166. }, 500)
  167. } else {
  168. that.setData({
  169. "detail.pay_enterpriseid": pay_enterpriseid,
  170. "detail.sys_enterprise_financeid": sys_enterprise_financeid,
  171. "detail.sa_accountclassid": sa_accountclassid
  172. });
  173. }
  174. })
  175. }
  176. }
  177. })
  178. },
  179. /* 修改支付账户 */
  180. changeAccount(e) {
  181. if (this.isEdit()) return;
  182. if (this.data.detail.type == '促销订单') return wx.showToast({
  183. title: '促销订单不可修改支付账户',
  184. icon: "none"
  185. });
  186. wx.navigateTo({
  187. url: `/select/account/index?params=${JSON.stringify({
  188. "id":20221008134803,
  189. "version": 1,
  190. "content": {
  191. "pageNumber": 1,
  192. "pageTotal": 1,
  193. "pageSize": 20,
  194. "where": {
  195. "condition": "",
  196. "isused": 1,
  197. "isnotspecialfund": this.data.detail.type == '标准订单' ? 0 : 1, //是否专用
  198. },
  199. }
  200. })}&radio=true&tradefield=${this.data.detail.tradefield}`,
  201. });
  202. getApp().globalData.handleSelect = this.setAccount.bind(this);
  203. },
  204. setAccount({
  205. item
  206. }) {
  207. let that = this;
  208. wx.showModal({
  209. title: '提示',
  210. content: `是否确认设置"${item.accountname}"为结算人?`,
  211. complete: (res) => {
  212. if (res.confirm) {
  213. that.setData({
  214. "detail.sa_accountclassid": item.sa_accountclassid,
  215. });
  216. that.changeDetail().then(s => {
  217. if (s.msg == '成功') {
  218. wx.showToast({
  219. title: '设置成功',
  220. icon: "none"
  221. });
  222. setTimeout(() => {
  223. wx.navigateBack();
  224. that.getDetail();
  225. }, 500)
  226. }
  227. })
  228. }
  229. }
  230. })
  231. },
  232. /* 选择财务信息 */
  233. selectFinance() {
  234. if (this.isEdit()) return;
  235. wx.navigateTo({
  236. url: `/select/finance/index?params=${JSON.stringify({
  237. "id":20221013160602,
  238. "content": {
  239. nocache:true,
  240. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  241. "pageNumber": 1,
  242. "pageTotal": 1,
  243. "pageSize": 20,
  244. "where": {
  245. "condition": "",
  246. },
  247. }
  248. })}&radio=true`,
  249. });
  250. getApp().globalData.handleSelect = this.setFinance.bind(this);
  251. },
  252. /* 设置财务信息 */
  253. setFinance({
  254. item
  255. }) {
  256. let that = this;
  257. console.log("设置财务信息", item)
  258. wx.showModal({
  259. title: '提示',
  260. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  261. complete: (res) => {
  262. if (res.confirm) {
  263. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  264. that.setData({
  265. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  266. });
  267. that.changeDetail().then(s => {
  268. if (s.msg == '成功') {
  269. wx.showToast({
  270. title: '设置成功',
  271. icon: "none"
  272. });
  273. setTimeout(() => {
  274. wx.navigateBack();
  275. that.getDetail();
  276. }, 500)
  277. } else {
  278. that.setData({
  279. "detail.sys_enterprise_financeid": sys_enterprise_financeid
  280. });
  281. }
  282. })
  283. }
  284. }
  285. })
  286. },
  287. //tabs 切换
  288. tabsChange({
  289. detail
  290. }) {
  291. this.setData({
  292. tabsActive: detail
  293. });
  294. this.partialRenewal();
  295. },
  296. //局部数据更新 tabs
  297. partialRenewal(init = false) {
  298. let model = this.data.tabsList[this.data.tabsActive].model;
  299. if (model) {
  300. let Component = this.selectComponent(model),
  301. {
  302. total,
  303. pageNumber,
  304. pageTotal
  305. } = Component.data.content,
  306. id = this.data.detail.sa_orderid;
  307. if (total == null || init) {
  308. Component.getList(id, init);
  309. } else if (pageNumber <= pageTotal) {
  310. Component.getList(id, false);
  311. }
  312. }
  313. },
  314. onReachBottom() {
  315. this.partialRenewal();
  316. },
  317. /* 更新数据 */
  318. changeDetail() {
  319. let data = this.data.detail,
  320. content = {
  321. "sa_orderid": data.sa_orderid,
  322. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  323. "sa_accountclassid": data.sa_accountclassid || 0, //营销账户类型ID
  324. "sa_brandid": data.sa_brandid, //品牌ID
  325. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  326. //"sa_logiscompid": data.logiscomp.sa_logiscompid || 0, 物流公司档案ID
  327. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  328. "type": data.type, //订单类型
  329. "typemx": data.typemx, // 明细分类,可选
  330. "remarks": data.remarks,
  331. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  332. "tradefield": data.tradefield, //必选
  333. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  334. "rebate_userate": data.accountclass.rebate_userate, //返利金使用比例
  335. sa_order_v: data.sa_order_v || "",
  336. abstract: data.abstract
  337. };
  338. return new Promise((resolve, reject) => {
  339. _Http.basic({
  340. "id": 20221108111402,
  341. content
  342. }).then(res => {
  343. console.log("修改订单数据", res);
  344. if (res.msg != '成功') wx.showToast({
  345. title: res.msg,
  346. icon: "none"
  347. });
  348. this.getDetail(true)
  349. resolve(res)
  350. })
  351. })
  352. },
  353. /* 修改订单备注 */
  354. changeRemarks(e) {
  355. let value = e.detail.value,
  356. remarks = this.data.detail.remarks,
  357. that = this;
  358. if (value == this.data.detail.remarks) return;
  359. wx.showModal({
  360. title: '提示',
  361. content: '是否确定修改订单备注?',
  362. complete: async (res) => {
  363. if (res.cancel) that.setData({
  364. "detail.remarks": remarks
  365. })
  366. if (res.confirm) {
  367. this.data.detail.remarks = value;
  368. let res = await that.changeDetail();
  369. that.setData({
  370. "detail.remarks": res.msg == '成功' ? value : remarks
  371. })
  372. }
  373. }
  374. })
  375. },
  376. /* 设置是否使用返利金 */
  377. changeRebateUsed() {
  378. if (this.isEdit()) return this.setData({
  379. detail: this.data.detail
  380. })
  381. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  382. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  383. _Http.basic({
  384. "id": 20230218225002,
  385. "content": {
  386. "sa_orderid": this.data.sa_orderid, //订单金额
  387. "isused": this.data.detail.rebate_used == 1 ? 0 : 1, //是否使用
  388. "rebateamount": rebatebalance > amount ? amount : rebatebalance, //返利金使用金额
  389. "sa_order_v": this.data.detail.sa_order_v || '',
  390. }
  391. }, false).then(res => {
  392. console.log('设置启用返利金', res)
  393. if (res.msg != '成功') {
  394. wx.showToast({
  395. title: res.msg,
  396. icon: "none"
  397. });
  398. this.setData({
  399. "detail.rebate_used": this.data.detail.rebate_used
  400. })
  401. return;
  402. }
  403. this.getDetail(true, false)
  404. })
  405. },
  406. /* 修改返利金 */
  407. setRebate_amount(e = 0) {
  408. let value = e.detail.value;
  409. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  410. value = value > rebatebalance ? rebatebalance : value;
  411. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  412. _Http.basic({
  413. "id": 20230218225002,
  414. "content": {
  415. "sa_orderid": this.data.sa_orderid, //订单金额
  416. "isused": 1, //是否使用
  417. "rebateamount": value > amount ? amount : value,
  418. "sa_order_v": this.data.detail.sa_order_v || '',
  419. }
  420. }, false).then(res => {
  421. console.log('设置返利金', res)
  422. if (res.msg != '成功') {
  423. wx.showToast({
  424. title: res.msg,
  425. icon: "none",
  426. mask: true
  427. });
  428. this.setData({
  429. "detail.accountclass.rebate_amount": this.data.detail.accountclass.rebate_amount
  430. })
  431. } else {
  432. this.setData({
  433. "detail.accountclass.rebate_amount": value
  434. })
  435. if (value > amount || amount == 0) wx.showToast({
  436. title: "返利金最大可使用" + amount + "元",
  437. icon: "none"
  438. })
  439. this.getDetail(true, false)
  440. }
  441. })
  442. },
  443. /* 删除订单 */
  444. deleteItem() {
  445. let that = this;
  446. wx.showModal({
  447. title: '提示',
  448. content: '是否确认删除订单?',
  449. complete: (res) => {
  450. if (res.confirm) _Http.basic({
  451. "id": 20221108152102,
  452. "content": {
  453. "sa_orderids": [
  454. that.data.sa_orderid
  455. ]
  456. }
  457. }).then(s => {
  458. console.log("删除订单", s)
  459. if (s.msg != '成功') return wx.showToast({
  460. title: s.msg,
  461. icon: "none"
  462. });
  463. wx.showToast({
  464. title: `成功删除${that.data.detail.sonum}订单`,
  465. icon: "none"
  466. });
  467. setTimeout(() => {
  468. wx.navigateBack()
  469. }, 500)
  470. })
  471. }
  472. })
  473. },
  474. /* 特殊订单预提交 */
  475. presubmission(e) {
  476. let that = this;
  477. let isrecheck = e.currentTarget.dataset.isrecheck == 1;
  478. wx.showModal({
  479. title: '提示',
  480. content: `是否确认${isrecheck?'预提交订单':'撤回预提交'}?`,
  481. complete: (res) => {
  482. if (res.confirm) _Http.basic({
  483. "id": 20230331152503,
  484. "content": {
  485. isrecheck,
  486. sa_orderid: that.data.sa_orderid,
  487. sa_order_v: that.data.detail.sa_order_v,
  488. },
  489. }).then(s => {
  490. console.log("预提交订单", s)
  491. wx.showToast({
  492. title: s.msg != '成功' ? s.msg : isrecheck ? '预提交成功' : '撤回预提交成功',
  493. icon: "none"
  494. });
  495. if (s.msg == '成功') that.getDetail(true)
  496. })
  497. }
  498. })
  499. },
  500. /* 提交订单 */
  501. submit() {
  502. let that = this;
  503. wx.showModal({
  504. title: '提示',
  505. content: '是否确认提交订单?',
  506. complete: (res) => {
  507. if (res.confirm) _Http.basic({
  508. "id": 20221108153402,
  509. "content": {
  510. sa_orderid: that.data.sa_orderid,
  511. sa_order_v: that.data.detail.sa_order_v,
  512. },
  513. }).then(s => {
  514. console.log("提交订单", s)
  515. wx.showToast({
  516. title: s.msg != '成功' ? s.msg : '提交成功',
  517. icon: "none"
  518. });
  519. if (s.msg == '成功') that.getDetail(true)
  520. })
  521. }
  522. })
  523. },
  524. /* 判断是否可以编辑 */
  525. isEdit() {
  526. if (this.data.detail.status != '新建') wx.showToast({
  527. title: '当前订单状态不可设置!',
  528. icon: "none"
  529. });
  530. return this.data.detail.status != '新建' || this.data.detail.type == '特殊订单';
  531. },
  532. /* 拷贝订单 */
  533. copyItem() {
  534. let item = this.data.detail;
  535. wx.showModal({
  536. title: '提示',
  537. content: `是否确认复制${item.type}“${item.sonum}”`,
  538. complete: (res) => {
  539. if (res.confirm) _Http.basic({
  540. "id": 20230102144502,
  541. "content": {
  542. "sa_orderid": item.sa_orderid
  543. }
  544. }).then(res => {
  545. console.log("复制订单", res)
  546. if (res.msg != '成功') return wx.showToast({
  547. title: res.msg,
  548. icon: "none"
  549. });
  550. wx.showModal({
  551. title: '提示',
  552. content: `${item.type}复制成功 是否立即前往`,
  553. complete: (s) => {
  554. if (s.confirm) wx.redirectTo({
  555. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  556. })
  557. }
  558. })
  559. })
  560. }
  561. })
  562. },
  563. /* 设置项目订单品牌领域 */
  564. setBraned() {
  565. wx.navigateTo({
  566. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  567. })
  568. },
  569. onUnload() {
  570. let page = getCurrentPages().find(v => v.__route__ == "packageA/orderForm/index")
  571. if (page) page.updateList && page.updateList()
  572. }
  573. })