detail.js 15 KB

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