detail.js 15 KB

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