Browse Source

app 考勤记录使用新版生成代码

大厂分支
zhichao lei 4 years ago
parent
commit
a1f760843a
2 changed files with 482 additions and 585 deletions
  1. +292
    -336
      Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/LogisticsManagement/ADR_Record/list.vue
  2. +190
    -249
      Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/LogisticsManagement/ADR_Record/single.vue

+ 292
- 336
Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/LogisticsManagement/ADR_Record/list.vue View File

@@ -1,344 +1,300 @@
<template>
<view class="page">
<scroll-view @scrolltolower="fetchList" :class="sideOpen ? 'show' : ''" style="padding-top: 100rpx" class="mainpage solid-top" scroll-y>
<view class="custom-list-header">
<view class="custom-list-banner">
{{ pageInfo }}
<view class="custom-list-action">
<l-icon @click="sideOpen = true" class="text-xxl" type="searchlist" color="blue" />
</view>
</view>
</view>

<view class="list">
<view class="custom-item" v-for="(item, index) of list" :key="item.ID">
<view class="custom-item-main">
<text class="custom-item-title">员工名字:</text>
{{ displayListItem(item, 'UserName') }}
</view>
<view class="custom-item-main">
<text class="custom-item-title">部门:</text>
{{ displayListItem(item, 'Department') }}
</view>
<view class="custom-item-main">
<text class="custom-item-title">考勤日期:</text>
{{ displayListItem(item, 'ADDate') }}
</view>
<view class="custom-item-main">
<text class="custom-item-title">考勤时间:</text>
{{ displayListItem(item, 'ADTime') }}
</view>
<view class="custom-item-main">
<text class="custom-item-title">打卡时间:</text>
{{ displayListItem(item, 'ClockTime') }}
</view>
<view class="custom-item-main">
<text class="custom-item-title">打卡状态:</text>
{{ displayListItem(item, 'ClockStatus') }}
</view>
<view class="custom-item-main">
<text class="custom-item-title">打卡地点:</text>
{{ displayListItem(item, 'ClockPlace') }}
</view>

<view class="custom-action">
<view @click="deleteItem(item.ID, index)" class="custom-action-btn line-red text-sm" style="border: currentColor 1px solid">
<l-icon type="delete" />
删除
</view>
<view @click="action('edit', item.ID)" class="custom-action-btn line-blue text-sm" style="border: currentColor 1px solid">
<l-icon type="edit" />
编辑
</view>
<view @click="action('view', item.ID)" class="custom-action-btn line-blue text-sm" style="border: currentColor 1px solid;min-width: 160rpx;">
查看
<l-icon type="right" />
</view>
</view>
</view>
</view>

<view class="custom-item">
{{ page >= total ? `已加载全部条目` : `加载中...` }}
</view>
</scroll-view>

<view class="sideclose" :class="sideOpen ? 'show' : ''" @click="sideOpen = false">
<l-icon type="pullright" color="blue" />
</view>

<scroll-view scroll-y class="sidepage" :class="sideOpen ? 'show' : ''">
<view v-if="ready" class="padding">
<view class="side-title">按时间筛选:</view>
<l-button @click="changeDateRange('all')" :line="dateRange !== 'all' ? 'green' : ''" :color="dateRange === 'all' ? 'green' : ''" class="block margin-top-sm" block>全部</l-button>
<l-button @click="changeDateRange('today')" :line="dateRange !== 'today' ? 'blue' : ''" :color="dateRange === 'today' ? 'blue' : ''" class="block margin-top-sm" block>今天</l-button>
<l-button @click="changeDateRange('7d')" :line="dateRange !== '7d' ? 'blue' : ''" :color="dateRange === '7d' ? 'blue' : ''" class="block margin-top-sm" block>最近7天内</l-button>
<l-button @click="changeDateRange('1m')" :line="dateRange !== '1m' ? 'blue' : ''" :color="dateRange === '1m' ? 'blue' : ''" class="block margin-top-sm" block>最近1个月内</l-button>
<l-button @click="changeDateRange('3m')" :line="dateRange !== '3m' ? 'blue' : ''" :color="dateRange === '3m' ? 'blue' : ''" class="block margin-top-sm" block>最近3个月内</l-button>
<view v-if="dateRange === 'custom'" class="side-title">自定义时间区间:</view>
<l-date-picker v-if="dateRange === 'custom'" v-model="startDate" @change="searchChange" title="起始时间" placeholder="点击来选取" />
<l-date-picker v-if="dateRange === 'custom'" v-model="endDate" @change="searchChange" title="结束时间" placeholder="点击来选取" />

