detail.js 22 KB

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