| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475 |
- /*******************************************************************************
- * 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,
- // 组件加载完毕(避免组件晃动,加载完毕后再可见)
- okFlag: false,
- // 下拉刷新控制标识
- pullRefreshFlag: false,
- },
- /**
- * @desc : 获取路由信息,供data中的对象使用
- * @author : 周兴
- * @date : 2024/1/19
- */
- $routeUrl(routeObjName, key) {
- return app.globalData['routeUrl'][routeObjName][key]?.url
- },
- /**
- * @desc : 2024-04-28类型转成时间戳
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- convertDateToMillisecondsTimestamp(dateString) {
- // 创建Date对象
- const date = new Date(`${dateString}T00:00:00Z`); // 假设dateString是YYYY-MM-DD格式,并添加T00:00:00Z使其成为ISO 8601格式
- // 获取毫秒级时间戳
- const timestamp = date.getTime();
- return timestamp;
- },
- /**
- * @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
- */
- clickPreview(e) {
- setTimeout(() => {
- this.setData({
- loading: false,
- })
- }, 500)
- },
- /**
- * @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];
- 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
- 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
- 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) {
- let address = config.image_url.replace('file', '')
- 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', address + 'wx-print?svc_code=' + app.globalData.company.svcCode + '&cp_id=' + app.globalData.company.cpId + '&doc=' + docName + '&layout_id=' + layoutId + '&data_id=' + dataId);
- }
- })
- },
- /**
- * @desc : 格式化日期
- * @date : 2024/7/5 13:22
- * @author : 王英杰
- */
- formatDateOnly(datetime) {
- // 创建Date对象
- var date = new Date(datetime);
- // 提取年、月、日
- var year = date.getFullYear();
- var month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份加1,并使用padStart确保为两位数
- var day = date.getDate().toString().padStart(2, '0'); // 使用padStart确保为两位数
- // 拼接年月日
- return year + '-' + month + '-' + day;
- },
- /**
- * @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 : 关闭所有的tip
- * @date : 2024/5/24 15:49
- * @author : 王英杰
- */
- handleTap() {
- this.selectComponent('#' + this.data.formName).handleTap()
- },
- /**
- * @desc : 关闭所有的tip
- * @date : 2024/5/24 15:49
- * @author : 王英杰
- */
- setShowTipFlag(id) {
- this.selectComponent('#' + id).setShowTipFlag(false)
- },
- /**
- * @desc : 关闭所有的tip
- * @date : 2024/5/24 15:49
- * @author : 王英杰
- */
- closeTips(ids) {
- ids.forEach(item => {
- if (this.selectComponent('#' + item)) {
- this.selectComponent('#' + item).setShowTipFlag(false)
- }
- })
- },
- /**
- * @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]
- })
- }
- }
- if (app.globalData.company) {
- 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
- })
- if (this.data.pullRefreshFlag) {
- return;
- }
- this.setData({
- pullRefreshFlag: true
- })
- setTimeout(() => {
- // 执行查询方法
- this.searchData()
- //停止刷新
- wx.stopPullDownRefresh()
- }, 300)
- setTimeout(() => {
- this.setData({
- pullRefreshFlag: false
- })
- }, 1000)
- },
- /**
- * 获取自定义导航栏高度
- * @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()
- }
- };
|