<l-input
v-model="queryData.UserName"
<template>
<view class="page">
<!-- 主列表页 -->
<view :class="sideOpen ? 'show' : ''" class="mainpage" style="padding-top: 80rpx;">
<!-- 顶部条目/分页信息栏 -->
<l-customlist-banner @buttonClick="sideOpen = true">{{ tips }}</l-customlist-banner>
<!-- 滚动列表,跨端支持上拉/下拉 -->
<l-scroll-list v-if="ready" @pullDown="pullDown" @toBottom="fetchList()" ref="list">
<l-customlist :tips="loadState" showTips>
<!-- 单条记录 -->
<view class="customlist-item" v-for="item of list" :key="item.ID">
<view class="customlist-item-field">
<text class="customlist-item-field-title">文本框:</text>
{{ displayListItem(item, 'ADDate') }}
</view>
<view class="customlist-item-field">
<text class="customlist-item-field-title">下拉框:</text>
{{ displayListItem(item, 'ClockStatus') }}
</view>
<view class="customlist-item-field">
<text class="customlist-item-field-title">日期框:</text>
{{ displayListItem(item, 'ADTime') }}
</view>
<l-customlist-action showEdit @edit="action('edit', item.ID)" showDelete @delete="action('delete', item.ID)" @view="action('view', item.ID)" />
</view>
</l-customlist>
</l-scroll-list>
</view>
<!-- 关闭侧边抽屉按钮 -->
<view @click="sideOpen = false" :class="sideOpen ? 'show' : ''" class="sideclose">
<l-icon type="pullright" color="blue" />
</view>
<!-- 侧边栏,用于设置查询条件 -->
<scroll-view :class="sideOpen ? 'show' : ''" class="sidepage" scroll-y>
<view v-if="ready" class="padding">
<l-customlist-sidepage-datefilter
v-model="dateRange"
@change="searchChange"
title ="员工名字"
placeholder="按员工名字筛选"
arrow
/>
<l-organize-picker
v-model="queryData.Department"
title="按时间日期查询: "
ref="datefilter"
class="margin-bottom"
/>
<l-input
v-model="queryData.ADDate"
@change="searchChange"
type="department"
title ="部门"
placeholder="按部门筛选"
arrow
/>
<l-date-picker
v-model="queryData.ADTime"
title ="文本框"
placeholder="按文本框查询"
/>
<l-select
v-model="queryData.ClockStatus"
@change="searchChange"
title ="考勤时间"
placeholder="按考勤时间筛选"
arrow
/>

<view class="padding-tb">
<l-button class="block" block line="orange" @click="reset">重置筛选条件</l-button>
</view>
</view>
</scroll-view>
<l-custom-add @click="action('create')" v-if="!sideOpen" />
</view>
</template>


<script>
/*
* 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
* Copyright (c) 2013-2020 上海力软信息技术有限公司
* 创建人:超级管理员
* 日 期:2020-08-28 18:09
* 描 述:考勤记录
:range="dataSource.ClockStatus"
title ="下拉框"
placeholder="按下拉框查询"
/>
<!-- 重置查询条件按钮 -->
<view class="padding-tb">
<l-button @click="reset" line="orange" class="block" block>重置查询条件</l-button>
</view>
</view>
</scroll-view>
<l-customlist-add v-if="!sideOpen" @click="action('add')" />
</view>
</template>
<script>
/*
* 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
* Copyright (c) 2013-2020 上海力软信息技术有限公司
* 创建人:超级管理员
* 日 期:2020-09-02 09:09
* 描 述:考勤记录
*/
/**
* 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
* 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
* { "path": "pages/LogisticsManagement/ADR_Record/list", "style": { "navigationBarTitleText": "表单列表页" } }
*
* (navigationBarTitleText 字段为本页面的标题文本,可以修改)
* (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
*/

import moment from 'moment'
import _ from 'lodash'

