detail.js 22 KB

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