detail.js 17 KB

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