detail.js 18 KB

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