detail.js 24 KB

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