detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = num => currency(num, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. loading: true,
  10. sa_orderid: null,
  11. tabsActive: 0,
  12. tabsList: [{
  13. label: "借用工具明细",
  14. icon: "icon-tabchanpin",
  15. model: "#Product"
  16. }, {
  17. label: "附件",
  18. icon: "icon-tabfujian1",
  19. model: "#Yl_Attachment"
  20. }, {
  21. label: "订单进度",
  22. icon: "icon-tabcaozuojilu1",
  23. model: "#Progress"
  24. }],
  25. },
  26. onLoad(options) {
  27. this.setData({
  28. sa_orderid: options.id
  29. });
  30. this.getDetail(true);
  31. },
  32. /* 获取详情 */
  33. getDetail(init = false, show = true) {
  34. _Http.basic({
  35. "id": 20230114140402,
  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. res.data.amount = CNY(res.data.amount);
  47. this.setData({
  48. detail: res.data,
  49. loading: false
  50. });
  51. if (init) this.partialRenewal(true)
  52. })
  53. },
  54. /* 选择收货人 */
  55. selectConsignee() {
  56. if (this.isEdit()) return;
  57. wx.navigateTo({
  58. url: `/select/address/index?params=${JSON.stringify({
  59. "id":20221009155803,
  60. "content": {
  61. nocache:true,
  62. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  63. "pageNumber": 1,
  64. "pageTotal": 1,
  65. "pageSize": 20,
  66. "where": {
  67. "condition": "",
  68. workaddress:1
  69. },
  70. }
  71. })}&radio=true`,
  72. });
  73. getApp().globalData.handleSelect = this.setConsignee.bind(this);
  74. },
  75. /* 设置收货人 */
  76. setConsignee({
  77. item
  78. }) {
  79. let that = this;
  80. console.log("设置收货人", item)
  81. wx.showModal({
  82. title: '提示',
  83. content: `是否确认设置"${item.name}"为收货人?`,
  84. complete: (res) => {
  85. if (res.confirm) {
  86. let rec_contactsid = that.data.detail.rec_contactsid;
  87. that.setData({
  88. "detail.rec_contactsid": item.contactsid
  89. });
  90. that.changeDetail().then(s => {
  91. if (s.msg == '成功') {
  92. wx.showToast({
  93. title: '设置成功',
  94. icon: "none"
  95. });
  96. setTimeout(() => {
  97. wx.navigateBack();
  98. that.getDetail();
  99. }, 500)
  100. } else {
  101. that.setData({
  102. "detail.rec_contactsid": rec_contactsid
  103. });
  104. }
  105. })
  106. }
  107. }
  108. })
  109. },
  110. /* 选择财务信息 */
  111. selectFinance() {
  112. if (this.isEdit()) return;
  113. wx.navigateTo({
  114. url: `/select/finance/index?params=${JSON.stringify({
  115. "id":20221013160602,
  116. "content": {
  117. nocache:true,
  118. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  119. "pageNumber": 1,
  120. "pageTotal": 1,
  121. "pageSize": 20,
  122. "where": {
  123. "condition": "",
  124. },
  125. }
  126. })}&radio=true`,
  127. });
  128. getApp().globalData.handleSelect = this.setFinance.bind(this);
  129. },
  130. /* 设置财务信息 */
  131. setFinance({
  132. item
  133. }) {
  134. let that = this;
  135. console.log("设置财务信息", item)
  136. wx.showModal({
  137. title: '提示',
  138. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  139. complete: (res) => {
  140. if (res.confirm) {
  141. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  142. that.setData({
  143. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  144. });
  145. that.changeDetail().then(s => {
  146. if (s.msg == '成功') {
  147. wx.showToast({
  148. title: '设置成功',
  149. icon: "none"
  150. });
  151. setTimeout(() => {
  152. wx.navigateBack();
  153. that.getDetail();
  154. }, 500)
  155. } else {
  156. that.setData({
  157. "detail.sys_enterprise_financeid": sys_enterprise_financeid
  158. });
  159. }
  160. })
  161. }
  162. }
  163. })
  164. },
  165. //tabs 切换
  166. tabsChange({
  167. detail
  168. }) {
  169. this.setData({
  170. tabsActive: detail
  171. });
  172. this.partialRenewal();
  173. },
  174. //局部数据更新 tabs
  175. partialRenewal(init = false) {
  176. let model = this.data.tabsList[this.data.tabsActive].model;
  177. if (model) {
  178. let Component = this.selectComponent(model),
  179. {
  180. total,
  181. pageNumber,
  182. pageTotal
  183. } = Component.data.content,
  184. id = this.data.detail.sa_orderid;
  185. if (model == '#Product') id = {
  186. id: this.data.detail.sa_orderid,
  187. toolcount: this.data.detail.toolcount || ""
  188. };
  189. if (total == null || init) {
  190. Component.getList(id, init);
  191. } else if (pageNumber < pageTotal) {
  192. Component.getList(id, false);
  193. }
  194. }
  195. },
  196. onReachBottom() {
  197. this.partialRenewal();
  198. },
  199. /* 更新数据 */
  200. changeDetail() {
  201. let data = this.data.detail,
  202. content = {
  203. "sa_orderid": data.sa_orderid,
  204. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  205. "sa_accountclassid": data.accountclass.sa_accountclassid || 0, //营销账户类型ID
  206. "sa_brandid": data.sa_brandid, //品牌ID
  207. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  208. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  209. "type": data.type, //订单类型
  210. "typemx": data.typemx, // 明细分类,可选
  211. "remarks": data.remarks,
  212. sa_contractid: data.sa_contractid,
  213. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  214. "tradefield": data.tradefield, //必选
  215. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  216. };
  217. return new Promise((resolve, reject) => {
  218. _Http.basic({
  219. "id": 20230116092702,
  220. content
  221. }).then(res => {
  222. console.log("修改订单数据", res);
  223. if (res.msg != '成功') wx.showToast({
  224. title: res.msg,
  225. icon: "none"
  226. });
  227. resolve(res)
  228. })
  229. })
  230. },
  231. /* 修改订单备注 */
  232. changeRemarks(e) {
  233. let value = e.detail.value,
  234. remarks = this.data.detail.remarks,
  235. that = this;
  236. if (value == this.data.detail.remarks) return;
  237. wx.showModal({
  238. title: '提示',
  239. content: '是否确定修改订单备注?',
  240. complete: async (res) => {
  241. if (res.cancel) that.setData({
  242. "detail.remarks": remarks
  243. })
  244. if (res.confirm) {
  245. this.data.detail.remarks = value;
  246. let res = await that.changeDetail();
  247. that.setData({
  248. "detail.remarks": res.msg == '成功' ? value : remarks
  249. })
  250. }
  251. }
  252. })
  253. },
  254. /* 删除订单 */
  255. deleteItem() {
  256. let that = this;
  257. wx.showModal({
  258. title: '提示',
  259. content: '是否确认删除订单?',
  260. complete: (res) => {
  261. if (res.confirm) _Http.basic({
  262. "id": 20230116100002,
  263. "content": {
  264. "sa_orderids": [
  265. that.data.sa_orderid
  266. ]
  267. }
  268. }).then(s => {
  269. console.log("删除订单", s)
  270. if (s.msg != '成功') return wx.showToast({
  271. title: s.msg,
  272. icon: "none"
  273. });
  274. wx.showToast({
  275. title: `成功删除${that.data.detail.sonum}订单`,
  276. icon: "none"
  277. });
  278. setTimeout(() => {
  279. /* let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/index');
  280. if (page) page.setData({
  281. list: page.data.list.filter(v => v.sa_orderid != that.data.sa_orderid),
  282. "content.total": page.data.content.total - 1,
  283. amount: (page.data.amount - that.data.detail.amount).toFixed(2)
  284. }); */
  285. wx.navigateBack()
  286. }, 500)
  287. })
  288. }
  289. })
  290. },
  291. /* 提交订单 */
  292. submit() {
  293. let that = this;
  294. wx.showModal({
  295. title: '提示',
  296. content: '是否确认提交订单?',
  297. complete: (res) => {
  298. if (res.confirm) _Http.basic({
  299. "id": 20230114160002,
  300. "content": {
  301. sa_orderid: that.data.sa_orderid
  302. },
  303. }).then(s => {
  304. console.log("提交订单", s)
  305. wx.showToast({
  306. title: s.msg != '成功' ? s.msg : '提交成功',
  307. icon: "none"
  308. });
  309. if (s.msg == '成功') that.setData({
  310. "detail.status": "提交"
  311. })
  312. })
  313. }
  314. })
  315. },
  316. /* 确认订单交期 */
  317. notarize() {
  318. let that = this;
  319. wx.showModal({
  320. title: '提示',
  321. content: '是否确认交期?',
  322. complete: (res) => {
  323. if (res.confirm) _Http.basic({
  324. "id": 20230129154102,
  325. "content": {
  326. sa_orderid: that.data.sa_orderid
  327. },
  328. }).then(s => {
  329. console.log("确认交期", s)
  330. wx.showToast({
  331. title: s.msg != '成功' ? s.msg : '确认成功',
  332. icon: "none"
  333. });
  334. if (s.msg == '成功') {
  335. that.setData({
  336. "detail.status": "交期确认"
  337. })
  338. }
  339. })
  340. }
  341. })
  342. },
  343. /* 判断是否可以编辑 */
  344. isEdit() {
  345. if (this.data.detail.status != '新建') wx.showToast({
  346. title: '当前订单状态不可设置!',
  347. icon: "none"
  348. });
  349. return this.data.detail.status != '新建';
  350. },
  351. /* 设置项目订单品牌领域 */
  352. setBraned() {
  353. wx.navigateTo({
  354. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  355. })
  356. },
  357. onUnload() {
  358. let page = getCurrentPages().find(v => v.__route__ == 'packageA/borrow/index');
  359. let content = JSON.parse(JSON.stringify(page.data.content));
  360. content.pageNumber = 1;
  361. content.pageSize = (page.data.content.pageNumber - 1) * page.data.content.pageSize;
  362. _Http.basic({
  363. "id": 20230114105002,
  364. content
  365. }).then(res => {
  366. console.log("更新借用单", res)
  367. page.setData({
  368. list: res.data.map(v => {
  369. v.amount = CNY(v.amount)
  370. return v
  371. }),
  372. "content.total": res.total,
  373. })
  374. /* amount: res.tips.amount || 0 */
  375. })
  376. },
  377. })