index.js 38 KB

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