detail.js 23 KB

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