detail.js 18 KB

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