detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. wx.navigateTo({
  171. url: `/select/account/index?params=${JSON.stringify({
  172. "id":20221008134803,
  173. "version": 1,
  174. "content": {
  175. "pageNumber": 1,
  176. "pageTotal": 1,
  177. "pageSize": 20,
  178. "where": {
  179. "condition": "",
  180. "isused": 1,
  181. "isnotspecialfund": this.data.detail.type == '标准订单' ? 0 : 1, //是否专用
  182. },
  183. }
  184. })}&radio=true`,
  185. });
  186. getApp().globalData.handleSelect = this.setAccount.bind(this);
  187. },
  188. setAccount({
  189. item
  190. }) {
  191. let that = this;
  192. wx.showModal({
  193. title: '提示',
  194. content: `是否确认设置"${item.accountname}"为结算人?`,
  195. complete: (res) => {
  196. if (res.confirm) {
  197. that.setData({
  198. "detail.sa_accountclassid": item.sa_accountclassid,
  199. });
  200. that.changeDetail().then(s => {
  201. if (s.msg == '成功') {
  202. wx.showToast({
  203. title: '设置成功',
  204. icon: "none"
  205. });
  206. setTimeout(() => {
  207. wx.navigateBack();
  208. that.getDetail();
  209. }, 500)
  210. }
  211. })
  212. }
  213. }
  214. })
  215. },
  216. /* 选择财务信息 */
  217. selectFinance() {
  218. if (this.isEdit()) return;
  219. wx.navigateTo({
  220. url: `/select/finance/index?params=${JSON.stringify({
  221. "id":20221013160602,
  222. "content": {
  223. nocache:true,
  224. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  225. "pageNumber": 1,
  226. "pageTotal": 1,
  227. "pageSize": 20,
  228. "where": {
  229. "condition": "",
  230. },
  231. }
  232. })}&radio=true`,
  233. });
  234. getApp().globalData.handleSelect = this.setFinance.bind(this);
  235. },
  236. /* 设置财务信息 */
  237. setFinance({
  238. item
  239. }) {
  240. let that = this;
  241. console.log("设置财务信息", item)
  242. wx.showModal({
  243. title: '提示',
  244. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  245. complete: (res) => {
  246. if (res.confirm) {
  247. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  248. that.setData({
  249. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  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.sys_enterprise_financeid": sys_enterprise_financeid
  264. });
  265. }
  266. })
  267. }
  268. }
  269. })
  270. },
  271. //tabs 切换
  272. tabsChange({
  273. detail
  274. }) {
  275. this.setData({
  276. tabsActive: detail
  277. });
  278. this.partialRenewal();
  279. },
  280. //局部数据更新 tabs
  281. partialRenewal(init = false) {
  282. let model = this.data.tabsList[this.data.tabsActive].model;
  283. if (model) {
  284. let Component = this.selectComponent(model),
  285. {
  286. total,
  287. pageNumber,
  288. pageTotal
  289. } = Component.data.content,
  290. id = this.data.detail.sa_orderid;
  291. if (total == null || init) {
  292. Component.getList(id, init);
  293. } else if (pageNumber <= pageTotal) {
  294. Component.getList(id, false);
  295. }
  296. }
  297. },
  298. onReachBottom() {
  299. this.partialRenewal();
  300. },
  301. /* 更新数据 */
  302. changeDetail() {
  303. let data = this.data.detail,
  304. content = {
  305. "sa_orderid": data.sa_orderid,
  306. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  307. "sa_accountclassid": data.sa_accountclassid || 0, //营销账户类型ID
  308. "sa_brandid": data.sa_brandid, //品牌ID
  309. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  310. //"sa_logiscompid": data.logiscomp.sa_logiscompid || 0, 物流公司档案ID
  311. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  312. "type": data.type, //订单类型
  313. "typemx": data.typemx, // 明细分类,可选
  314. "remarks": data.remarks,
  315. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  316. "tradefield": data.tradefield, //必选
  317. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  318. "rebate_userate": data.accountclass.rebate_userate, //返利金使用比例
  319. };
  320. return new Promise((resolve, reject) => {
  321. _Http.basic({
  322. "id": 20221108111402,
  323. content
  324. }).then(res => {
  325. console.log("修改订单数据", res);
  326. if (res.msg != '成功') wx.showToast({
  327. title: res.msg,
  328. icon: "none"
  329. });
  330. resolve(res)
  331. })
  332. })
  333. },
  334. /* 修改订单备注 */
  335. changeRemarks(e) {
  336. let value = e.detail.value,
  337. remarks = this.data.detail.remarks,
  338. that = this;
  339. if (value == this.data.detail.remarks) return;
  340. wx.showModal({
  341. title: '提示',
  342. content: '是否确定修改订单备注?',
  343. complete: async (res) => {
  344. if (res.cancel) that.setData({
  345. "detail.remarks": remarks
  346. })
  347. if (res.confirm) {
  348. this.data.detail.remarks = value;
  349. let res = await that.changeDetail();
  350. that.setData({
  351. "detail.remarks": res.msg == '成功' ? value : remarks
  352. })
  353. }
  354. }
  355. })
  356. },
  357. /* 设置是否使用返利金 */
  358. changeRebateUsed() {
  359. if (this.isEdit()) return this.setData({
  360. detail: this.data.detail
  361. })
  362. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  363. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  364. _Http.basic({
  365. "id": 20230218225002,
  366. "content": {
  367. "sa_orderid": this.data.sa_orderid, //订单金额
  368. "isused": this.data.detail.rebate_used == 1 ? 0 : 1, //是否使用
  369. "rebateamount": rebatebalance > amount ? amount : rebatebalance //返利金使用金额
  370. }
  371. }, false).then(res => {
  372. console.log('设置启用返利金', res)
  373. if (res.msg != '成功') {
  374. wx.showToast({
  375. title: res.msg,
  376. icon: "none"
  377. });
  378. this.setData({
  379. "detail.rebate_used": this.data.detail.rebate_used
  380. })
  381. return;
  382. }
  383. this.getDetail(true, false)
  384. })
  385. },
  386. /* 修改返利金 */
  387. setRebate_amount(e = 0) {
  388. let value = e.detail.value;
  389. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  390. value = value > rebatebalance ? rebatebalance : value;
  391. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  392. _Http.basic({
  393. "id": 20230218225002,
  394. "content": {
  395. "sa_orderid": this.data.sa_orderid, //订单金额
  396. "isused": 1, //是否使用
  397. "rebateamount": value > amount ? amount : value
  398. }
  399. }, false).then(res => {
  400. console.log('设置返利金', res)
  401. if (res.msg != '成功') {
  402. wx.showToast({
  403. title: res.msg,
  404. icon: "none",
  405. mask: true
  406. });
  407. this.setData({
  408. "detail.accountclass.rebate_amount": this.data.detail.accountclass.rebate_amount
  409. })
  410. } else {
  411. this.setData({
  412. "detail.accountclass.rebate_amount": value
  413. })
  414. if (value > amount || amount == 0) wx.showToast({
  415. title: "返利金最大可使用" + amount + "元",
  416. icon: "none"
  417. })
  418. this.getDetail(true, false)
  419. }
  420. })
  421. },
  422. /* 删除订单 */
  423. deleteItem() {
  424. let that = this;
  425. wx.showModal({
  426. title: '提示',
  427. content: '是否确认删除订单?',
  428. complete: (res) => {
  429. if (res.confirm) _Http.basic({
  430. "id": 20221108152102,
  431. "content": {
  432. "sa_orderids": [
  433. that.data.sa_orderid
  434. ]
  435. }
  436. }).then(s => {
  437. console.log("删除订单", s)
  438. if (s.msg != '成功') return wx.showToast({
  439. title: s.msg,
  440. icon: "none"
  441. });
  442. wx.showToast({
  443. title: `成功删除${that.data.detail.sonum}订单`,
  444. icon: "none"
  445. });
  446. setTimeout(() => {
  447. wx.navigateBack()
  448. }, 500)
  449. })
  450. }
  451. })
  452. },
  453. /* 特殊订单预提交 */
  454. presubmission(e) {
  455. let that = this;
  456. let isrecheck = e.currentTarget.dataset.isrecheck == 1;
  457. wx.showModal({
  458. title: '提示',
  459. content: `是否确认${isrecheck?'预提交订单':'撤回预提交'}?`,
  460. complete: (res) => {
  461. if (res.confirm) _Http.basic({
  462. "id": 20230331152503,
  463. "content": {
  464. isrecheck,
  465. sa_orderid: that.data.sa_orderid
  466. },
  467. }).then(s => {
  468. console.log("预提交订单", s)
  469. wx.showToast({
  470. title: s.msg != '成功' ? s.msg : isrecheck ? '预提交成功' : '撤回预提交成功',
  471. icon: "none"
  472. });
  473. if (s.msg == '成功') that.setData({
  474. "detail.status": isrecheck ? "预提交" : '新建'
  475. })
  476. })
  477. }
  478. })
  479. },
  480. /* 提交订单 */
  481. submit() {
  482. let that = this;
  483. wx.showModal({
  484. title: '提示',
  485. content: '是否确认提交订单?',
  486. complete: (res) => {
  487. if (res.confirm) _Http.basic({
  488. "id": 20221108153402,
  489. "content": {
  490. sa_orderid: that.data.sa_orderid
  491. },
  492. }).then(s => {
  493. console.log("提交订单", s)
  494. wx.showToast({
  495. title: s.msg != '成功' ? s.msg : '提交成功',
  496. icon: "none"
  497. });
  498. if (s.msg == '成功') that.setData({
  499. "detail.status": "提交"
  500. })
  501. })
  502. }
  503. })
  504. },
  505. /* 判断是否可以编辑 */
  506. isEdit() {
  507. if (this.data.detail.status != '新建') wx.showToast({
  508. title: '当前订单状态不可设置!',
  509. icon: "none"
  510. });
  511. return this.data.detail.status != '新建' || this.data.detail.type == '特殊订单';
  512. },
  513. /* 拷贝订单 */
  514. copyItem() {
  515. let item = this.data.detail;
  516. wx.showModal({
  517. title: '提示',
  518. content: `是否确认复制${item.type}“${item.sonum}”`,
  519. complete: (res) => {
  520. if (res.confirm) _Http.basic({
  521. "id": 20230102144502,
  522. "content": {
  523. "sa_orderid": item.sa_orderid
  524. }
  525. }).then(res => {
  526. console.log("复制订单", res)
  527. if (res.msg != '成功') return wx.showToast({
  528. title: res.msg,
  529. icon: "none"
  530. });
  531. wx.showModal({
  532. title: '提示',
  533. content: `${item.type}复制成功 是否立即前往`,
  534. complete: (s) => {
  535. if (s.confirm) wx.redirectTo({
  536. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  537. })
  538. }
  539. })
  540. })
  541. }
  542. })
  543. },
  544. /* 设置项目订单品牌领域 */
  545. setBraned() {
  546. wx.navigateTo({
  547. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  548. })
  549. },
  550. onUnload() {
  551. let page = getCurrentPages().find(v => v.__route__ == "packageA/orderForm/index")
  552. if (page) page.updateList && page.updateList()
  553. }
  554. })