export default {
name: 'l-LogisticsManagementADR_Record',

data() {
return {
// 数据项的数据类型、结构
scheme: {
UserName: { type: 'text' },
Department: { type: 'organize', dataType: 'department' },
ADDate: { type: 'datetime', dateformat: '0' },
ADTime: { type: 'datetime', dateformat: '0' },
ClockTime: { type: 'datetime', dateformat: '0' },
ClockStatus: { type: 'text' },
ClockPlace: { type: 'text' },
},

// 筛选菜单值
defaultQueryData: {},
queryData: {
UserName: '',
Department: '',
ADTime: '',
},

// 数据源
dataSource: {
},

dateRange: 'all',
startDate: null,
endDate: null,

page: 1,
total: 2,
list: [],
searchData: {},
pageInfo: '(请等待页面加载完成...)',
sideOpen: false,
ready: false
}
},

async onLoad() {
await this.init()
},
onUnload() {
uni.$off('LogisticsManagementADR_Record-list-change')
},

methods: {
// 初始化
async init() {
uni.$on('LogisticsManagementADR_Record-list-change', this.refresh)
// 加载列表和数据源



await Promise.all([

this.fetchList()
])
this.defaultQueryData = JSON.parse(JSON.stringify(this.queryData))
import get from 'lodash/get'
import set from 'lodash/set'
import pickBy from 'lodash/pickBy'
import mapValues from 'lodash/mapValues'
export default {
data() {
return {
// 数据项的数据类型、结构
scheme: {
ADDate: { type: 'text' },
ClockStatus: { type: 'select', itemCode: 'DbFieldType', dataSource: '0' },
ADTime: { type: 'datetime', dateformat: '0' },
},
// 查询条件
searchData: {},
defaultQueryData: {},
queryData: {
ADDate: '',
ClockStatus: '',
},
// 数据源
dataSource: {
ClockStatus: Object.values(this.GET_GLOBAL('dataDictionary').DbFieldType).map(t => ({ value: t.value, text: t.text })),
},
// 时间查询参数
dateRange: null,
// 页面相关参数
ready: false,
tips: '加载中...',
loadState: '向下翻以加载更多',
sideOpen: false,
// 列表与分页信息
page: 1,
total: 2,
list: []
}
},
async onLoad() {
await this.init()
},
onUnload() {
this.OFF('LogisticsManagementADR_Record-list-change')
},
methods: {
// 页面初始化
async init() {
this.ON('LogisticsManagementADR_Record-list-change', this.refreshList)
// 拉取加载列表和数据源
await Promise.all([
() => {}
])
await this.fetchList()
// 初始化查询条件
this.defaultQueryData = this.COPY(this.queryData)
this.ready = true
},

// 请求api,以获取列表数据
async fetchList(e) {
if (e && e.preventDefault) { e.preventDefault() }
if (this.page > this.total) { return }

uni.showLoading({ title: '加载订单信息...', mask: true })
const [err, { data: { data: result } } = {}] = await uni.request({
url: this.apiRoot + '/LogisticsManagement/ADR_Record/pagelist',
data: {
...this.auth,
data: JSON.stringify({
pagination: { rows: 10, page: this.page, sidx: 'ID', sord: 'DESC' },
queryJson: JSON.stringify(this.searchData)
})
}
})

if (err || !result) {
uni.hideLoading()
uni.showToast({ title: '加载数据时出错', icon: 'none' })
}
this.total = result.total
this.page = this.page + 1
this.list = this.list.concat(result.rows)
const currentPageNum = Math.min(result.page, result.total)
this.pageInfo = `已加载 ${currentPageNum} / ${result.total} 页,合计共 ${result.records} 条记录`
uni.hideLoading()
},

// 显示列表中的标题项
displayListItem(item, field) {
const fieldItem = this.scheme[field]
const value = item[field]

switch (fieldItem.type) {
case 'currentInfo':
case 'organize':
switch (fieldItem.dataType) {
case 'user': return _.get(this.$store.state.staff, `${value}.name`, '')
case 'department': return _.get(this.$store.state.dep, `${value}.name`, '')
case 'company': return _.get(this.$store.state.company, `${value}.name`, '')
default: return value || ''
}

case 'radio':
case 'select':
const selectItem = this.sourceData[field].find(t => t.value === value)
return _.get(selectItem, 'text', '')

case 'checkbox':
if (!value || value.split(',').length <= 0) { return '' }
const checkboxItems = value.split(',')
return this.sourceData[field].filter(t => checkboxItems.includes(t.value)).map(t => t.text).join(',')

case 'datetime':
if (!value) { return '' }
return moment(value).format(Number(fieldItem.dateformat) === 0 ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss')

default: return value || ''
}
},

// 列表内容发生变化,刷新列表
async refresh(e) {
this.page = 1
this.total = 2
this.list = []
await this.fetchList()
},

// 设置搜索条件
async searchChange() {
const result = {}

const todayEnd = moment().format('YYYY-MM-DD 23:59:59')
if (dateRange === 'today') {
result.StartTime = moment().subtract(1, 'day').format('YYYY-MM-DD 00:00:00')
result.EndTime = todayEnd
} else if (dateRange === '7d') {
result.StartTime = moment().subtract(7, 'days').format('YYYY-MM-DD 00:00:00')
result.EndTime = todayEnd
} else if (dateRange === '1m') {
result.StartTime = moment().subtract(1, 'month').format('YYYY-MM-DD 00:00:00')
result.EndTime = todayEnd
} else if (dateRange === '3m') {
result.StartTime = moment().subtract(3, 'months').format('YYYY-MM-DD 00:00:00')
result.EndTime = todayEnd
} else if (dateRange === 'custom' && (startDate || startDate)) {
if (!(startDate && startDate && moment(startDate).isAfter(endDate))) {
result.StartTime = startDate ? moment(startDate).format('YYYY-MM-DD 00:00:00') : '1900-01-01 00:00:00'
result.EndTime = endDate ? moment(endDate).format('YYYY-MM-DD 23:59:59') : todayEnd
}
}

const queryObj = _.pickBy(this.queryData, t => (Array.isArray(t) ? t.length > 0 : t))
Object.assign(result, _.mapValues(queryObj, t => (Array.isArray(t) ? t.join(',') : t)))

this.searchData = result
await this.refresh()
},

// 点击「清空搜索条件」按钮
reset() {
this.dateRange = 'all'
this.startDate = null
this.endDate = null

this.queryData = JSON.parse(JSON.stringify(this.defaultQueryData))

this.searchChange()
},

// 点击「编辑」、「查看」、「添加」按钮
action(type, id = 'no') {
uni.navigateTo({ url: `./single?type=${type}&id=${id}` })
},

// 点击「删除」按钮
async deleteItem(id, index) {
uni.showModal({
title: '删除项目',
content: '确定要删除该项吗?',
success: ({ confirm }) => {
if (!confirm) { return }
uni
.request({
url: this.apiRoot + '/LogisticsManagement/ADR_Record/delete',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: { ...this.auth, data: id }
})
.then(([err, { data }]) => {
if (err || !data || data.code !== 200) {
uni.showToast({ title: '删除失败', icon: 'none' })
return
}
uni.showToast({ title: '删除成功', icon: 'success' })
this.refresh()
})
}
})
},

}

}
</script>


},
// 拉取列表
async fetchList() {
if (this.page > this.total) { return }
const result = await this.HTTP_GET(
'/LogisticsManagement/ADR_Record/pagelist',
{
// 这里 sidx 表示排序字段,sord 表示排序方式(DESC=降序,ASC=升序)
// 代码生成器生成时默认按照主键排序,您可以修改成按创建时间的字段降序
pagination: { rows: 10, page: this.page, sidx: 'ID', sord: 'DESC' },
queryJson: JSON.stringify(this.searchData)
},
'加载数据时出错'
)
if (!result) { return }
this.total = result.total
this.page = result.page + 1
this.list = this.list.concat(result.rows)
this.tips = `已加载 ${Math.min(result.page, result.total)} / ${result.total} 页,共 ${result.records} 项`
this.loadState = result.page >= result.total ? '已加载所有项目' : '向下翻以加载更多'
},
// 刷新清空列表
async refreshList() {
this.page = 1
this.total = 2
this.list = []
await this.fetchList()
},
// 列表下拉
pullDown() {
this.refreshList().then(() => {
this.$refs.list.stopPullDown()
})
},
// 设置搜索条件
async searchChange() {
const result = {}
// 时间查询相关参数
if (this.dateRange) {
result.StartTime = this.dateRange.start
result.EndTime = this.dateRange.end
}
// 将其他查询项添加到查询 JSON 中
const queryObj = pickBy(this.queryData, t => (Array.isArray(t) ? t.length > 0 : t))
Object.assign(result, mapValues(queryObj, t => (Array.isArray(t) ? t.join(',') : t)))
this.searchData = result
await this.refreshList()
},
// 点击「清空查询条件」按钮
reset() {
this.$refs.datefilter.changeDateRange('all')
this.queryData = this.COPY(this.defaultQueryData)
this.searchChange()
},
// 点击「编辑」、「查看」、「添加」、「删除」按钮
async action(type, id = '') {
switch (type) {
case 'view':
this.NAV_TO(`./single?type=view&id=${id}`)
return
case 'add':
this.NAV_TO('./single?type=create')
return
case 'edit':
this.NAV_TO(`./single?type=edit&id=${id}`)
return
case 'delete':
if (!(await this.CONFIRM('删除项目', '确定要删除该项吗?', true))) {
return
}
this.HTTP_POST('/LogisticsManagement/ADR_Record/delete', id, '删除失败').then(success => {
if(!success) { return }
this.TOAST('删除成功', 'success')
this.refreshList()
})
return
default:
return
}
},
// 显示列表中的标题项
displayListItem(item, field) {
const fieldItem = this.scheme[field]
const value = item[field]
switch (fieldItem.type) {
case 'currentInfo':
case 'organize':
return fieldItem.dataType === 'time' ? value : get(this.GET_GLOBAL(fieldItem.dataType), `${value}.name`, '')
case 'radio':
case 'select':
const selectItem = this.dataSource[field].find(t => t.value === String(value))
return get(selectItem, 'text', '')
case 'checkbox':
if (!value || value.split(',').length <= 0) { return '' }
const checkboxItems = value.split(',')
return this.dataSource[field].filter(t => checkboxItems.includes(t.value)).map(t => t.text).join(',')
case 'datetime':
if (!value) { return '' }
return moment(value).format(Number(fieldItem.dateformat) === 0 ? 'YYYY年 M月 D日' : 'YYYY-MM-DD HH:mm')
default: return value === null || value === undefined ? '' : value
}
}
}
}
</script>
<style lang="less" scoped>
@import '~@/common/css/sidepage.less';
@import '~@/common/css/custom-item.less';
</style>
@import '~@/common/css/customlist.less';
</style>

+ 190
- 249
Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/LogisticsManagement/ADR_Record/single.vue View File

@@ -1,267 +1,208 @@
<template>
<view class="page">
<view v-if="ready">
<l-input
@input="setValue('ADR_Record.UserName', $event)"
:value="getValue('ADR_Record.UserName')"
:disabled="!edit"
title="员工名字"
placeholder="请输入员工名字"
right
/>
<l-organize-picker
@input="setValue('ADR_Record.Department', $event)"
:value="getValue('ADR_Record.Department')"
:readonly="!edit"
:arrow="edit"
type="department"
title="部门"
placeholder="请选择部门"
/>
<l-date-picker
<template>
<view class="page">
<view v-if="ready">
<l-input
@input="setValue('ADR_Record.ADDate', $event)"
:value="getValue('ADR_Record.ADDate')"
:disabled="!edit"
:arrow="edit"
title="考勤日期"
placeholder="请选择考勤日期"
/>
<l-date-picker
@input="setValue('ADR_Record.ADTime', $event)"
:value="getValue('ADR_Record.ADTime')"
:disabled="!edit"
:arrow="edit"
title="考勤时间"
placeholder="请选择考勤时间"
/>
<l-date-picker
@input="setValue('ADR_Record.ClockTime', $event)"
:value="getValue('ADR_Record.ClockTime')"
:disabled="!edit"
:arrow="edit"
title="打卡时间"
placeholder="请选择打卡时间"
/>
<l-input
title="文本框"
/>
<l-select
@input="setValue('ADR_Record.ClockStatus', $event)"
:value="getValue('ADR_Record.ClockStatus')"
:disabled="!edit"
title="打卡状态"
placeholder="请输入打卡状态"
right
/>
<l-input
@input="setValue('ADR_Record.ClockPlace', $event)"
:value="getValue('ADR_Record.ClockPlace')"
:range="dataSource.ADR_Record.ClockStatus"
title="下拉框"
/>
<l-date-picker
@input="setValue('ADR_Record.ADTime', $event)"
:value="getValue('ADR_Record.ADTime')"
:disabled="!edit"
title="打卡地点"
placeholder="请输入打卡地点"
right
/>
</view>

<view v-if="ready" class="padding-lr bg-white margin-tb padding-tb">
<l-button v-if="edit" @click="action('save')" class="block" size="lg" color="green" block>
提交保存
</l-button>
<l-button v-if="!edit && mode !== 'create'" @click="action('edit')" class="block" size="lg" line="orange" block>
编辑本页
</l-button>
<l-button v-if="edit && mode !== 'create'" @click="action('reset')" class="block margin-top" size="lg" line="red" block>
取消编辑
</l-button>
<l-button v-if="!edit && mode !== 'create'" @click="action('delete')" class="block margin-top" size="lg" line="red" block>
删除
</l-button>
</view>
</view>
</template>


<script>
/*
* 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
* Copyright (c) 2013-2020 上海力软信息技术有限公司
* 创建人:超级管理员
* 日 期:2020-08-28 18:09
* 描 述:考勤记录
title="日期框"
/>
</view>
<view v-if="ready" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;">
<l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block>
提交保存
</l-button>
<l-button v-if="!edit && mode !== 'create'" @click="action('edit')" size="lg" line="orange" class="block margin-top" block>
编辑本页
</l-button>
<l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block>
取消编辑
</l-button>
<l-button v-if="!edit && mode !== 'create'" @click="action('delete')" size="lg" line="red" class="block margin-top" block>
删除
</l-button>
</view>
</view>
</template>
<script>
/*
* 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
* Copyright (c) 2013-2020 上海力软信息技术有限公司
* 创建人:超级管理员
* 日 期:2020-09-02 09:09
* 描 述:考勤记录
*/
/**
* 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
* 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
* { "path": "pages/LogisticsManagement/ADR_Record/single", "style": { "navigationBarTitleText": "表单详情页" } }
*
* (navigationBarTitleText 字段为本页面的标题文本,可以修改)
* (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
*/

import _ from 'lodash'
import get from 'lodash/get'
import set from 'lodash/set'
import moment from 'moment'
import { guid, copy } from '@/common/utils.js'
import customPageMixins from '@/common/custom-page.js'

export default {
mixins: [customPageMixins],

data() {
return {
id: null,
mode: null,
edit: null,
modal: null,
ready: false,

current: null,
origin: null,

// 表单项数据结构
scheme: {
ADR_Record: {
UserName: { type: 'text', title: '员工名字' },
Department: { type: 'organize', title: '部门', dataType: 'department' },
ADDate: { type: 'datetime', title: '考勤日期', dateformat: '0' },
ADTime: { type: 'datetime', title: '考勤时间', dateformat: '0' },
ClockTime: { type: 'datetime', title: '打卡时间', dateformat: '0' },
ClockStatus: { type: 'text', title: '打卡状态' },
ClockPlace: { type: 'text', title: '打卡地点' },
},

},

// 数据源
dataSource: {
ADR_Record: {
},

}
}
},

async onLoad({ type, id }) {
await this.init(type, id)
},

methods: {
async init(type, id) {
uni.showLoading({ title: `加载数据中...`, mask: true })

this.id = id
this.mode = type
this.edit = ['create', 'edit'].includes(this.mode)



// 加载所有数据源
await Promise.all([

this.fetchForm()
])

import customPageMixins from '@/common/custompage.js'
export default {
mixins: [customPageMixins],
data() {
return {
// 页面相关参数
id: null,
mode: null,
edit: null,
ready: false,
// 表单数据
current: {},
origin: {},
// 表单项数据结构
scheme: {
ADR_Record: {
ADDate: { type: 'text', title: '文本框' },
ClockStatus: { type: 'select', title: '下拉框', itemCode: 'DbFieldType', dataSource: '0' },
ADTime: { type: 'datetime', title: '日期框', dateformat: '0' },
},
},
// 数据源
dataSource: {
ADR_Record: {
ClockStatus: Object.values(this.GET_GLOBAL('dataDictionary').DbFieldType).map(t => ({ value: t.value, text: t.text })),
},
}
}
},
async onLoad({ type, id }) {
await this.init(type, id)
},
methods: {
// 页面初始化
async init(type, id) {
this.LOADING('加载数据中...')
this.id = id
this.mode = type
this.edit = ['create', 'edit'].includes(this.mode)
// 拉取表单数据,同时拉取所有来自数据源的选单数据
await Promise.all([
() => {}
])
await this.fetchForm()
this.ready = true
uni.hideLoading()
},

// 获取表单值
getValue(path) {
return _.get(this.current, path)
},

// 设置表单值
setValue(path, val) {
_.set(this.current, path, val)
},

// 加载表单数据
async fetchForm() {
if (this.mode === 'create') {
this.origin = await this.getDefaultForm()
} else {
const [err, { data: { data: result } } = {}] = await uni.request({
url: this.apiRoot + '/LogisticsManagement/ADR_Record/form',
data: { ...this.auth, data: this.id }
})
this.origin = await this.formatFormData(result)
}
this.current = copy(this.origin)
},

// 点击「编辑、重置、保存、删除」按钮
async action(type) {
switch (type) {
case 'edit':
this.HIDE_LOADING()
},
// 加载表单数据
async fetchForm() {
if (this.mode === 'create') {
this.origin = await this.getDefaultForm()
} else {
const result = await this.HTTP_GET('/LogisticsManagement/ADR_Record/form', this.id)
this.origin = await this.formatFormData(result)
}
this.current = this.COPY(this.origin)
},
// 点击 「编辑」、「重置」、「保存」、「删除」 按钮
async action(type) {
switch (type) {
case 'edit':
this.edit = true
break
case 'reset':
this.current = copy(this.origin)
case 'reset':
this.current = this.COPY(this.origin)
this.edit = false
break
case 'save':
const verifyResult = this.verifyForm()
if (verifyResult.length > 0) {
uni.showModal({ title: '表单验证失败', content: verifyResult.join('\n'), showCancel: false })
case 'save':
const verifyResult = this.verifyForm()
if (verifyResult.length > 0) {
this.CONFIRM('表单验证失败', verifyResult.join('\n'))
return
}

uni.showModal({
title: '提交确认',
content: `确定要提交本页表单内容吗?`,
success: async ({ confirm }) => {
if (!confirm) { return }
uni.showLoading({ title: '正在提交...', mask: true })
const postData = await this.getPostData()

uni
.request({
url: this.apiRoot + `/LogisticsManagement/ADR_Record/save`,
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: { ...this.auth, data: postData }
})
.then(([err, result]) => {
uni.hideLoading()
if (err || result.data.code !== 200) {
uni.showToast({ title: `表单提交保存失败`, icon: 'none' })
return
}

uni.$emit('LogisticsManagementADR_Record-list-change')
uni.navigateBack()
uni.showToast({ title: `提交保存成功`, icon: 'success' })
})
}
})
}
if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
return
}
this.LOADING('正在提交...')
const postData = await this.getPostData()
this.HTTP_POST('/LogisticsManagement/ADR_Record/save', postData, '表单提交保存失败').then(success => {
this.HIDE_LOADING()
if (!success) {
return
}
this.EMIT('LogisticsManagementADR_Record-list-change')
this.NAV_BACK()
this.TOAST('提交保存成功')
})
break

case 'delete':
uni.showModal({
title: '删除项目',
content: `确定要删除本项吗?`,
success: ({ confirm }) => {
if (!confirm) { return }

uni
.request({
url: this.apiRoot + `/LogisticsManagement/ADR_Record/delete`,
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: { ...this.auth, data: this.id }
})
.then(([err, { data }]) => {
if (err || !data || data.code !== 200) {
uni.showToast({ title: '删除失败', icon: 'none' })
return
}

uni.$emit('LogisticsManagementADR_Record-list-change')
uni.navigateBack()
uni.showToast({ title: '删除成功', icon: 'success' })
})
}
})
case 'delete':
if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?', true))) {
return
}
this.LOADING('提交删除中...')
this.HTTP_POST('/LogisticsManagement/ADR_Record/delete', this.id, '删除失败').then(success => {
this.HIDE_LOADING()
if (!success) {
return
}
this.EMIT('LogisticsManagementADR_Record-list-change')
this.NAV_BACK()
this.this.TOAST('删除成功', 'success')
})
break
default: break
}
}
}
}
</script>


<style lang="less" scoped>
@import '~@/common/css/custom-form.less';
</style>
}
},
// 获取表单值
getValue(path) {
return get(this.current, path)
},
// 设置表单值
setValue(path, val) {
set(this.current, path, val)
}
}
}
</script>

Loading…
Cancel
Save