index.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /*******************************************************************************
  2. * Copyright(c) 2024 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:一览界面混入
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 周兴 2024-1-19 1.00 新建
  9. *******************************************************************************/
  10. const api = require('../utils/api.js');
  11. const config = require('@/config/config.js');
  12. const Constants = require('../utils/Constants.js')
  13. import Dialog from '@/dist/dialog/dialog.js';
  14. const app = getApp()
  15. module.exports = {
  16. data: {
  17. // 系统版本
  18. gradeCode: null,
  19. // 标准版(免费)标识
  20. freeVersionFlag: true,
  21. // 图片路径
  22. imageUrl: config.image_url + '/static/img/',
  23. // 加载中
  24. loading: false,
  25. // 没有更多
  26. noMore: false,
  27. // 路由名称
  28. routeObjName: null,
  29. // 当前服务
  30. service: null,
  31. // 当前路由
  32. route: null,
  33. // 主键Id
  34. primaryKey: null,
  35. //菜单编码
  36. functionCode: null,
  37. // 是否分页
  38. pageFlag: true,
  39. // 是否回到上一界面
  40. backFlag: false,
  41. // 分页
  42. pageInfo: {
  43. pageSize: Constants.PAGE_SIZE,
  44. currentPage: 1
  45. },
  46. // 查询条件
  47. searchContent: [],
  48. // 查询条件实体
  49. searchForm: null,
  50. // 大查询文本
  51. searchText: null,
  52. // 保存参数
  53. params: null,
  54. // 查询结果集
  55. tableData: [],
  56. // 需要校验表单Id名
  57. formName: 'dkForm',
  58. // 表单实体
  59. formData: null,
  60. // 表单类型
  61. formMode: null,
  62. // id
  63. id: null,
  64. // other
  65. other: null,
  66. // 当前数据
  67. item: null,
  68. // 新建后刷新一览界面标识
  69. refreshByAdd: false,
  70. // 表名
  71. table: null,
  72. // 界面的功能编码
  73. menuUuid: null,
  74. // 操作手册跳转的链接
  75. guideUrl: null,
  76. // 语言包
  77. $t: app.globalData.lang,
  78. // 是否进行校验
  79. validFlag: true,
  80. // 导出excel
  81. exportCols: null,
  82. // 初始加载查询
  83. initSearchFlag: true,
  84. // params事件监听,解决重复进入的问题
  85. paramsInitFlag: true,
  86. // 自定义导航栏的高度
  87. navBarHeight: 0,
  88. // 页面头部高度
  89. stickyHeight: 0,
  90. // 页面的员工和部门
  91. orgStaffInfo: null,
  92. },
  93. /**
  94. * @desc : 获取路由信息,供data中的对象使用
  95. * @author : 周兴
  96. * @date : 2024/1/19
  97. */
  98. $routeUrl(routeObjName, key) {
  99. return app.globalData['routeUrl'][routeObjName][key]?.url
  100. },
  101. /**
  102. * @desc : 获取语言的方法
  103. * @author : 周兴
  104. * @date : 2024/1/19
  105. */
  106. $t(name) {
  107. if (this.data.$t[name]) {
  108. return this.data.$t[name];
  109. } else {
  110. return name;
  111. }
  112. },
  113. /**
  114. * @desc : 点击上传附件
  115. * @author : 周兴
  116. * @date : 2024/6/24
  117. */
  118. clickAttach(e) {
  119. this.setData({
  120. loading: true,
  121. })
  122. },
  123. /**
  124. * @desc : 上传附件成功
  125. * @author : 周兴
  126. * @date : 2024/6/24
  127. */
  128. uploadSucess(e) {
  129. this.setData({
  130. loading: false,
  131. })
  132. },
  133. /**
  134. * @desc : 上传附件取消
  135. * @author : 周兴
  136. * @date : 2024/6/24
  137. */
  138. uploadError(e) {
  139. this.setData({
  140. loading: false,
  141. })
  142. },
  143. /**
  144. * @desc : 查询共通方法
  145. * @author : 周兴
  146. * @date : 2024/1/19
  147. */
  148. searchData(e) {
  149. // 加载中
  150. this.setData({
  151. loading: true
  152. })
  153. // 如果重新查询,需要nomore标识重置为false //并且分页重置
  154. if (e != 'more' && this.data.noMore) {
  155. this.setData({
  156. noMore: false,
  157. pageInfo: {
  158. pageSize: Constants.PAGE_SIZE,
  159. currentPage: 1
  160. },
  161. })
  162. }
  163. // 给参数赋值
  164. let params = this._setSearchParams();
  165. this._getData(params).then(res => {
  166. this.setData({
  167. loading: false
  168. })
  169. if (res == null) {
  170. return;
  171. }
  172. if (res && res.data.code === Constants.SUCESS_CODE) {
  173. let tableData = this.data.tableData;
  174. let list = []
  175. if (res.data.data && Array.isArray(res.data.data)) {
  176. list = res.data.data;
  177. } else {
  178. list = res.data.data.list
  179. }
  180. // 如果不是翻页,需要清空
  181. if (e != 'more') {
  182. let pageInfo = this.data.pageInfo
  183. pageInfo.currentPage = 1
  184. tableData = []
  185. this.setData({
  186. tableData: tableData,
  187. pageInfo
  188. })
  189. }
  190. // if (!list || list.length === 0) {
  191. // this.setData({
  192. // noMore: true
  193. // })
  194. // }
  195. if (e == 'more') {
  196. // 如果返回数据小于页数,就不能再继续翻页了
  197. if (list.length == 0 || list.length < this.data.pageInfo.pageSize) {
  198. this.setData({
  199. noMore: true
  200. })
  201. }
  202. }
  203. // else {
  204. // this.setData({
  205. // noMore: true
  206. // })
  207. // }
  208. // 把查询数据加入到结果集中
  209. tableData = tableData.concat(list)
  210. this.setData({
  211. tableData: tableData
  212. })
  213. // 如果页面需要后续处理,再进行处理
  214. if (this.handleSearchData) {
  215. this.handleSearchData(tableData);
  216. }
  217. // 不处理数据 直接把接口返回值 扔到方法中 目前 销售订单的详情在用
  218. if (this.notProcessedResult) {
  219. this.notProcessedResult(res);
  220. }
  221. }
  222. });
  223. },
  224. /**
  225. * @desc : 给查询实体赋值
  226. * @author : 周兴
  227. * @date : 2024/1/19
  228. */
  229. _setSearchParams() {
  230. let params = {}
  231. if (this.data.searchForm) {
  232. params = JSON.parse(this.data.searchForm);
  233. }
  234. // 如果需要分页
  235. if (this.data.pageFlag) {
  236. params.pageSize = this.data.pageInfo.pageSize;
  237. params.currentPage = this.data.pageInfo.currentPage;
  238. }
  239. if (this.setSearchParams) {
  240. // 调用参数赋值
  241. params = this.setSearchParams(params);
  242. }
  243. return params;
  244. },
  245. /**
  246. * @desc : 执行查询共通方法
  247. * @author : 周兴
  248. * @date : 2024/1/19
  249. */
  250. _getData(params) {
  251. return new Promise(resolve => {
  252. if (this.getData) {
  253. let res = this.getData(params);
  254. resolve(res);
  255. } else {
  256. this.setData({
  257. loading: false
  258. })
  259. return (null)
  260. }
  261. })
  262. },
  263. /**
  264. * @desc : 跳转明细
  265. * @author : 周兴
  266. * @date : 2024/1/22
  267. */
  268. toDetail(e) {
  269. if (e) {
  270. let item = null;
  271. if (e.currentTarget.dataset.item) {
  272. item = e.currentTarget.dataset.item
  273. }
  274. if (!e.detail) {
  275. e.detail = {}
  276. }
  277. if (item) {
  278. e.detail.item = item;
  279. }
  280. if (e.detail.item) {
  281. let button = {
  282. formMode: Constants.formMode.edit
  283. }
  284. e.detail.item.button = button
  285. }
  286. // 如果name不传递,默认为edit
  287. e.detail.name = 'edit'
  288. }
  289. this.open(e);
  290. },
  291. /**
  292. * @desc : 点击按钮
  293. * @author : 周兴
  294. * @date : 2024/1/22
  295. */
  296. open(e) {
  297. // 如果没有路由就不往下进行
  298. if (!this.data.routeObjName) return;
  299. let name;
  300. let item;
  301. if (typeof e === 'object') {
  302. if (e && e.currentTarget) {
  303. name = e.currentTarget.dataset.name;
  304. item = e.currentTarget.dataset.item;
  305. }
  306. // 那可能是在detail中
  307. if (!name && e.detail) {
  308. name = e.detail.name;
  309. item = e.detail.item;
  310. }
  311. if (item && this.data.primaryKey) {
  312. item.id = item[this.data.primaryKey]
  313. }
  314. } else {
  315. name = e;
  316. }
  317. // 默认是新建
  318. if (!name) {
  319. name = 'add'
  320. }
  321. let routeUrl = this.data.route[name];
  322. console.log('rreee',routeUrl,name);
  323. if (!routeUrl) return;
  324. this._openValidData(item, name, routeUrl.valid).then(res => {
  325. if (!res) {
  326. return;
  327. }
  328. // 如果有链接,就跳转
  329. if (routeUrl.url) {
  330. let url = routeUrl.url
  331. //保存按钮自定义跳转URL
  332. if (e.detail && e.detail.customUrl) {
  333. url = e.detail.customUrl
  334. }
  335. //阻止并提示信息
  336. if (routeUrl.tipMethod) {
  337. let result = this[routeUrl.tipMethod](item)
  338. if (result) {
  339. // 是否弹出询问框
  340. Dialog.confirm({
  341. message: result,
  342. }).then(() => {
  343. }).catch(() => {
  344. })
  345. return
  346. }
  347. }
  348. let _this = this;
  349. wx.navigateTo({
  350. url: url,
  351. events: {
  352. // 保存成功后刷新页面
  353. refresh: function (data) {
  354. if (data.backFlag) {
  355. // 刷新一览界面
  356. wx.reLaunch({
  357. url: '/pages/welcome/welcome?' + name + '=true',
  358. })
  359. } else {
  360. // 刷新一览界面
  361. _this.searchData();
  362. }
  363. }
  364. },
  365. success: function (res) {
  366. let data = {}
  367. if (item && item.button && item.button.idKey) {
  368. data['id'] = item[item.button.idKey]
  369. }
  370. if (item && item.id) {
  371. data['id'] = item.id
  372. }
  373. if (item && item.button && item.button.formMode) {
  374. data['formMode'] = item.button.formMode
  375. }
  376. //api 上的优先
  377. if (_this.data.route[name].formMode) {
  378. data['formMode'] = _this.data.route[name].formMode
  379. }
  380. if (_this.data.route[name].idKey) {
  381. data['id'] = item[_this.data.route[name].idKey]
  382. }
  383. if (item && item.button && item.button.formType) {
  384. data['formType'] = item.button.formType
  385. }
  386. if (routeUrl.formType) {
  387. data['formType'] = routeUrl.formType
  388. }
  389. // 新建增加默认的新建formMode
  390. if (name === 'add') {
  391. data['formMode'] = Constants.formMode.add;
  392. }
  393. data['item'] = item
  394. console.log('data', data);
  395. res.eventChannel.emit('params', data);
  396. }
  397. })
  398. } else {
  399. // 如果是方法就执行方法
  400. if (routeUrl.method) {
  401. // 有提示信息,就提出
  402. if (routeUrl.question) {
  403. // 是否弹出询问框
  404. Dialog.confirm({
  405. message: '是否进行该操作?',
  406. }).then(() => {
  407. this[routeUrl.method](item);
  408. }).catch(() => {
  409. })
  410. } else {
  411. this[routeUrl.method](item);
  412. }
  413. }
  414. }
  415. })
  416. },
  417. /**
  418. * @desc : 打印票据
  419. * @author : 周兴
  420. * @date : 2024/4/22
  421. */
  422. printedBill(row) {
  423. // 查询票据
  424. let docName = app.globalData['routeUrl'][this.data.routeObjName].docName
  425. console.log('row',row,docName);
  426. if (!docName || !row || !row.id) {
  427. return;
  428. }
  429. this.setData({
  430. loading: true
  431. })
  432. let service = app.globalData['printLayoutService']
  433. // 查询打印票据
  434. this.excute(service, service.selectByCond, { docName: docName.title, flgValid: true }).then(res => {
  435. this.setData({
  436. loading: false
  437. })
  438. if (res.data.code == Constants.SUCESS_CODE) {
  439. let tableList = res.data.data.list;
  440. if (tableList && tableList.length > 0) {
  441. // 如果只有一个票据,直接调取打印
  442. if (tableList.length == 1) {
  443. this.print(docName.key, tableList[0].layoutId, row.id)
  444. } else {
  445. // 多个跳转到票据打印页面
  446. wx.navigateTo({
  447. url: '/package-basic-data/pages/print-layout/print-layout',
  448. success: function (res) {
  449. res.eventChannel.emit('print', { data: tableList, docName: docName.key, dataId: row.id });
  450. }
  451. })
  452. }
  453. }
  454. }
  455. });
  456. },
  457. /**
  458. * @desc : 调取打印
  459. * @author : 周兴
  460. * @date : 2024/4/22
  461. */
  462. print(docName, layoutId, dataId) {
  463. wx.navigateTo({
  464. url: '/package-base-select/pages/web-view-select/web-view-select',
  465. success: function (res) {
  466. // res.eventChannel.emit('url', 'http://localhost:8081/wx-print?svc_code=' + app.globalData.company.svcCode + '&cp_id=' + app.globalData.company.cpId + '&doc=' + docName + '&layout_id=' + layoutId + '&data_id=' + dataId);
  467. res.eventChannel.emit('url', 'https://s.dev01.dkiboss.com:7000/wx-print?svc_code=' + app.globalData.company.svcCode + '&cp_id=' + app.globalData.company.cpId + '&doc=' + docName + '&layout_id=' + layoutId + '&data_id=' + dataId);
  468. }
  469. })
  470. },
  471. /**
  472. * @desc : 执行保存方法
  473. * @author : 周兴
  474. * @date : 2024/1/22
  475. */
  476. save({
  477. saveFlag = true,
  478. url,
  479. dialogMes
  480. }) {
  481. // 解决点击太快,blur没有切换过来的问题
  482. setTimeout(() => {
  483. // 校验
  484. this._validData().then(res => {
  485. if (!res) {
  486. return;
  487. }
  488. this.setData({
  489. loading: true
  490. })
  491. // 设置参数
  492. this._setParams();
  493. // 如果需要有询问
  494. if (dialogMes) {
  495. Dialog.confirm({
  496. message: dialogMes,
  497. }).then(() => {
  498. // 执行保存方法
  499. if (saveFlag) {
  500. this._handleSaveData();
  501. } else {
  502. let that = this
  503. this.setData({
  504. loading: false
  505. })
  506. wx.navigateTo({
  507. url: url,
  508. events: {
  509. // 回调后
  510. refresh: function (data) {
  511. if (that.handleSaveData) {
  512. that.handleSaveData();
  513. }
  514. }
  515. },
  516. success: function (res) {
  517. // 通过eventChannel向被打开页面传送数据
  518. res.eventChannel.emit('params', {
  519. params: that.data.params
  520. })
  521. }
  522. })
  523. }
  524. })
  525. } else {
  526. // 执行保存方法
  527. if (saveFlag) {
  528. this._handleSaveData();
  529. } else {
  530. let that = this
  531. this.setData({
  532. loading: false
  533. })
  534. wx.navigateTo({
  535. url: url,
  536. events: {
  537. // 回调后
  538. refresh: function (data) {
  539. // 回退
  540. if (data.backFlag) {
  541. const eventChannel = that.getOpenerEventChannel();
  542. eventChannel.emit('refresh', {
  543. id: 1
  544. })
  545. wx.navigateBack({
  546. delta: 1
  547. })
  548. } else {
  549. // 新建界面清空
  550. that.setData({
  551. formData: null
  552. })
  553. var pages = getCurrentPages();
  554. var prevPage = pages[pages.length - 3]; //上上一个页面
  555. if (prevPage) {
  556. prevPage.setData({
  557. refreshByAdd: true
  558. })
  559. }
  560. if (that.handleSaveData) {
  561. that.handleSaveData();
  562. }
  563. }
  564. }
  565. },
  566. success: function (res) {
  567. // 通过eventChannel向被打开页面传送数据
  568. res.eventChannel.emit('params', {
  569. params: that.data.params,
  570. formType: that.data.params.formType ? that.data.params.formType : ''
  571. })
  572. }
  573. })
  574. }
  575. }
  576. });
  577. }, 300)
  578. },
  579. /**
  580. * @desc : 保存方法
  581. * @author : 周兴
  582. * @date : 2024/1/22
  583. */
  584. _handleSaveData() {
  585. this._saveData(this.data.params).then(result => {
  586. if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
  587. wx.showToast({
  588. title: '保存成功',
  589. image: '/static/image/success.png',
  590. duration: 2000
  591. })
  592. // 如果页面需要后续处理,再进行处理
  593. if (this.handleData) {
  594. this.handleData();
  595. }
  596. //是否返回上一页
  597. if (!this.data.navigateBackFlag) {
  598. // 非新建页面回到上一个页面
  599. if (this.data.formMode != Constants.formMode.add || this.data.backFlag) {
  600. // 给父页面传递数据
  601. const eventChannel = this.getOpenerEventChannel();
  602. eventChannel.emit('refresh', {
  603. id: 1
  604. })
  605. setTimeout(() => {
  606. wx.navigateBack({
  607. data: 1
  608. })
  609. }, 2000)
  610. } else {
  611. // 新建界面清空
  612. this.setData({
  613. formData: null
  614. })
  615. if (this.handleSaveData) {
  616. this.handleSaveData();
  617. }
  618. // 清空页面金额
  619. if (this.clearAmount) {
  620. this.clearAmount();
  621. }
  622. var pages = getCurrentPages();
  623. var prevPage = pages[pages.length - 2]; //上一个页面
  624. prevPage.setData({
  625. refreshByAdd: true
  626. })
  627. }
  628. } else {
  629. //不返回上一页 并且执行查询接口
  630. // 执行查询方法
  631. this.searchData()
  632. }
  633. setTimeout(() => {
  634. this.setData({
  635. loading: false
  636. })
  637. }, 2000)
  638. } else {
  639. setTimeout(() => {
  640. this.setData({
  641. loading: false
  642. })
  643. }, 2000)
  644. }
  645. });
  646. },
  647. /**
  648. * @desc : 给实体赋值
  649. * @author : 周兴
  650. * @date : 2024/1/19
  651. */
  652. _setParams() {
  653. let params = {}
  654. if (this.data.formData && JSON.stringify(this.data.formData) !== '{}') {
  655. params = JSON.parse(this.data.formData);
  656. }
  657. this.setData({
  658. params: params
  659. })
  660. if (this.setParams) {
  661. // 调用参数赋值
  662. let parm = this.setParams(params);
  663. this.setData({
  664. params: parm
  665. })
  666. }
  667. },
  668. /**
  669. * @desc : 打开工具校验,(不给外部调用)
  670. * @author : 周兴
  671. * @date : 2024/1/22 14:13
  672. */
  673. _openValidData(item, name, valid) {
  674. return new Promise(resolve => {
  675. // 页面校验
  676. if (this.openValidData && valid) {
  677. let flag = this.openValidData(item, name);
  678. resolve(flag);
  679. } else {
  680. resolve(true);
  681. }
  682. })
  683. },
  684. /**
  685. * @desc : 校验,(不给外部调用)
  686. * @author : 周兴
  687. * @date : 2024/1/22 14:13
  688. */
  689. _validData() {
  690. return new Promise(resolve => {
  691. // 不需要校验直接返回
  692. if (!this.data.validFlag) {
  693. resolve(true);
  694. }
  695. // 非空校验
  696. if (this.data.formName) {
  697. const component = this.selectComponent('#' + this.data.formName);
  698. if (component && component.validData) {
  699. let valid = component.validData();
  700. if (!valid) {
  701. resolve(false);
  702. }
  703. }
  704. }
  705. // 页面校验
  706. if (this.validData) {
  707. let flag = this.validData();
  708. resolve(flag);
  709. } else {
  710. resolve(true);
  711. }
  712. })
  713. },
  714. /**
  715. * @desc : 给参数赋值(不给外部调用)
  716. * @author : 周兴
  717. * @date : 2024/1/22 14:33
  718. */
  719. _saveData(params) {
  720. return new Promise(resolve => {
  721. let res = this.saveData(params);
  722. resolve(res);
  723. })
  724. },
  725. /**
  726. * @desc : 查询明细的方法(不给外部调用)
  727. * @author : 周兴
  728. * @date : 2022/12/8 17:56
  729. */
  730. _detail(id) {
  731. this.loading = true;
  732. this.detail(id)?.then(res => {
  733. if (res.data.code === Constants.SUCESS_CODE && res.data.data) {
  734. // 给变量赋值
  735. if (this.setValuesByEdit) {
  736. this.setValuesByEdit(res.data.data)
  737. }
  738. }
  739. setTimeout(() => {
  740. this.loading = false
  741. }, 300)
  742. })
  743. },
  744. /**
  745. * @desc : 根据id查询数据
  746. * @date : 2024/2/26 15:49
  747. * @author : 周兴
  748. */
  749. detail(id) {
  750. return this.excute(this.data.service, id, null);
  751. },
  752. /**
  753. * @desc : 查询明细的方法(不给外部调用)
  754. * @author : 周兴
  755. * @date : 2022/12/8 17:56
  756. */
  757. _other(param) {
  758. this.loading = true;
  759. // 给参数赋值
  760. this._getData(param).then(res => {
  761. if (res && res.data.code === Constants.SUCESS_CODE) {
  762. // 给变量赋值
  763. if (this.setValuesByEdit) {
  764. this.setValuesByEdit(res.data.data)
  765. }
  766. }
  767. setTimeout(() => {
  768. this.loading = false
  769. }, 300)
  770. });
  771. },
  772. /**
  773. * @desc : 微信支付-随机生成单号
  774. * @date : 2022/5/12 13:49
  775. * @author : 姜永辉
  776. */
  777. generateRandomNo() {
  778. let timestamp = new Date().getTime().toString() // 当前时间戳
  779. let randomPart = Math.random().toString(36).substring(2, 10) // 随机字符串
  780. return timestamp + randomPart
  781. },
  782. /**
  783. * @desc : 微信支付
  784. * @date : 2022/5/12 13:49
  785. * @author : 姜永辉
  786. */
  787. toPay(e, closeFlag = true) {
  788. let wechatPayService = app.globalData['wechatPayService']
  789. let params = {
  790. openId: app.globalData.openid,
  791. // paymentSn: this.generateOrderNumber(),
  792. payFee: e.tradeAmount,
  793. paymentSn: e.tradeNo,
  794. }
  795. return this.excute(wechatPayService, wechatPayService.unifiedOrder, params).then(res => {
  796. if (res.data.code === Constants.SUCESS_CODE) {
  797. var appid = res.data.data.appId
  798. var timeStamp = res.data.data.timeStamp
  799. var nonce_str = res.data.data.nonceStr
  800. var pk = res.data.data.pack
  801. var paySign = res.data.data.paySign
  802. let _this = this
  803. //调用微信支付
  804. wx.requestPayment({
  805. 'appId': appid,
  806. 'timeStamp': timeStamp,
  807. 'nonceStr': nonce_str,
  808. 'package': pk,
  809. 'signType': 'MD5',
  810. 'paySign': paySign,
  811. 'success': function (res) {
  812. wx.showToast({
  813. title: '支付成功',
  814. image: '/static/image/success.png',
  815. duration: 2000
  816. })
  817. _this.setData({
  818. loading: false
  819. })
  820. if (closeFlag) {
  821. const eventChannel = _this.getOpenerEventChannel();
  822. eventChannel.emit('refresh', {
  823. id: 1,
  824. backFlag: true
  825. })
  826. // 调转主页
  827. wx.reLaunch({
  828. url: '/pages/welcome/welcome',
  829. })
  830. wx.navigateBack({
  831. delta: 1
  832. })
  833. }
  834. },
  835. 'fail': function (res) {
  836. _this.setData({
  837. loading: false
  838. })
  839. },
  840. 'complete': function (res) {
  841. }
  842. });
  843. }
  844. });
  845. },
  846. /**
  847. * @desc : 导出excel
  848. * @author : 周兴
  849. * @date : 2024/4/23
  850. */
  851. export() {
  852. let exportCols = this.data.exportCols;
  853. if (!exportCols) {
  854. return;
  855. }
  856. let params = {}
  857. if (this.data.searchForm) {
  858. params = JSON.parse(this.data.searchForm);
  859. }
  860. let otherSearchParams = this.data.otherSearchParams;
  861. if (otherSearchParams) {
  862. // 把其他查询条件拼到查询实体上去
  863. params = Object.assign(params, otherSearchParams);
  864. }
  865. params.name = this.data.objectCode;
  866. if (params.flgViewItem) {
  867. params.name = params.name + '-item'
  868. }
  869. params.title = this.data.title;
  870. params.currentPage = 1;
  871. params.pageSize = Constants.MAX_PAGE_SIZE;
  872. if (exportCols) {
  873. // 增加序号
  874. params.condition = Object.assign({ 'seq': '序号' }, exportCols);
  875. }
  876. let service = app.globalData['exportService']
  877. let url = config.image_url.replace('file', '') + 'api/'
  878. // let url = 'http://192.168.0.57:7001/'
  879. url = url + service.prefix + service.export
  880. if (app.globalData.company && app.globalData.company.svcCode) {
  881. url = url.replace('mdm-server', 'mdm-server' + '-' + app.globalData.company.svcCode.replace('_', '-'))
  882. }
  883. this.setData({
  884. loading: true
  885. })
  886. let _this = this;
  887. wx.request({
  888. url: url,
  889. header: {
  890. 'content-type': 'application/json',
  891. 'Authorization': 'Bearer ' + app.globalData.token,
  892. 'i18n': Constants.lan
  893. },
  894. data: params,
  895. method: 'POST',
  896. success: function (res) {
  897. if (res.data.code == Constants.SUCESS_CODE) {
  898. if (res.data) {
  899. let url = config.image_url.replace('file', 'excel')
  900. _this.downloadFile(url + '/' + res.data.data);
  901. }
  902. }
  903. _this.setData({
  904. loading: false
  905. })
  906. },
  907. fail: function (err) {
  908. // reject(err);
  909. _this.setData({
  910. loading: false
  911. })
  912. }
  913. })
  914. },
  915. /**
  916. * 下载文件资源到本地 打开文档
  917. * @param {*} url
  918. */
  919. downloadFile(url, type = 'xlsx') {
  920. let that = this
  921. wx.downloadFile({
  922. url: url,
  923. success: function (resd) {
  924. if (resd.statusCode == Constants.SUCESS_CODE) {
  925. const filePath = resd.tempFilePath
  926. // 说明有值
  927. if (filePath) {
  928. that.setData({
  929. filePath: filePath
  930. })
  931. // 如果有值就打开文档
  932. wx.openDocument({
  933. filePath: filePath,
  934. showMenu: true,
  935. fileType: type,
  936. success: function (reso) {
  937. }
  938. })
  939. }
  940. }
  941. }, fail(err) {
  942. }
  943. })
  944. },
  945. /**
  946. * @desc : 执行方法
  947. * @author : 周兴
  948. * @date : 2024/1/22
  949. */
  950. excute(service, method, params, showMessage = false, button = '') {
  951. if (service && method) {
  952. let url = service.prefix + method;
  953. let param = params;
  954. if (params && typeof params != 'object') {
  955. url = url + '/' + params;
  956. param = null;
  957. }
  958. let res = api.request(url, 'POST', param);
  959. if (res) {
  960. res.then(t => {
  961. if (showMessage) {
  962. if (t.data.code === Constants.SUCESS_CODE) {
  963. if (button == '') {
  964. button = Constants.Messages.save_sucess;
  965. }
  966. wx.showToast({
  967. title: button,
  968. image: '/static/image/success.png',
  969. duration: 2000
  970. })
  971. // if (searchFlag) {
  972. // this.searchData();
  973. // }
  974. } else {
  975. if (t.message) {
  976. wx.showToast({
  977. title: t.message,
  978. image: '/static/image/warning.png',
  979. duration: 2000
  980. })
  981. }
  982. }
  983. }
  984. })
  985. }
  986. return res;
  987. }
  988. },
  989. /**
  990. * @desc : 处理数据的有效标识(启用/停用)
  991. * @author : 周兴
  992. * @date : 2024/1/22
  993. */
  994. handleDataIsValid(e) {
  995. let item = e.detail.item;
  996. let primaryKey = this.data.primaryKey;
  997. let service = this.data.service;
  998. if (item && primaryKey && item[primaryKey] && service) {
  999. let method = item.flgValid ? service.disable : service.enable;
  1000. return this.excute(service, method, item[primaryKey]).then(res => {
  1001. if (res.data.code == Constants.SUCESS_CODE) {
  1002. wx.showToast({
  1003. title: '操作成功',
  1004. image: '/static/image/success.png',
  1005. duration: 2000
  1006. })
  1007. // 重新查询
  1008. this.searchData()
  1009. }
  1010. });
  1011. }
  1012. },
  1013. /**
  1014. * @desc : 处理数据的有效标识(启用/停用)(用于像基础资料和商品属性)
  1015. * @author : 周兴
  1016. * @date : 2024/1/22
  1017. */
  1018. handleMoreDataIsValid(service, item, primaryKey) {
  1019. if (service && item && item[primaryKey]) {
  1020. let method = item.flgValid ? service.disable : service.enable;
  1021. return this.excute(service, method, item[primaryKey]).then(res => {
  1022. if (res.data.code == Constants.SUCESS_CODE) {
  1023. wx.showToast({
  1024. title: '操作成功',
  1025. image: '/static/image/success.png',
  1026. duration: 2000
  1027. })
  1028. this.setData({
  1029. pageInfo: {
  1030. currentPage: 1,
  1031. pageSize: Constants.PAGE_SIZE
  1032. }
  1033. })
  1034. // 重新查询
  1035. this.searchData()
  1036. }
  1037. });
  1038. }
  1039. },
  1040. /**
  1041. * @desc : 生命周期函数(onLoad)
  1042. * @author : 周兴
  1043. * @date : 2024/1/22
  1044. */
  1045. handleLoadData() {
  1046. let formMode = this.data.formMode;
  1047. formMode = formMode ? formMode : Constants.formMode.index
  1048. let noMore = false;
  1049. // 列表
  1050. if (formMode == Constants.formMode.index) {
  1051. if (this.data.initSearchFlag) {
  1052. // 默认查询
  1053. this.searchData();
  1054. }
  1055. // 更新用户功能频率
  1056. this.saveUserMenuFrequency();
  1057. // 编辑
  1058. } else if (formMode == Constants.formMode.edit) {
  1059. let id = this.data.id;
  1060. if (id) {
  1061. // 调用明细
  1062. this._detail(id);
  1063. }
  1064. noMore = true;
  1065. } else if (formMode == Constants.formMode.other) {
  1066. let other = this.data.other ? this.data.other : {};
  1067. other.id = this.data.id
  1068. if (other) {
  1069. // 调用
  1070. this._other(other);
  1071. }
  1072. } else if (formMode == Constants.formMode.add) {
  1073. noMore = true;
  1074. }
  1075. this.setData({
  1076. noMore: noMore
  1077. })
  1078. },
  1079. /**
  1080. * @desc : 加载暂存数据
  1081. * @author : 周兴
  1082. * @date : 2024/1/22
  1083. */
  1084. loadTempData() {
  1085. setTimeout(() => {
  1086. var pages = getCurrentPages();
  1087. var currentPage = pages[pages.length - 1];
  1088. let formData = this.data.formData
  1089. let formValue = app.globalData[currentPage.route];
  1090. if (formValue && formData && formData != formValue) {
  1091. Dialog.confirm({
  1092. message: '是否加载缓存数据',
  1093. }).then(() => {
  1094. // 执行保存方法
  1095. this.setData({
  1096. formData: formValue
  1097. })
  1098. // 删除缓存
  1099. delete app.globalData[currentPage.route]
  1100. }).catch(() => {
  1101. // 删除缓存
  1102. delete app.globalData[currentPage.route]
  1103. })
  1104. }
  1105. }, 1000)
  1106. },
  1107. /**
  1108. * @desc : 保存用户功能频率
  1109. * @author : 周兴
  1110. * @date : 2024/1/22
  1111. */
  1112. saveUserMenuFrequency() {
  1113. let menuUuid = this.data.menuUuid
  1114. if (menuUuid) {
  1115. let params = {
  1116. menuUuid: menuUuid,
  1117. staffId: app.globalData.user.staffId,
  1118. appCode: Constants.APP_CODE,
  1119. }
  1120. let service = app.globalData['userMenuFrequencyService']
  1121. // 保存用户功能频率
  1122. this.excute(service, service.save, params);
  1123. service = app.globalData['menuFrequencyService']
  1124. // 保存功能频率
  1125. params.cpId = app.globalData.company.cpId
  1126. this.excute(service, service.save, params);
  1127. }
  1128. },
  1129. /**
  1130. * 点击返回按钮返回上一层
  1131. * @author 刘尧
  1132. * @date 2024.05.31
  1133. */
  1134. handleNavBack() {
  1135. wx.navigateBack({
  1136. data: 1
  1137. })
  1138. },
  1139. /**
  1140. * @desc : 生命周期函数(onShow)
  1141. * @author : 周兴
  1142. * @date : 2024/1/22
  1143. */
  1144. onShow() {
  1145. // 新建后关闭新建后刷新页面
  1146. if (this.data.refreshByAdd) {
  1147. this.searchData();
  1148. if(this.customQuery){
  1149. //自定义查询
  1150. this.customQuery();
  1151. }
  1152. this.setData({
  1153. refreshByAdd: false
  1154. })
  1155. }
  1156. },
  1157. /**
  1158. * @desc : 生命周期函数(onLoad)
  1159. * @author : 周兴
  1160. * @date : 2024/1/22
  1161. */
  1162. onLoad() {
  1163. let routeObjName = this.data.routeObjName;
  1164. if (routeObjName) {
  1165. // 根据routeObjName获取当前服务
  1166. if (app.globalData[routeObjName + 'Service']) {
  1167. this.setData({
  1168. service: app.globalData[routeObjName + 'Service']
  1169. })
  1170. }
  1171. // 根据routeObjName获取当前路由
  1172. if (app.globalData['routeUrl'][this.data.routeObjName]) {
  1173. this.setData({
  1174. route: app.globalData['routeUrl'][routeObjName]
  1175. })
  1176. }
  1177. }
  1178. let gradeCode = app.globalData.company.gradeCode
  1179. this.setData({
  1180. gradeCode: gradeCode,
  1181. freeVersionFlag: gradeCode === 'STD'
  1182. })
  1183. // 接收父页面传递的参数
  1184. const eventChannel = this.getOpenerEventChannel();
  1185. if (eventChannel && JSON.stringify(eventChannel) !== '{}') {
  1186. let _this = this;
  1187. // 指定类型
  1188. eventChannel.once('params', function (data) {
  1189. if (!_this.data.paramsInitFlag) {
  1190. return;
  1191. }
  1192. _this.setData({
  1193. paramsInitFlag: false
  1194. })
  1195. // 获取参数
  1196. if (data.formMode) {
  1197. _this.setData({
  1198. id: data.id,
  1199. other: data.item ? (data.item.button ? data.item.button.other : null) : "",
  1200. formMode: data.formMode,
  1201. menuUuid: data.menuUuid,
  1202. objectCode: data.objectCode,
  1203. guideUrl: data.guideUrl
  1204. })
  1205. }
  1206. //是否返回原始页面
  1207. if (data.formReturnMode) {
  1208. _this.setData({
  1209. formReturnMode: data.formReturnMode
  1210. })
  1211. }
  1212. if (data.params) {
  1213. _this.setData({
  1214. params: data.params
  1215. })
  1216. }
  1217. //菜单编码
  1218. if (data.functionCode) {
  1219. _this.setData({
  1220. functionCode: data.functionCode
  1221. })
  1222. }
  1223. //选品弹出pop
  1224. if (data.popContent) {
  1225. _this.setData({
  1226. popContent: data.popContent
  1227. })
  1228. }
  1229. //控制标识 的 集合
  1230. if (data.controlFlags) {
  1231. _this.setData({
  1232. controlFlags: data.controlFlags
  1233. })
  1234. }
  1235. // 控制选择商品页面是否显示去入库
  1236. if(data.noWarehouseFlag){
  1237. _this.setData({
  1238. noWarehouseFlag:data.noWarehouseFlag
  1239. })
  1240. }
  1241. if (data.item) {
  1242. _this.setData({
  1243. item: data.item
  1244. })
  1245. }
  1246. if (data.formItem) {
  1247. _this.setData({
  1248. formItem: data.formItem
  1249. })
  1250. }
  1251. if (data.formType) { //表单保存修改按钮控制属性(标识)
  1252. _this.setData({
  1253. formType: data.formType
  1254. })
  1255. }
  1256. if (data.backFlag) {
  1257. _this.setData({
  1258. backFlag: data.backFlag
  1259. })
  1260. }
  1261. if (data.chooseType) {
  1262. _this.setData({
  1263. chooseData: data
  1264. })
  1265. }
  1266. if (data.route) {
  1267. _this.setData({
  1268. chooseRoute: data.route
  1269. })
  1270. }
  1271. // 加载后续数据
  1272. _this.handleLoadData();
  1273. // 页面设置初始信息
  1274. if (_this.loadInit) {
  1275. _this.loadInit();
  1276. }
  1277. if (data.formMode == Constants.formMode.add) {
  1278. // // 加载暂存数据
  1279. // _this.loadTempData();
  1280. }
  1281. })
  1282. setTimeout(() => {
  1283. _this.setData({
  1284. paramsInitFlag: true
  1285. })
  1286. }, 2000)
  1287. } else {
  1288. // 加载后续数据
  1289. this.handleLoadData();
  1290. // 页面设置初始信息
  1291. if (this.loadInit) {
  1292. this.loadInit();
  1293. }
  1294. }
  1295. },
  1296. /**
  1297. * @desc : 生命周期函数(onUnload)
  1298. * @author : 周兴
  1299. * @date : 2024/1/22
  1300. */
  1301. onUnload() {
  1302. // 关闭时,如果数据源有值,记录到缓存中
  1303. let formData = this.data.formData
  1304. // 获取当前页面的路由
  1305. var pages = getCurrentPages();
  1306. var currentPage = pages[pages.length - 1];
  1307. if (!currentPage) return;
  1308. let route = currentPage.route;
  1309. if (formData && formData != '{}') {
  1310. // 记录缓存
  1311. app.globalData[route] = formData;
  1312. } else {
  1313. // 删除对应的缓存
  1314. delete app.globalData[route]
  1315. }
  1316. },
  1317. /**
  1318. * @desc : 页面上拉触底事件的处理函数
  1319. * @author : 于继渤
  1320. * @date : 2022/5/24 12:16
  1321. */
  1322. onReachBottom: function () {
  1323. // 不分页也不能进行下翻
  1324. if (!this.data.pageFlag || this.data.loading || this.data.noMore) {
  1325. return;
  1326. }
  1327. this.setData({
  1328. pageInfo: {
  1329. pageSize: this.data.pageInfo.pageSize,
  1330. currentPage: this.data.pageInfo.currentPage + 1
  1331. }
  1332. })
  1333. // 执行查询方法
  1334. this.searchData('more')
  1335. },
  1336. /**
  1337. * @desc : 页面下拉刷新事件的处理函数
  1338. * @author : 于继渤
  1339. * @date : 2024/4/10 12:16
  1340. */
  1341. onPullDownRefresh(e) {
  1342. this.setData({
  1343. noMore: true
  1344. })
  1345. setTimeout(() => {
  1346. // 执行查询方法
  1347. this.searchData()
  1348. //停止刷新
  1349. wx.stopPullDownRefresh()
  1350. }, 300)
  1351. },
  1352. /**
  1353. * 获取自定义导航栏高度
  1354. * @author: 刘尧
  1355. */
  1356. getNavbarHeight(e) {
  1357. const detail = e.detail
  1358. this.setData({
  1359. navBarHeight: detail.height
  1360. })
  1361. },
  1362. /**
  1363. * 获取sticky组件高度
  1364. * @author: 刘尧
  1365. */
  1366. getStickyHeight(e) {
  1367. let that = this
  1368. let query = wx.createSelectorQuery().in(this);
  1369. query.select('#sticky').boundingClientRect(function (rect) {
  1370. that.setData({
  1371. stickyHeight: rect.height
  1372. })
  1373. }).exec()
  1374. }
  1375. };