Commit 4ed7bf53 by 李伟康

feat(dailyNewspaper): 添加单位显示功能并优化表格组件

- 在 NegotiationDetail 和 StaffDailyReport 中添加单位显示
- 优化 StoreDailyReport 的布局和单位显示
- 在 Table 组件中添加自定义单元格插槽支持单位显示
- 更新数据结构以包含单位信息
- 移除调试日志并优化代码格式
1 parent 3d802c98
......@@ -90,7 +90,8 @@ export default {
rowData.map(row => {
dataList.push({
rowHeader: row.label,
data: values[row.key]
data: values[row.key],
unit: row.unit
})
})
}
......
......@@ -39,6 +39,9 @@
>
<template v-slot:customCell="{row, colIndex}">
<text>{{ formatValue(row[colIndex].value) }}</text>
<template v-if="row[colIndex].unit && formatValue(row[colIndex].value) != '-'">
<text class="unit">{{ row[colIndex].unit }}</text>
</template>
</template>
</Table>
</template>
......
......@@ -37,6 +37,9 @@
<view class="label">{{ item.label }}</view>
<view class="value">
<text>{{ formatValue(item.value) }}</text>
<template v-if="item.unit">
<text class="unit">{{ item.unit }}</text>
</template>
</view>
</view>
</template>
......
......@@ -8,35 +8,27 @@
<template v-if="list.length">
<template v-for="(item, index) in list">
<template v-if="item.type == 'subform'">
<view
class="list-box"
:key="`subform-${index}`"
v-if="item.children && item.children.length"
>
<view class="list-box" :key="`subform-${index}`" v-if="item.children && item.children.length">
<view class="list-title">{{ item.label }}</view>
<Table
:columns="item.columns"
:data="item.dataList"
tableStyle="padding-right:32rpx"
cornerText="门店日报内容项"
isDetail
/>
<Table :columns="item.columns" :data="item.dataList" tableStyle="padding-right:32rpx"
cornerText="门店日报内容项" isDetail />
</view>
</template>
<template v-else-if="item.type == 'divider'">
<view
class="divider"
:key="`divider-${index}`"
>{{ item.label }}</view>
<view class="divider" :key="`divider-${index}`">{{ item.label }}</view>
</template>
<template v-else>
<view
:class="['item',{ 'before-divider': isFollowedByDivider(index) || isFollowedBySubform(index)},{'frist': index === 0}]"
:key="`item-${index}`"
>
:class="['item', { 'before-divider': isFollowedByDivider(index) || isFollowedBySubform(index) }, { 'frist': index === 0 }]"
:key="`item-${index}`">
<view class="label">{{ item.label }}</view>
<view class="value">{{ formatValue(item.value) }}</view>
<view class="value flex">
<text class="value-text">{{ formatValue(item.value) }}</text>
<template v-if="item.unit">
<text class="unit">{{ item.unit }}</text>
</template>
</view>
</view>
</template>
</template>
......@@ -61,7 +53,7 @@ export default {
default: () => []
}
},
data () {
data() {
return {
loadComplete: false,
list: []
......@@ -69,9 +61,9 @@ export default {
},
watch: {
templateData: {
handler (newVal) {
handler(newVal) {
console.log(newVal)
if (newVal.length ) this.formatData(newVal)
if (newVal.length) this.formatData(newVal)
else {
this.list = []
this.loadComplete = true
......@@ -83,7 +75,7 @@ export default {
},
computed: {
},
mounted () {
mounted() {
},
methods: {
......@@ -95,10 +87,10 @@ export default {
const prevItem = this.list[index + 1];
return prevItem && prevItem.type === 'subform';
},
formatValue (value) {
formatValue(value) {
return value != null && value !== undefined && value !== '' ? value : '-'
},
formatData (data) {
formatData(data) {
let list = utils.deepClone(data)
list.map(item => {
let columns = [],
......@@ -117,7 +109,8 @@ export default {
rowData.map(row => {
dataList.push({
rowHeader: row.label,
data: values[row.key]
data: values[row.key],
unit: row.unit
})
})
}
......@@ -135,12 +128,14 @@ export default {
.daily-report {
height: 100%;
position: relative;
.content {
height: calc(100% - #{toRpx(120)});
overflow-y: auto;
padding: 0 48rpx 32rpx;
box-sizing: border-box;
}
.divider {
color: #333333;
font-size: 32rpx;
......@@ -149,6 +144,7 @@ export default {
margin-bottom: 24rpx;
padding-top: 16rpx;
}
.item {
display: flex;
align-items: flex-start;
......@@ -159,22 +155,28 @@ export default {
font-size: 28rpx;
font-weight: 400;
color: #333333;
.label,
.value {
width: calc(50% - #{toRpx(16)});
}
.label {
color: #999999;
}
}
.item.before-divider {
padding-bottom: 28rpx;
border-radius: 0 0 16rpx 16rpx;
}
.divider + .item ,.frist{
.divider+.item,
.frist {
padding-top: 28rpx;
border-radius: 16rpx 16rpx 0 0;
}
.list-box {
// position: absolute;
width: 100%;
......@@ -183,6 +185,7 @@ export default {
padding: 0 0 32rpx 32rpx;
overflow-x: auto;
margin-top: 16rpx;
.list-title {
font-size: 32rpx;
font-weight: 600;
......
......@@ -7,28 +7,16 @@
<template v-if="staffList.length">
<scroll-view scroll-x>
<view class="name-list">
<view
:class="['name-item', currentIndex === index ? 'active' : '', 'flex']"
v-for="(item, index) in staffList"
:key="index"
@click="changeSatffView(index)"
>{{ item.staffName }}</view>
<view :class="['name-item', currentIndex === index ? 'active' : '', 'flex']"
v-for="(item, index) in staffList" :key="index" @click="changeSatffView(index)">{{ item.staffName }}
</view>
</view>
</scroll-view>
<view class="content">
<template v-for="(i,index) in list">
<view
class="table-box"
:key="`t-${index}`"
v-if="i.children && i.children.length"
>
<template v-for="(i, index) in list">
<view class="table-box" :key="`t-${index}`" v-if="i.children && i.children.length">
<view class="table-title">{{ i.label }}</view>
<Table
:columns="i.columns"
:data="i.dataList"
tableStyle="padding-right:32rpx"
isDetail
/>
<Table :columns="i.columns" :data="i.dataList" tableStyle="padding-right:32rpx" isDetail />
</view>
</template>
</view>
......@@ -38,10 +26,7 @@
</view>
<view class="footer">
<Footer>
<view
class="btn"
@click="$emit('back')"
>返回</view>
<view class="btn" @click="$emit('back')">返回</view>
</Footer>
</view>
</view>
......@@ -66,7 +51,7 @@ export default {
},
watch: {
currentDate: {
handler (val) {
handler(val) {
if (val) {
this.getDiscussionStaffList(val)
this.currentIndex = 0
......@@ -77,7 +62,7 @@ export default {
},
},
data () {
data() {
return {
staffList: [],
loadComplete: false,
......@@ -85,15 +70,15 @@ export default {
list: []
}
},
mounted () {
mounted() {
},
methods: {
changeSatffView (index) {
changeSatffView(index) {
if (this.currentIndex === index) return
this.currentIndex = index
this.getReportDetail(this.staffList[index])
},
async getDiscussionStaffList (reportDate) {
async getDiscussionStaffList(reportDate) {
this.loadComplete = false
const { shopMerchantId } = this.userInfo,
data = await uni.$api.dailyTemplateApi.getDiscussionStaffList({
......@@ -105,7 +90,7 @@ export default {
if (data && data.length) this.getReportDetail(data[0])
},
async getReportDetail (item) {
async getReportDetail(item) {
const { shopMerchantId } = this.userInfo,
{ currentDate } = this,
data = await uni.$api.dailyTemplateApi.getReportDetail({
......@@ -116,6 +101,7 @@ export default {
})
if (data) {
let list = JSON.parse(data.jsonContent || '[]')
console.log(list)
list.forEach(e => {
if (e.childrenValue && e.childrenValue.length > 0) {
const children = e.childrenValue.map(c => {
......@@ -124,8 +110,8 @@ export default {
originChildren.forEach(item => {
const key = item.key
const val = c[e.key]?.[key]
if (typeof val === 'string') {
if (typeof val == 'string' || typeof val == 'number') {
item.value = val
} else if (val) {
item.value = val.text
......@@ -154,7 +140,8 @@ export default {
rowData.map(row => {
dataList.push({
rowHeader: row.label,
data: values[row.key]
data: values[row.key],
unit: row.unit
})
})
}
......@@ -177,14 +164,17 @@ export default {
left: 0;
z-index: 2;
animation: list-left-in 0.5s ease-in-out;
.common-title {
position: absolute;
top: 0;
left: 0;
}
&-box {
height: calc(100% - #{toRpx(136)});
box-sizing: border-box;
.name-list {
display: flex;
flex-direction: row;
......@@ -192,6 +182,7 @@ export default {
overflow-x: auto;
gap: 16rpx;
padding: 48rpx 48rpx 32rpx;
.name-item {
padding: 0 48rpx;
height: 72rpx;
......@@ -203,6 +194,7 @@ export default {
box-sizing: border-box;
border: 2rpx solid #f5f7fa;
}
.active {
border-color: #fff;
font-weight: 500;
......@@ -210,6 +202,7 @@ export default {
background: linear-gradient(180deg, #6795ff 0%, #4a84f9 100%);
}
}
.content {
height: calc(100% - #{toRpx(152)});
box-sizing: border-box;
......@@ -218,6 +211,7 @@ export default {
border-radius: 32rpx;
background: #fff;
overflow-y: auto;
.table-title {
font-size: 32rpx;
font-weight: 600;
......@@ -230,6 +224,7 @@ export default {
}
}
}
.footer {
height: 136rpx;
......@@ -248,10 +243,12 @@ export default {
}
}
}
@keyframes list-left-in {
0% {
left: 100%;
}
100% {
left: 0;
}
......
......@@ -185,7 +185,6 @@ export default {
keys.map((key, index) => {
let ind = this.data.findIndex(i => i.key == key),
val = chooseContent[resultKeys[index]]
console.log(chooseContent[resultKeys[index]])
this.$set(this.data[ind], 'value', val != null ? val : '-')
})
}
......
<template>
<view class="table-container">
<view class="table-scroll">
<view
class="table-wrapper"
:style="tableStyle"
>
<view class="table-wrapper" :style="tableStyle">
<!-- 表格 -->
<view
class="table"
:id="id"
>
<view class="table" :id="id">
<!-- 第一行:表头 -->
<view class="table-row header-row">
<!-- 左上角固定单元格 -->
<view
:class="['table-cell corner-cell fixed-corner',{'is-detail': isDetail}]"
:style="{width:LeftWidth, minWidth:LeftWidth}"
>
<view :class="['table-cell corner-cell fixed-corner', { 'is-detail': isDetail }]"
:style="{ width: LeftWidth, minWidth: LeftWidth }">
<text class="cell-text">{{ cornerText }}</text>
</view>
<!-- 顶部表头 -->
<view
v-for="(col, colIndex) in columns"
:key="'header-' + colIndex"
:class="['table-cell header-cell fixed-header',{'is-detail': isDetail}]"
:style="{ width: col.width + 'rpx', minWidth: col.width + 'rpx' }"
>
<view v-for="(col, colIndex) in columns" :key="'header-' + colIndex"
:class="['table-cell header-cell fixed-header', { 'is-detail': isDetail }]"
:style="{ width: col.width + 'rpx', minWidth: col.width + 'rpx' }">
<text class="cell-text">
{{ col[titleKey] }}
<template v-if="col.required">
......@@ -36,49 +25,31 @@
</view>
<!-- 数据行 -->
<view
v-for="(row, rowIndex) in tableData"
:key="'row-' + rowIndex"
<view v-for="(row, rowIndex) in tableData" :key="'row-' + rowIndex"
:class="['table-row', { 'row-clicked': clickedRowIndex === rowIndex }]"
@click="handleRowClick(row, rowIndex)"
>
@click="handleRowClick(row, rowIndex)">
<!-- 左侧行表头 -->
<view
class="table-cell row-header-cell fixed-left"
:style="{width:LeftWidth, minWidth:LeftWidth}"
>
<view class="table-cell row-header-cell fixed-left" :style="{ width: LeftWidth, minWidth: LeftWidth }">
<text class="cell-text">{{ row.rowHeader || rowIndex + 1 }}</text>
</view>
<!-- 数据单元格 -->
<view
v-for="(col, colIndex) in columns"
:key="'cell-' + rowIndex + '-' + colIndex"
class="table-cell data-cell"
:style="{ width: col.width + 'rpx', minWidth: col.width + 'rpx' }"
>
<view v-for="(col, colIndex) in columns" :key="'cell-' + rowIndex + '-' + colIndex"
class="table-cell data-cell" :style="{ width: col.width + 'rpx', minWidth: col.width + 'rpx' }">
<template v-if="customTable">
<slot
name="customCell"
:row="row"
:col="col"
:colIndex="colIndex"
:rowIndex="rowIndex"
></slot>
<slot name="customCell" :row="row" :col="col" :colIndex="colIndex" :rowIndex="rowIndex"></slot>
</template>
<template v-else>
<text :class="[`${isDetail ? '' : 'cell-text'}`]">{{ formatValue(row.data[colIndex]) }}</text>
<template v-if="row.unit && formatValue(row.data[colIndex]) != '-'">
<text class="unit">{{ row.unit }}</text>
</template>
</template>
<template v-else><text :class="[`${isDetail ? '' : 'cell-text'}`]">{{ formatValue(row.data[colIndex]) }}</text></template>
</view>
</view>
</view>
<template v-if="hasFooter">
<view
class="footer-row"
:style="{width:tableWidth}"
v-if="maxLength && tableData.length < maxLength"
>
<view
class="add"
@click="$emit('clickAdd')"
></view>
<view class="footer-row" :style="{ width: tableWidth }" v-if="maxLength && tableData.length < maxLength">
<view class="add" @click="$emit('clickAdd')"></view>
</view>
</template>
</view>
......@@ -143,7 +114,7 @@ export default {
default: false
},
},
data () {
data() {
return {
tableData: [],
tableWidth: '',
......@@ -153,7 +124,7 @@ export default {
},
watch: {
data: {
handler (val) {
handler(val) {
this.tableData = val || []
this.$nextTick(() => {
this.getTableWidth()
......@@ -163,32 +134,32 @@ export default {
}
},
computed: {
id () {
id() {
return 'table-' + this.tableIndex
},
},
mounted () {
mounted() {
},
methods: {
formatValue (value) {
formatValue(value) {
return value !== null && value !== '' && value !== undefined ? value : '-'
},
handleRowClick (row, rowIndex) {
handleRowClick(row, rowIndex) {
if (this.isDetail) return
// 清除之前的定时器
if (this.clickTimer) {
clearTimeout(this.clickTimer)
}
this.clickedRowIndex = rowIndex;
this.$emit('rowClick', row, rowIndex, this.tableIndex)
// 0.5秒后清除点击样式
this.clickTimer = setTimeout(() => {
this.clickedRowIndex = -1
}, 500)
},
getTableWidth () {
getTableWidth() {
const query = uni.createSelectorQuery()
query.select(`#${this.id}`).boundingClientRect(data => {
if (data && data.width) this.tableWidth = data.width + 'px'
......@@ -257,9 +228,11 @@ export default {
border-bottom: 2rpx solid #fff;
border-right: 1rpx solid #fff;
}
.required-text {
color: #f24724;
}
// 顶部表头
.header-row {
position: sticky;
......@@ -313,7 +286,7 @@ export default {
.data-cell {
background-color: rgba($color: #000000, $alpha: 0.05) !important;
}
.row-header-cell {
background-color: rgba($color: #000000, $alpha: 0.05) !important;
......@@ -333,12 +306,14 @@ export default {
text-overflow: ellipsis;
white-space: nowrap;
}
.footer-row {
width: 100%;
height: 88rpx;
padding: 16rpx 24rpx;
border-top: 2rpx solid #fff;
background: #f9fafc;
.add {
width: 56rpx;
height: 56rpx;
......@@ -350,6 +325,7 @@ export default {
justify-content: center;
position: sticky;
left: 24rpx;
&::before,
&::after {
position: absolute;
......@@ -360,17 +336,20 @@ export default {
background: #4673ff;
border-radius: 4rpx;
}
&::before {
width: 4rpx;
height: 28rpx;
}
&::after {
width: 28rpx;
height: 4rpx;
}
}
}
.is-detail{
.is-detail {
color: #999 !important;
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!