detail.js 15 KB

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