detail.js 15 KB

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