detail.js 15 KB

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