detail.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. loading: true,
  10. isLeader: false, //是否为负责人
  11. tabsActive: 1, //tabs 选中项
  12. sa_quotedpriceid: "",
  13. tabbarList: [],
  14. },
  15. onLoad(options) {
  16. const appAuth = wx.getStorageSync('auth').woffer;
  17. let tabsList = [{
  18. label: "详细信息",
  19. icon: "icon-tabxiangxixinxi1"
  20. }, {
  21. label: "产品明细折扣",
  22. icon: "icon-tabchanpin",
  23. model: "#Product"
  24. }, {
  25. label: "产品类别折扣",
  26. icon: "icon-tabchanpinleibie",
  27. model: "#PiscountType"
  28. }, {
  29. label: "其他费用",
  30. icon: "icon-tabkaipiaoxinxi",
  31. model: "#PettyExpense"
  32. }, {
  33. label: "历史报价",
  34. icon: "icon-tabbaojiadan",
  35. model: "#History"
  36. }, {
  37. label: "跟进动态",
  38. icon: "icon-tabgenjinjilu",
  39. model: "#Trace"
  40. }, {
  41. label: "操作记录",
  42. icon: "icon-tabcaozuojilu1",
  43. model: "#Record"
  44. }, {
  45. label: "附件",
  46. icon: "icon-tabfujian1",
  47. model: "#Files"
  48. }];
  49. if (appAuth.istask) tabsList.push({
  50. label: "任务",
  51. icon: "icon-tabrenwu",
  52. model: "#Work"
  53. })
  54. this.setData({
  55. sa_quotedpriceid: options.sa_quotedpriceid,
  56. isAdmin: appAuth.options.some(v => v == "admin"), //是否具有管理权限
  57. options: appAuth.options, //权限列表
  58. tabsList
  59. })
  60. this.getDetail(true);
  61. },
  62. getDetail(init = false) {
  63. _Http.basic({
  64. "id": 20221020165203,
  65. "version": 1,
  66. "content": {
  67. nocache: true,
  68. "sa_quotedpriceid": this.data.sa_quotedpriceid
  69. },
  70. }).then(res => {
  71. console.log("报价单详情", res)
  72. if (res.msg != '成功') return wx.showToast({
  73. title: res.msg,
  74. icon: "none"
  75. });
  76. this.setPreview(res);
  77. this.setTabbar(res.data.status, res.data.leader[0].userid == wx.getStorageSync('userMsg').userid);
  78. this.setData({
  79. loading: false,
  80. detail: res.data,
  81. })
  82. /* 更新列表数据 */
  83. let page = getCurrentPages().find(v => v.__route__ == 'packageA/offers/index');
  84. if (page) {
  85. let i = page.data.list.findIndex(v => v.sa_quotedpriceid == this.data.sa_quotedpriceid);
  86. if (i != -1 && page.data.list[i].status != res.data.status) page.setData({
  87. [`list[${i}].status`]: res.data.status
  88. })
  89. }
  90. this.getTags();
  91. this.getGroup();
  92. this.partialRenewal();
  93. })
  94. },
  95. /* 设置显示字段 */
  96. setPreview(res) {
  97. let briefs = [{
  98. label: "报价类型",
  99. value: res.data.quotedpricetype
  100. }, {
  101. label: "项目",
  102. value: res.data.projectname
  103. }, {
  104. label: "客户",
  105. value: res.data.enterprisename
  106. }, {
  107. label: "是否特价",
  108. value: res.data.specialoffer == 1 ? '是' : '否'
  109. }, {
  110. label: "状态",
  111. value: res.data.status
  112. }];
  113. //客户报价移除项目字段
  114. if (res.data.quotedpricetype == '客户报价') briefs.splice(1, 1);
  115. let list1 = [{
  116. label: "报价单号",
  117. value: res.data.billno
  118. }, {
  119. label: "报价类型",
  120. value: res.data.quotedpricetype
  121. }, {
  122. label: "产品系列",
  123. value: res.data.itemtype
  124. }, {
  125. label: "领域",
  126. value: res.data.tradefields
  127. }, {
  128. label: "品牌",
  129. value: res.data.brandname
  130. }, {
  131. label: "项目名称",
  132. value: res.data.projectname
  133. }, {
  134. label: "客户",
  135. value: res.data.enterprisename
  136. }, {
  137. label: "电话",
  138. value: res.data.telephone
  139. }, {
  140. label: "客户联系人",
  141. value: res.data.contactsname
  142. }, {
  143. label: "联系人手机号",
  144. value: res.data.contactsphonenumber
  145. }, {
  146. label: "报价日期",
  147. value: res.data.billdate
  148. }, {
  149. label: "有效期",
  150. value: res.data.begdate + ' - ' + res.data.enddate
  151. }, {
  152. label: "整单折扣(%)",
  153. value: (res.data.discountrate * 100).toFixed(2) + '%'
  154. }, {
  155. label: "总金额",
  156. value: CNY(res.data.sumamount)
  157. }, {
  158. label: "是否特价",
  159. value: res.data.specialoffer == 1 ? '是' : '否'
  160. }, {
  161. label: "状态",
  162. value: res.data.status
  163. }, {
  164. label: "负责人",
  165. value: res.data.leader[0].name
  166. }, {
  167. label: "备注",
  168. value: res.data.remarks
  169. }];
  170. //客户报价移除项目字段
  171. if (res.data.quotedpricetype == '客户报价') list1.splice(4, 2);
  172. this.setData({
  173. briefs,
  174. list1,
  175. list2: [{
  176. label: "创建人",
  177. value: res.data.createby
  178. }, {
  179. label: "创建时间",
  180. value: res.data.createdate
  181. }, {
  182. label: "最近编辑人",
  183. value: res.data.changeby
  184. }, {
  185. label: "最近编辑时间",
  186. value: res.data.changedate
  187. }, {
  188. label: "提交人",
  189. value: res.data.submitby
  190. }, {
  191. label: "提交时间",
  192. value: res.data.submitdate
  193. }, {
  194. label: "审核人",
  195. value: res.data.checkby
  196. }, {
  197. label: "审核时间",
  198. value: res.data.checkdate
  199. }, {
  200. label: "作废原因",
  201. value: res.data.deletereason
  202. }, {
  203. label: "转手次数",
  204. value: res.data.leader[0].leadernum
  205. }],
  206. })
  207. },
  208. /* 设置底部功能 */
  209. async setTabbar(status, Leader) {
  210. let isLeader = Leader,
  211. isAdmin = this.data.isAdmin,
  212. editdataleader = true,
  213. tabbarList = [{
  214. icon: "icon-genjin",
  215. label: "跟进"
  216. }];
  217. if (!isLeader) {
  218. let s = await getApp().agentOrNot("sa_quotedprice", this.data.sa_quotedpriceid);
  219. isLeader = s.data.editable == 1;
  220. editdataleader = s.data.editdataleader == 1;
  221. }
  222. if (isLeader || isAdmin) {
  223. //负责人/管理员默认权限功能
  224. tabbarList.push({
  225. icon: "icon-guanlian-fuzhi",
  226. label: "复制"
  227. });
  228. if (status == '新建') {
  229. if (editdataleader) tabbarList.unshift({
  230. icon: "icon-zhuanyi",
  231. label: "更换负责人"
  232. })
  233. tabbarList = [{
  234. icon: "icon-shanchu",
  235. label: "作废"
  236. }, {
  237. icon: "icon-dibu-bianji",
  238. label: "编辑"
  239. }].concat(tabbarList);
  240. }
  241. //负责人 新建状态可以提交 提交状态可以撤回 负责人可以打印
  242. if (isLeader) {
  243. if (status == '新建') tabbarList.unshift({
  244. icon: "icon-genjin",
  245. label: '提交'
  246. })
  247. if (status == '提交') tabbarList.unshift({
  248. icon: "icon-genjin",
  249. label: '撤回'
  250. });
  251. }
  252. //拥有管理权限 提交状态可以审核 审核状态可以反审核
  253. if (this.data.isAdmin && (res.data.status == '审核' || res.data.status == '提交')) tabbarList.unshift(res.data.status == '审核' ? {
  254. icon: "icon-guanlian-fuzhi",
  255. label: "反审核"
  256. } : {
  257. icon: "icon-guanlian-fuzhi",
  258. label: "审核"
  259. });
  260. }
  261. this.setData({
  262. tabbarList,
  263. isLeader,
  264. editdataleader
  265. });
  266. },
  267. //tabs 切换
  268. tabsChange({
  269. detail
  270. }) {
  271. this.setData({
  272. tabsActive: detail
  273. });
  274. this.partialRenewal();
  275. },
  276. //更新标签
  277. getTags() {
  278. this.selectComponent("#Tags").getTags();
  279. },
  280. //更新团队成员
  281. getGroup() {
  282. this.selectComponent("#Group").getList();
  283. },
  284. //局部数据更新 tabs
  285. partialRenewal(init = false) {
  286. let model = this.data.tabsList[this.data.tabsActive].model;
  287. if (model) {
  288. let Component = this.selectComponent(model),
  289. {
  290. total,
  291. pageNumber,
  292. pageTotal
  293. } = Component.data.content,
  294. id = this.data.sa_quotedpriceid;
  295. if (total == null || init) {
  296. Component.getList(id, init);
  297. } else if (pageNumber <= pageTotal) {
  298. Component.getList(id, false);
  299. }
  300. }
  301. },
  302. onReachBottom() {
  303. this.partialRenewal();
  304. },
  305. //详情按钮回调
  306. tabbarOnClick({
  307. detail
  308. }) {
  309. let data = this.data.detail,
  310. that = this;
  311. switch (detail.label) {
  312. case "编辑":
  313. console.log(data)
  314. wx.navigateTo({
  315. url: `/packageA/offers/${data.quotedpricetype=='项目报价'?'addProjectOffer':'addSetclientOffer'}?data=${JSON.stringify(data)}`,
  316. })
  317. break;
  318. case "提交":
  319. if (data.status != '新建') return wx.showToast({
  320. title: '当前状态不可提交!',
  321. icon: "none"
  322. })
  323. wx.showModal({
  324. title: '提示',
  325. content: `是否确定提交当前报价,提交后禁止使用部分功能`,
  326. complete: (res) => {
  327. if (res.confirm) _Http.basic({
  328. "id": 20221020165303,
  329. "version": 1,
  330. "content": {
  331. "sa_quotedpriceid": that.data.sa_quotedpriceid
  332. }
  333. }).then(res => {
  334. console.log("提交报价单", res)
  335. wx.showToast({
  336. title: res.msg == '成功' ? "提交成功" : res.msg,
  337. icon: "none"
  338. })
  339. if (res.msg == '成功') setTimeout(() => {
  340. that.getDetail();
  341. }, 300)
  342. })
  343. }
  344. })
  345. break;
  346. case "审核":
  347. if (data.status != '提交') return wx.showToast({
  348. title: '当前状态不可审核!',
  349. icon: "none"
  350. })
  351. wx.showModal({
  352. title: '提示',
  353. content: `是否通过当前报价`,
  354. complete: (res) => {
  355. if (res.confirm) _Http.basic({
  356. "id": 20221020165403,
  357. "version": 1,
  358. "content": {
  359. "sa_quotedpriceid": that.data.sa_quotedpriceid,
  360. ischeck: true
  361. }
  362. }).then(res => {
  363. console.log("审核报价单", res)
  364. wx.showToast({
  365. title: res.msg == '成功' ? "审核成功" : res.msg,
  366. icon: "none"
  367. })
  368. if (res.msg == '成功') setTimeout(() => {
  369. that.getDetail();
  370. }, 300)
  371. })
  372. }
  373. })
  374. break;
  375. case "反审核":
  376. if (data.status != '审核') return wx.showToast({
  377. title: '当前状态不可反审核!',
  378. icon: "none"
  379. })
  380. wx.showModal({
  381. title: '提示',
  382. content: `是否退回当前报价`,
  383. complete: (res) => {
  384. if (res.confirm) _Http.basic({
  385. "id": 20221020165403,
  386. "version": 1,
  387. "content": {
  388. "sa_quotedpriceid": that.data.sa_quotedpriceid,
  389. ischeck: false
  390. }
  391. }).then(res => {
  392. console.log("反审核报价单", res)
  393. wx.showToast({
  394. title: res.msg == '成功' ? "反审核成功" : res.msg,
  395. icon: "none"
  396. })
  397. if (res.msg == '成功') setTimeout(() => {
  398. that.getDetail();
  399. }, 300)
  400. })
  401. }
  402. })
  403. break;
  404. case "撤回":
  405. console.log(data.status)
  406. if (data.status != '提交') return wx.showToast({
  407. title: '当前状态不可撤回审核!',
  408. icon: "none"
  409. })
  410. wx.showModal({
  411. title: '提示',
  412. content: `是否撤回审核当前报价`,
  413. complete: (res) => {
  414. if (res.confirm) _Http.basic({
  415. "id": 20221125162803,
  416. "version": 1,
  417. "content": {
  418. "sa_quotedpriceid": that.data.sa_quotedpriceid
  419. }
  420. }).then(res => {
  421. console.log("撤回报价单", res)
  422. wx.showToast({
  423. title: res.msg == '成功' ? "撤回审核成功" : res.msg,
  424. icon: "none"
  425. })
  426. if (res.msg == '成功') setTimeout(that.getDetail, 300)
  427. })
  428. }
  429. })
  430. break;
  431. case "跟进":
  432. wx.navigateTo({
  433. url: `/packageA/setclient/modules/trace/add/index?ownertable=sa_quotedprice&ownerid=${data.sa_quotedpriceid}`,
  434. })
  435. break;
  436. case "复制":
  437. const {
  438. billno,
  439. sa_quotedpriceid
  440. } = data;
  441. wx.showModal({
  442. title: '提示',
  443. content: `是否确认复制“${billno}”`,
  444. complete: ({
  445. confirm
  446. }) => {
  447. if (confirm) _Http.basic({
  448. "id": 20221209094103,
  449. "content": {
  450. sa_quotedpriceid
  451. },
  452. }).then(res => {
  453. console.log("复制报价单", res)
  454. wx.showToast({
  455. title: res.msg == '成功' ? '复制成功' : res.msg,
  456. icon: "none",
  457. mask: true
  458. });
  459. if (res.msg == '成功') setTimeout(() => {
  460. wx.redirectTo({
  461. url: `/packageA/offers/detail?sa_quotedpriceid=${res.data.sa_quotedpriceid}`,
  462. })
  463. let page = getCurrentPages().find(v => v.__route__ == 'packageA/offers/index');
  464. if (page) page.getList(true);
  465. }, 300)
  466. })
  467. }
  468. })
  469. break;
  470. case "作废":
  471. wx.showModal({
  472. title: '提示',
  473. content: '是否确认作废该报价单?',
  474. complete: ({
  475. confirm
  476. }) => {
  477. if (confirm) _Http.basic({
  478. "id": 20221020165503,
  479. "version": 1,
  480. "content": {
  481. "sa_quotedpriceids": [this.data.detail.sa_quotedpriceid]
  482. }
  483. }).then(res => {
  484. wx.showToast({
  485. title: res.msg == '成功' ? '已作废报价单' : res.msg,
  486. icon: "none"
  487. });
  488. if (res.msg == '成功') {
  489. setTimeout(() => {
  490. getCurrentPages().forEach(v => {
  491. if (v.__route__ == 'packageA/offers/index') {
  492. v.setData({
  493. list: v.data.list.filter(value => value.sa_quotedpriceid != this.data.detail.sa_quotedpriceid),
  494. 'content.total': v.data.content.total - 1
  495. })
  496. }
  497. })
  498. wx.navigateBack();
  499. }, 300)
  500. }
  501. })
  502. }
  503. })
  504. break;
  505. case "更换负责人":
  506. wx.navigateTo({
  507. url: `/pages/group/select?data=${JSON.stringify({
  508. ownertable:"sa_quotedprice",
  509. ownerid:data.sa_quotedpriceid,
  510. })}&radio=true&principal=true`,
  511. })
  512. break;
  513. }
  514. },
  515. /* 更换负责人 */
  516. handelSubmit(arr) {
  517. const that = this;
  518. wx.showModal({
  519. title: '提示',
  520. content: '是否确认更换负责人',
  521. complete: ({
  522. confirm
  523. }) => {
  524. if (confirm) _Http.basic({
  525. "id": 20220930103701,
  526. "content": {
  527. ownertable: "sa_quotedprice",
  528. ownerid: that.data.detail.sa_quotedpriceid,
  529. userid: arr[0]
  530. }
  531. }).then(res => {
  532. console.log("更换负责人", res)
  533. if (res.msg != '成功') return wx.showToast({
  534. title: res.data,
  535. icon: "none"
  536. });
  537. wx.showToast({
  538. title: '更换成功!',
  539. icon: "none",
  540. mask: true
  541. });
  542. setTimeout(() => {
  543. that.getDetail();
  544. wx.navigateBack();
  545. /* getCurrentPages().forEach(v => {
  546. if (['packageA/project/index'].includes(v.__route__)) v.getList(true)
  547. }) */
  548. }, 300)
  549. })
  550. }
  551. })
  552. }
  553. })