detail.js 18 KB

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