| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390 |
- /*******************************************************************************
- * Copyright(c) 2024 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:一览界面混入
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 周兴 2024-1-19 1.00 新建
- *******************************************************************************/
- const api = require('../utils/api.js');
- const config = require('@/config/config.js');
- const Constants = require('../utils/Constants.js')
- import Dialog from '@/dist/dialog/dialog.js';
- const app = getApp()
- module.exports = {
- data: {
- // 系统版本
- gradeCode: null,
- // 标准版(免费)标识
- freeVersionFlag: true,
- // 图片路径
- imageUrl: config.image_url + '/static/img/',
- // 加载中
- loading: false,
- // 没有更多
- noMore: false,
- // 路由名称
- routeObjName: null,
- // 当前服务
- service: null,
- // 当前路由
- route: null,
- // 主键Id
- primaryKey: null,
- //菜单编码
- functionCode: null,
- // 是否分页
- pageFlag: true,
- // 是否回到上一界面
- backFlag: false,
- // 分页
- pageInfo: {
- pageSize: Constants.PAGE_SIZE,
- currentPage: 1
- },
- // 查询条件
- searchContent: [],
- // 查询条件实体
- searchForm: null,
- // 大查询文本
- searchText: null,
- // 保存参数
- params: null,
- // 查询结果集
- tableData: [],
- // 需要校验表单Id名
- formName: 'dkForm',
- // 表单实体
- formData: null,
- // 表单类型
- formMode: null,
- // id
- id: null,
- // other
- other: null,
- // 当前数据
- item: null,
- // 新建后刷新一览界面标识
- refreshByAdd: false,
- // 表名
- table: null,
- // 界面的功能编码
- menuUuid: null,
- // 操作手册跳转的链接
- guideUrl: null,
- // 语言包
- $t: app.globalData.lang,
- // 是否进行校验
- validFlag: true,
- // 导出excel
- exportCols: null,
- // 初始加载查询
- initSearchFlag: true,
- // params事件监听,解决重复进入的问题
- paramsInitFlag: true,
- // 自定义导航栏的高度
- navBarHeight: 0,
- // 页面头部高度
- stickyHeight: 0,
- // 页面的员工和部门
- orgStaffInfo: null,
- },
- /**
- * @desc : 获取路由信息,供data中的对象使用
- * @author : 周兴
- * @date : 2024/1/19
- */
- $routeUrl(routeObjName, key) {
- return app.globalData['routeUrl'][routeObjName][key]?.url
- },
- /**
- * @desc : 获取语言的方法
- * @author : 周兴
- * @date : 2024/1/19
- */
- $t(name) {
- if (this.data.$t[name]) {
- return this.data.$t[name];
- } else {
- return name;
- }
- },
- /**
- * @desc : 点击上传附件
- * @author : 周兴
- * @date : 2024/6/24
- */
- clickAttach(e) {
- this.setData({
- loading: true,
- })
- },
- /**
- * @desc : 上传附件成功
- * @author : 周兴
- * @date : 2024/6/24
- */
- uploadSucess(e) {
- this.setData({
- loading: false,
- })
- },
- /**
- * @desc : 上传附件取消
- * @author : 周兴
- * @date : 2024/6/24
- */
- uploadError(e) {
- this.setData({
- loading: false,
- })
- },
- /**
- * @desc : 查询共通方法
- * @author : 周兴
- * @date : 2024/1/19
- */
- searchData(e) {
- // 加载中
- this.setData({
- loading: true
- })
- // 如果重新查询,需要nomore标识重置为false //并且分页重置
- if (e != 'more' && this.data.noMore) {
- this.setData({
- noMore: false,
- pageInfo: {
- pageSize: Constants.PAGE_SIZE,
- currentPage: 1
- },
- })
- }
- // 给参数赋值
- let params = this._setSearchParams();
- this._getData(params).then(res => {
- this.setData({
- loading: false
- })
- if (res == null) {
- return;
- }
- if (res && res.data.code === Constants.SUCESS_CODE) {
- let tableData = this.data.tableData;
- let list = []
- if (res.data.data && Array.isArray(res.data.data)) {
- list = res.data.data;
- } else {
- list = res.data.data.list
- }
- // 如果不是翻页,需要清空
- if (e != 'more') {
- let pageInfo = this.data.pageInfo
- pageInfo.currentPage = 1
- tableData = []
- this.setData({
- tableData: tableData,
- pageInfo
- })
- }
- // if (!list || list.length === 0) {
- // this.setData({
- // noMore: true
- // })
- // }
- if (e == 'more') {
- // 如果返回数据小于页数,就不能再继续翻页了
- if (list.length == 0 || list.length < this.data.pageInfo.pageSize) {
- this.setData({
- noMore: true
- })
- }
- }
- // else {
- // this.setData({
- // noMore: true
- // })
- // }
- // 把查询数据加入到结果集中
- tableData = tableData.concat(list)
- this.setData({
- tableData: tableData
- })
- // 如果页面需要后续处理,再进行处理
- if (this.handleSearchData) {
- this.handleSearchData(tableData);
- }
- // 不处理数据 直接把接口返回值 扔到方法中 目前 销售订单的详情在用
- if (this.notProcessedResult) {
- this.notProcessedResult(res);
- }
- }
- });
- },
- /**
- * @desc : 给查询实体赋值
- * @author : 周兴
- * @date : 2024/1/19
- */
- _setSearchParams() {
- let params = {}
- if (this.data.searchForm) {
- params = JSON.parse(this.data.searchForm);
- }
- // 如果需要分页
- if (this.data.pageFlag) {
- params.pageSize = this.data.pageInfo.pageSize;
- params.currentPage = this.data.pageInfo.currentPage;
- }
- if (this.setSearchParams) {
- // 调用参数赋值
- params = this.setSearchParams(params);
- }
- return params;
- },
- /**
- * @desc : 执行查询共通方法
- * @author : 周兴
- * @date : 2024/1/19
- */
- _getData(params) {
- return new Promise(resolve => {
- if (this.getData) {
- let res = this.getData(params);
- resolve(res);
- } else {
- this.setData({
- loading: false
- })
- return (null)
- }
- })
- },
- /**
- * @desc : 跳转明细
- * @author : 周兴
- * @date : 2024/1/22
- */
- toDetail(e) {
- if (e) {
- let item = null;
- if (e.currentTarget.dataset.item) {
- item = e.currentTarget.dataset.item
- }
- if (!e.detail) {
- e.detail = {}
- }
- if (item) {
- e.detail.item = item;
- }
- if (e.detail.item) {
- let button = {
- formMode: Constants.formMode.edit
- }
- e.detail.item.button = button
- }
- // 如果name不传递,默认为edit
- e.detail.name = 'edit'
- }
- this.open(e);
- },
- /**
- * @desc : 点击按钮
- * @author : 周兴
- * @date : 2024/1/22
- */
- open(e) {
- // 如果没有路由就不往下进行
- if (!this.data.routeObjName) return;
- let name;
- let item;
- if (typeof e === 'object') {
- if (e && e.currentTarget) {
- name = e.currentTarget.dataset.name;
- item = e.currentTarget.dataset.item;
- }
- // 那可能是在detail中
- if (!name && e.detail) {
- name = e.detail.name;
- item = e.detail.item;
- }
- if (item && this.data.primaryKey) {
- item.id = item[this.data.primaryKey]
- }
- } else {
- name = e;
- }
- // 默认是新建
- if (!name) {
- name = 'add'
- }
- let routeUrl = this.data.route[name];
- console.log('rreee',routeUrl,name);
- if (!routeUrl) return;
- this._openValidData(item, name, routeUrl.valid).then(res => {
- if (!res) {
- return;
- }
- // 如果有链接,就跳转
- if (routeUrl.url) {
- let url = routeUrl.url
- //保存按钮自定义跳转URL
- if (e.detail && e.detail.customUrl) {
- url = e.detail.customUrl
- }
- //阻止并提示信息
- if (routeUrl.tipMethod) {
- let result = this[routeUrl.tipMethod](item)
- if (result) {
- // 是否弹出询问框
- Dialog.confirm({
- message: result,
- }).then(() => {
- }).catch(() => {
- })
- return
- }
- }
- let _this = this;
- wx.navigateTo({
- url: url,
- events: {
- // 保存成功后刷新页面
- refresh: function (data) {
- if (data.backFlag) {
- // 刷新一览界面
- wx.reLaunch({
- url: '/pages/welcome/welcome?' + name + '=true',
- })
- } else {
- // 刷新一览界面
- _this.searchData();
- }
- }
- },
- success: function (res) {
- let data = {}
- if (item && item.button && item.button.idKey) {
- data['id'] = item[item.button.idKey]
- }
- if (item && item.id) {
- data['id'] = item.id
- }
- if (item && item.button && item.button.formMode) {
- data['formMode'] = item.button.formMode
- }
- //api 上的优先
- if (_this.data.route[name].formMode) {
- data['formMode'] = _this.data.route[name].formMode
- }
- if (_this.data.route[name].idKey) {
- data['id'] = item[_this.data.route[name].idKey]
- }
- if (item && item.button && item.button.formType) {
- data['formType'] = item.button.formType
- }
- if (routeUrl.formType) {
- data['formType'] = routeUrl.formType
- }
- // 新建增加默认的新建formMode
- if (name === 'add') {
- data['formMode'] = Constants.formMode.add;
- }
- data['item'] = item
- console.log('data', data);
- res.eventChannel.emit('params', data);
- }
- })
- } else {
- // 如果是方法就执行方法
- if (routeUrl.method) {
- // 有提示信息,就提出
- if (routeUrl.question) {
- // 是否弹出询问框
- Dialog.confirm({
- message: '是否进行该操作?',
- }).then(() => {
- this[routeUrl.method](item);
- }).catch(() => {
- })
- } else {
- this[routeUrl.method](item);
- }
- }
- }
- })
- },
- /**
- * @desc : 打印票据
- * @author : 周兴
- * @date : 2024/4/22
- */
- printedBill(row) {
- // 查询票据
- let docName = app.globalData['routeUrl'][this.data.routeObjName].docName
- console.log('row',row,docName);
- if (!docName || !row || !row.id) {
- return;
- }
- this.setData({
- loading: true
- })
- let service = app.globalData['printLayoutService']
- // 查询打印票据
- this.excute(service, service.selectByCond, { docName: docName.title, flgValid: true }).then(res => {
- this.setData({
- loading: false
- })
- if (res.data.code == Constants.SUCESS_CODE) {
- let tableList = res.data.data.list;
- if (tableList && tableList.length > 0) {
- // 如果只有一个票据,直接调取打印
- if (tableList.length == 1) {
- this.print(docName.key, tableList[0].layoutId, row.id)
- } else {
- // 多个跳转到票据打印页面
- wx.navigateTo({
- url: '/package-basic-data/pages/print-layout/print-layout',
- success: function (res) {
- res.eventChannel.emit('print', { data: tableList, docName: docName.key, dataId: row.id });
- }
- })
- }
- }
- }
- });
- },
- /**
- * @desc : 调取打印
- * @author : 周兴
- * @date : 2024/4/22
- */
- print(docName, layoutId, dataId) {
- wx.navigateTo({
- url: '/package-base-select/pages/web-view-select/web-view-select',
- success: function (res) {
- // 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);
- 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);
- }
- })
- },
- /**
- * @desc : 执行保存方法
- * @author : 周兴
- * @date : 2024/1/22
- */
- save({
- saveFlag = true,
- url,
- dialogMes
- }) {
- // 解决点击太快,blur没有切换过来的问题
- setTimeout(() => {
- // 校验
- this._validData().then(res => {
- if (!res) {
- return;
- }
- this.setData({
- loading: true
- })
- // 设置参数
- this._setParams();
- // 如果需要有询问
- if (dialogMes) {
- Dialog.confirm({
- message: dialogMes,
- }).then(() => {
- // 执行保存方法
- if (saveFlag) {
- this._handleSaveData();
- } else {
- let that = this
- this.setData({
- loading: false
- })
- wx.navigateTo({
- url: url,
- events: {
- // 回调后
- refresh: function (data) {
- if (that.handleSaveData) {
- that.handleSaveData();
- }
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- params: that.data.params
- })
- }
- })
- }
- })
- } else {
- // 执行保存方法
- if (saveFlag) {
- this._handleSaveData();
- } else {
- let that = this
- this.setData({
- loading: false
- })
- wx.navigateTo({
- url: url,
- events: {
- // 回调后
- refresh: function (data) {
- // 回退
- if (data.backFlag) {
- const eventChannel = that.getOpenerEventChannel();
- eventChannel.emit('refresh', {
- id: 1
- })
- wx.navigateBack({
- delta: 1
- })
- } else {
- // 新建界面清空
- that.setData({
- formData: null
- })
- var pages = getCurrentPages();
- var prevPage = pages[pages.length - 3]; //上上一个页面
- if (prevPage) {
- prevPage.setData({
- refreshByAdd: true
- })
- }
- if (that.handleSaveData) {
- that.handleSaveData();
- }
- }
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- params: that.data.params,
- formType: that.data.params.formType ? that.data.params.formType : ''
- })
- }
- })
- }
- }
- });
- }, 300)
- },
- /**
- * @desc : 保存方法
- * @author : 周兴
- * @date : 2024/1/22
- */
- _handleSaveData() {
- this._saveData(this.data.params).then(result => {
- if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
- wx.showToast({
- title: '保存成功',
- image: '/static/image/success.png',
- duration: 2000
- })
- // 如果页面需要后续处理,再进行处理
- if (this.handleData) {
- this.handleData();
- }
- //是否返回上一页
- if (!this.data.navigateBackFlag) {
- // 非新建页面回到上一个页面
- if (this.data.formMode != Constants.formMode.add || this.data.backFlag) {
- // 给父页面传递数据
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.emit('refresh', {
- id: 1
- })
- setTimeout(() => {
- wx.navigateBack({
- data: 1
- })
- }, 2000)
- } else {
- // 新建界面清空
- this.setData({
- formData: null
- })
- if (this.handleSaveData) {
- this.handleSaveData();
- }
- // 清空页面金额
- if (this.clearAmount) {
- this.clearAmount();
- }
- var pages = getCurrentPages();
- var prevPage = pages[pages.length - 2]; //上一个页面
- prevPage.setData({
- refreshByAdd: true
- })
- }
- } else {
- //不返回上一页 并且执行查询接口
- // 执行查询方法
- this.searchData()
- }
- setTimeout(() => {
- this.setData({
- loading: false
- })
- }, 2000)
- } else {
- setTimeout(() => {
- this.setData({
- loading: false
- })
- }, 2000)
- }
- });
- },
- /**
- * @desc : 给实体赋值
- * @author : 周兴
- * @date : 2024/1/19
- */
- _setParams() {
- let params = {}
- if (this.data.formData && JSON.stringify(this.data.formData) !== '{}') {
- params = JSON.parse(this.data.formData);
- }
- this.setData({
- params: params
- })
- if (this.setParams) {
- // 调用参数赋值
- let parm = this.setParams(params);
- this.setData({
- params: parm
- })
- }
- },
- /**
- * @desc : 打开工具校验,(不给外部调用)
- * @author : 周兴
- * @date : 2024/1/22 14:13
- */
- _openValidData(item, name, valid) {
- return new Promise(resolve => {
- // 页面校验
- if (this.openValidData && valid) {
- let flag = this.openValidData(item, name);
- resolve(flag);
- } else {
- resolve(true);
- }
- })
- },
- /**
- * @desc : 校验,(不给外部调用)
- * @author : 周兴
- * @date : 2024/1/22 14:13
- */
- _validData() {
- return new Promise(resolve => {
- // 不需要校验直接返回
- if (!this.data.validFlag) {
- resolve(true);
- }
- // 非空校验
- if (this.data.formName) {
- const component = this.selectComponent('#' + this.data.formName);
- if (component && component.validData) {
- let valid = component.validData();
- if (!valid) {
- resolve(false);
- }
- }
- }
- // 页面校验
- if (this.validData) {
- let flag = this.validData();
- resolve(flag);
- } else {
- resolve(true);
- }
- })
- },
- /**
- * @desc : 给参数赋值(不给外部调用)
- * @author : 周兴
- * @date : 2024/1/22 14:33
- */
- _saveData(params) {
- return new Promise(resolve => {
- let res = this.saveData(params);
- resolve(res);
- })
- },
- /**
- * @desc : 查询明细的方法(不给外部调用)
- * @author : 周兴
- * @date : 2022/12/8 17:56
- */
- _detail(id) {
- this.loading = true;
- this.detail(id)?.then(res => {
- if (res.data.code === Constants.SUCESS_CODE && res.data.data) {
- // 给变量赋值
- if (this.setValuesByEdit) {
- this.setValuesByEdit(res.data.data)
- }
- }
- setTimeout(() => {
- this.loading = false
- }, 300)
- })
- },
- /**
- * @desc : 根据id查询数据
- * @date : 2024/2/26 15:49
- * @author : 周兴
- */
- detail(id) {
- return this.excute(this.data.service, id, null);
- },
- /**
- * @desc : 查询明细的方法(不给外部调用)
- * @author : 周兴
- * @date : 2022/12/8 17:56
- */
- _other(param) {
- this.loading = true;
- // 给参数赋值
- this._getData(param).then(res => {
- if (res && res.data.code === Constants.SUCESS_CODE) {
- // 给变量赋值
- if (this.setValuesByEdit) {
- this.setValuesByEdit(res.data.data)
- }
- }
- setTimeout(() => {
- this.loading = false
- }, 300)
- });
- },
- /**
- * @desc : 微信支付-随机生成单号
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- generateRandomNo() {
- let timestamp = new Date().getTime().toString() // 当前时间戳
- let randomPart = Math.random().toString(36).substring(2, 10) // 随机字符串
- return timestamp + randomPart
- },
- /**
- * @desc : 微信支付
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- toPay(e, closeFlag = true) {
- let wechatPayService = app.globalData['wechatPayService']
- let params = {
- openId: app.globalData.openid,
- // paymentSn: this.generateOrderNumber(),
- payFee: e.tradeAmount,
- paymentSn: e.tradeNo,
- }
- return this.excute(wechatPayService, wechatPayService.unifiedOrder, params).then(res => {
- if (res.data.code === Constants.SUCESS_CODE) {
- var appid = res.data.data.appId
- var timeStamp = res.data.data.timeStamp
- var nonce_str = res.data.data.nonceStr
- var pk = res.data.data.pack
- var paySign = res.data.data.paySign
- let _this = this
- //调用微信支付
- wx.requestPayment({
- 'appId': appid,
- 'timeStamp': timeStamp,
- 'nonceStr': nonce_str,
- 'package': pk,
- 'signType': 'MD5',
- 'paySign': paySign,
- 'success': function (res) {
- wx.showToast({
- title: '支付成功',
- image: '/static/image/success.png',
- duration: 2000
- })
- _this.setData({
- loading: false
- })
- if (closeFlag) {
- const eventChannel = _this.getOpenerEventChannel();
- eventChannel.emit('refresh', {
- id: 1,
- backFlag: true
- })
- // 调转主页
- wx.reLaunch({
- url: '/pages/welcome/welcome',
- })
- wx.navigateBack({
- delta: 1
- })
- }
- },
- 'fail': function (res) {
- _this.setData({
- loading: false
- })
- },
- 'complete': function (res) {
- }
- });
- }
- });
- },
- /**
- * @desc : 导出excel
- * @author : 周兴
- * @date : 2024/4/23
- */
- export() {
- let exportCols = this.data.exportCols;
- if (!exportCols) {
- return;
- }
- let params = {}
- if (this.data.searchForm) {
- params = JSON.parse(this.data.searchForm);
- }
- let otherSearchParams = this.data.otherSearchParams;
- if (otherSearchParams) {
- // 把其他查询条件拼到查询实体上去
- params = Object.assign(params, otherSearchParams);
- }
- params.name = this.data.objectCode;
- if (params.flgViewItem) {
- params.name = params.name + '-item'
- }
- params.title = this.data.title;
- params.currentPage = 1;
- params.pageSize = Constants.MAX_PAGE_SIZE;
- if (exportCols) {
- // 增加序号
- params.condition = Object.assign({ 'seq': '序号' }, exportCols);
- }
- let service = app.globalData['exportService']
- let url = config.image_url.replace('file', '') + 'api/'
- // let url = 'http://192.168.0.57:7001/'
- url = url + service.prefix + service.export
- if (app.globalData.company && app.globalData.company.svcCode) {
- url = url.replace('mdm-server', 'mdm-server' + '-' + app.globalData.company.svcCode.replace('_', '-'))
- }
- this.setData({
- loading: true
- })
- let _this = this;
- wx.request({
- url: url,
- header: {
- 'content-type': 'application/json',
- 'Authorization': 'Bearer ' + app.globalData.token,
- 'i18n': Constants.lan
- },
- data: params,
- method: 'POST',
- success: function (res) {
- if (res.data.code == Constants.SUCESS_CODE) {
- if (res.data) {
- let url = config.image_url.replace('file', 'excel')
- _this.downloadFile(url + '/' + res.data.data);
- }
- }
- _this.setData({
- loading: false
- })
- },
- fail: function (err) {
- // reject(err);
- _this.setData({
- loading: false
- })
- }
- })
- },
- /**
- * 下载文件资源到本地 打开文档
- * @param {*} url
- */
- downloadFile(url, type = 'xlsx') {
- let that = this
- wx.downloadFile({
- url: url,
- success: function (resd) {
- if (resd.statusCode == Constants.SUCESS_CODE) {
- const filePath = resd.tempFilePath
- // 说明有值
- if (filePath) {
- that.setData({
- filePath: filePath
- })
- // 如果有值就打开文档
- wx.openDocument({
- filePath: filePath,
- showMenu: true,
- fileType: type,
- success: function (reso) {
- }
- })
- }
- }
- }, fail(err) {
- }
- })
- },
- /**
- * @desc : 执行方法
- * @author : 周兴
- * @date : 2024/1/22
- */
- excute(service, method, params, showMessage = false, button = '') {
- if (service && method) {
- let url = service.prefix + method;
- let param = params;
- if (params && typeof params != 'object') {
- url = url + '/' + params;
- param = null;
- }
- let res = api.request(url, 'POST', param);
- if (res) {
- res.then(t => {
- if (showMessage) {
- if (t.data.code === Constants.SUCESS_CODE) {
- if (button == '') {
- button = Constants.Messages.save_sucess;
- }
- wx.showToast({
- title: button,
- image: '/static/image/success.png',
- duration: 2000
- })
- // if (searchFlag) {
- // this.searchData();
- // }
- } else {
- if (t.message) {
- wx.showToast({
- title: t.message,
- image: '/static/image/warning.png',
- duration: 2000
- })
- }
- }
- }
- })
- }
- return res;
- }
- },
- /**
- * @desc : 处理数据的有效标识(启用/停用)
- * @author : 周兴
- * @date : 2024/1/22
- */
- handleDataIsValid(e) {
- let item = e.detail.item;
- let primaryKey = this.data.primaryKey;
- let service = this.data.service;
- if (item && primaryKey && item[primaryKey] && service) {
- let method = item.flgValid ? service.disable : service.enable;
- return this.excute(service, method, item[primaryKey]).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- wx.showToast({
- title: '操作成功',
- image: '/static/image/success.png',
- duration: 2000
- })
- // 重新查询
- this.searchData()
- }
- });
- }
- },
- /**
- * @desc : 处理数据的有效标识(启用/停用)(用于像基础资料和商品属性)
- * @author : 周兴
- * @date : 2024/1/22
- */
- handleMoreDataIsValid(service, item, primaryKey) {
- if (service && item && item[primaryKey]) {
- let method = item.flgValid ? service.disable : service.enable;
- return this.excute(service, method, item[primaryKey]).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- wx.showToast({
- title: '操作成功',
- image: '/static/image/success.png',
- duration: 2000
- })
- this.setData({
- pageInfo: {
- currentPage: 1,
- pageSize: Constants.PAGE_SIZE
- }
- })
- // 重新查询
- this.searchData()
- }
- });
- }
- },
- /**
- * @desc : 生命周期函数(onLoad)
- * @author : 周兴
- * @date : 2024/1/22
- */
- handleLoadData() {
- let formMode = this.data.formMode;
- formMode = formMode ? formMode : Constants.formMode.index
- let noMore = false;
- // 列表
- if (formMode == Constants.formMode.index) {
- if (this.data.initSearchFlag) {
- // 默认查询
- this.searchData();
- }
- // 更新用户功能频率
- this.saveUserMenuFrequency();
- // 编辑
- } else if (formMode == Constants.formMode.edit) {
- let id = this.data.id;
- if (id) {
- // 调用明细
- this._detail(id);
- }
- noMore = true;
- } else if (formMode == Constants.formMode.other) {
- let other = this.data.other ? this.data.other : {};
- other.id = this.data.id
- if (other) {
- // 调用
- this._other(other);
- }
- } else if (formMode == Constants.formMode.add) {
- noMore = true;
- }
- this.setData({
- noMore: noMore
- })
- },
- /**
- * @desc : 加载暂存数据
- * @author : 周兴
- * @date : 2024/1/22
- */
- loadTempData() {
- setTimeout(() => {
- var pages = getCurrentPages();
- var currentPage = pages[pages.length - 1];
- let formData = this.data.formData
- let formValue = app.globalData[currentPage.route];
- if (formValue && formData && formData != formValue) {
- Dialog.confirm({
- message: '是否加载缓存数据',
- }).then(() => {
- // 执行保存方法
- this.setData({
- formData: formValue
- })
- // 删除缓存
- delete app.globalData[currentPage.route]
- }).catch(() => {
- // 删除缓存
- delete app.globalData[currentPage.route]
- })
- }
- }, 1000)
- },
- /**
- * @desc : 保存用户功能频率
- * @author : 周兴
- * @date : 2024/1/22
- */
- saveUserMenuFrequency() {
- let menuUuid = this.data.menuUuid
- if (menuUuid) {
- let params = {
- menuUuid: menuUuid,
- staffId: app.globalData.user.staffId,
- appCode: Constants.APP_CODE,
- }
- let service = app.globalData['userMenuFrequencyService']
- // 保存用户功能频率
- this.excute(service, service.save, params);
- service = app.globalData['menuFrequencyService']
- // 保存功能频率
- params.cpId = app.globalData.company.cpId
- this.excute(service, service.save, params);
- }
- },
- /**
- * 点击返回按钮返回上一层
- * @author 刘尧
- * @date 2024.05.31
- */
- handleNavBack() {
- wx.navigateBack({
- data: 1
- })
- },
- /**
- * @desc : 生命周期函数(onShow)
- * @author : 周兴
- * @date : 2024/1/22
- */
- onShow() {
- // 新建后关闭新建后刷新页面
- if (this.data.refreshByAdd) {
- this.searchData();
- if(this.customQuery){
- //自定义查询
- this.customQuery();
- }
- this.setData({
- refreshByAdd: false
- })
- }
- },
- /**
- * @desc : 生命周期函数(onLoad)
- * @author : 周兴
- * @date : 2024/1/22
- */
- onLoad() {
- let routeObjName = this.data.routeObjName;
- if (routeObjName) {
- // 根据routeObjName获取当前服务
- if (app.globalData[routeObjName + 'Service']) {
- this.setData({
- service: app.globalData[routeObjName + 'Service']
- })
- }
- // 根据routeObjName获取当前路由
- if (app.globalData['routeUrl'][this.data.routeObjName]) {
- this.setData({
- route: app.globalData['routeUrl'][routeObjName]
- })
- }
- }
- let gradeCode = app.globalData.company.gradeCode
- this.setData({
- gradeCode: gradeCode,
- freeVersionFlag: gradeCode === 'STD'
- })
- // 接收父页面传递的参数
- const eventChannel = this.getOpenerEventChannel();
- if (eventChannel && JSON.stringify(eventChannel) !== '{}') {
- let _this = this;
- // 指定类型
- eventChannel.once('params', function (data) {
- if (!_this.data.paramsInitFlag) {
- return;
- }
- _this.setData({
- paramsInitFlag: false
- })
- // 获取参数
- if (data.formMode) {
- _this.setData({
- id: data.id,
- other: data.item ? (data.item.button ? data.item.button.other : null) : "",
- formMode: data.formMode,
- menuUuid: data.menuUuid,
- objectCode: data.objectCode,
- guideUrl: data.guideUrl
- })
- }
- //是否返回原始页面
- if (data.formReturnMode) {
- _this.setData({
- formReturnMode: data.formReturnMode
- })
- }
- if (data.params) {
- _this.setData({
- params: data.params
- })
- }
- //菜单编码
- if (data.functionCode) {
- _this.setData({
- functionCode: data.functionCode
- })
- }
- //选品弹出pop
- if (data.popContent) {
- _this.setData({
- popContent: data.popContent
- })
- }
- //控制标识 的 集合
- if (data.controlFlags) {
- _this.setData({
- controlFlags: data.controlFlags
- })
- }
- // 控制选择商品页面是否显示去入库
- if(data.noWarehouseFlag){
- _this.setData({
- noWarehouseFlag:data.noWarehouseFlag
- })
- }
-
- if (data.item) {
- _this.setData({
- item: data.item
- })
- }
- if (data.formItem) {
- _this.setData({
- formItem: data.formItem
- })
- }
- if (data.formType) { //表单保存修改按钮控制属性(标识)
- _this.setData({
- formType: data.formType
- })
- }
- if (data.backFlag) {
- _this.setData({
- backFlag: data.backFlag
- })
- }
- if (data.chooseType) {
- _this.setData({
- chooseData: data
- })
- }
- if (data.route) {
- _this.setData({
- chooseRoute: data.route
- })
- }
- // 加载后续数据
- _this.handleLoadData();
- // 页面设置初始信息
- if (_this.loadInit) {
- _this.loadInit();
- }
- if (data.formMode == Constants.formMode.add) {
- // // 加载暂存数据
- // _this.loadTempData();
- }
- })
- setTimeout(() => {
- _this.setData({
- paramsInitFlag: true
- })
- }, 2000)
- } else {
- // 加载后续数据
- this.handleLoadData();
- // 页面设置初始信息
- if (this.loadInit) {
- this.loadInit();
- }
- }
- },
- /**
- * @desc : 生命周期函数(onUnload)
- * @author : 周兴
- * @date : 2024/1/22
- */
- onUnload() {
- // 关闭时,如果数据源有值,记录到缓存中
- let formData = this.data.formData
- // 获取当前页面的路由
- var pages = getCurrentPages();
- var currentPage = pages[pages.length - 1];
- if (!currentPage) return;
- let route = currentPage.route;
- if (formData && formData != '{}') {
- // 记录缓存
- app.globalData[route] = formData;
- } else {
- // 删除对应的缓存
- delete app.globalData[route]
- }
- },
- /**
- * @desc : 页面上拉触底事件的处理函数
- * @author : 于继渤
- * @date : 2022/5/24 12:16
- */
- onReachBottom: function () {
- // 不分页也不能进行下翻
- if (!this.data.pageFlag || this.data.loading || this.data.noMore) {
- return;
- }
- this.setData({
- pageInfo: {
- pageSize: this.data.pageInfo.pageSize,
- currentPage: this.data.pageInfo.currentPage + 1
- }
- })
- // 执行查询方法
- this.searchData('more')
- },
- /**
- * @desc : 页面下拉刷新事件的处理函数
- * @author : 于继渤
- * @date : 2024/4/10 12:16
- */
- onPullDownRefresh(e) {
- this.setData({
- noMore: true
- })
- setTimeout(() => {
- // 执行查询方法
- this.searchData()
- //停止刷新
- wx.stopPullDownRefresh()
- }, 300)
- },
- /**
- * 获取自定义导航栏高度
- * @author: 刘尧
- */
- getNavbarHeight(e) {
- const detail = e.detail
- this.setData({
- navBarHeight: detail.height
- })
- },
- /**
- * 获取sticky组件高度
- * @author: 刘尧
- */
- getStickyHeight(e) {
- let that = this
- let query = wx.createSelectorQuery().in(this);
- query.select('#sticky').boundingClientRect(function (rect) {
- that.setData({
- stickyHeight: rect.height
- })
- }).exec()
- }
- };
|