| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <!-- 移动端表格组件 -->
- <template>
- <view class="custom-table-container">
- <!-- 表格容器 -->
- <div class="table-wrapper" >
- <view class="table" :id="id">
- <view class="table-body">
- <template v-for="(row, index) in columns">
- <view class="column" :style="{ width: (row[0] && row[0].width) ? row[0].width + 'rpx' : '200rpx' }">
- <view class="table-body-item" v-for="(item, rowIndex) in row" :key="item.id" :style="{
- height: item.rowspan > 1 ? (item.rowspan * 60) + 'rpx' : '60rpx',
- display: item.rowspan ? 'flex' : 'none',
- ...item.style,
- width: item.colspan ? getWidth(item) : 'auto'
- }" :class="{
- 'is-header': rowIndex === 0,
-
- 'is-readonly': equation[item.id]
- }">
- <!-- 输入框 -->
- <view class="input-wrapper">
-
- <textarea v-if="item.rowspan > 1" v-model="item.value" class="template-input"
- :id="item.id" :ref="item.id + 'ref'" :readonly="item.readonly == 2 || readonly||equation[item.id]"
- @input="calculation" :auto-height="true" :maxlength="200" />
- <input v-else v-model="item.value" class="template-input" :id="item.id"
- :ref="item.id + 'ref'" :disabled="item.readonly == 2 || readonly||equation[item.id]"
- @input="calculation" type="text" />
- </view>
- </view>
- </view>
- </template>
- </view>
- </view>
- </div>
- </view>
- </template>
- <script>
- import dictMixins from '@/mixins/dictMixins';
- export default {
- mixins: [dictMixins],
- props: {
- id: {
- type: String,
- default: ''
- },
- readonly: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- form: null,
- valueObj: {},
- domId: '',
- columns: [],
- units: {},
- equation: {},
-
- };
- },
- computed: {
-
- },
- methods: {
- getWidth(item) {
- let width = Number(item.style.width);
- if (item.colspanKey.length) {
- this.columns.forEach(cell => {
- cell.forEach(row => {
- if (item.colspanKey.includes(row.id)) {
- width += Number(row.style.width);
- }
- });
- });
- }
- return width + 'rpx';
- },
- calculation() {
- this.$emit('calculation');
- },
- equationValue({
- domId,
- value
- }) {
- this.columns.forEach((item, index) => {
- let cellIndex = item.findIndex(cell => cell.id == domId);
- if (cellIndex != '-1') {
- this.$set(this.columns[index][cellIndex], 'value', value);
- }
- });
- },
- getValue() {
- return {
- form: null,
- equation: this.equation,
- units: this.units,
- valueObj: {
- columns: this.columns
- }
- };
- },
- init({
- form,
- valueObj,
- equation,
- units
- }) {
- this.form = form;
- this.columns = valueObj.columns;
- this.equation = equation || {};
- this.units = units || {};
- console.log(this.units);
- console.log(this.equation);
- },
- }
- };
- </script>
- <style lang="scss" scoped>
- .custom-table-container {
- width: 100%;
- // overflow: hidden;
- .table-wrapper {
- width: 100%;
- // margin-top: 20rpx;
- .table {
- display: flex;
- min-width: 100%;
- .table-body {
- display: flex;
- .column {
- display: inline-block;
- .table-body-item {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: center;
- border: 1rpx solid #ddd;
- background-color: #fff;
- overflow: hidden;
- &.is-header {
- // background-color: #f2f2f2;
- .template-input {
- // background-color: #f2f2f2;
- }
- }
- &.is-selected {
- // background-color: #e6f7ff;
- border-color: #1890ff;
- }
- &.is-readonly {
- background-color: #f9f9f9;
- }
- .cell-actions {
- position: absolute;
- top: 0;
- right: 0;
- display: none;
- z-index: 10;
- .action-btn {
- width: 40rpx;
- height: 40rpx;
- line-height: 40rpx;
- text-align: center;
- background-color: rgba(0, 0, 0, 0.5);
- color: #fff;
- border-radius: 50%;
- font-size: 28rpx;
- &.delete {
- color: #f56c6c;
- }
- &.add {
- color: #409eff;
- margin-left: 5rpx;
- }
- &.deleteRow {
- color: #f56c6c;
- }
- &.addRow {
- color: #409eff;
- margin-left: 5rpx;
- }
- }
- }
- &:active .cell-actions {
- display: flex;
- }
- .input-wrapper {
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .template-input {
- width: 100%;
- height: 100%;
- border: none;
- text-align: center;
- background-color: transparent;
- font-size: 24rpx;
- padding: 0;
- line-height: 1.5;
- }
- textarea.template-input {
- padding: 10rpx;
- resize: none;
- }
- }
- }
- }
- }
- }
- .merge-tip {
- position: fixed;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- padding: 20rpx 40rpx;
- background-color: rgba(0, 0, 0, 0.7);
- color: #fff;
- border-radius: 8rpx;
- font-size: 28rpx;
- z-index: 1000;
- }
- .bottom-actions {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- z-index: 999;
- .action-sheet {
- background-color: #fff;
- border-top: 1rpx solid #e0e0e0;
- .sheet-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #e0e0e0;
- .title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- }
- .cancel {
- font-size: 28rpx;
- color: #999;
- }
- }
- .sheet-content {
- padding: 30rpx;
- .sheet-btn {
- width: 100%;
- height: 80rpx;
- line-height: 80rpx;
- text-align: center;
- border-radius: 8rpx;
- font-size: 32rpx;
- &.primary {
- background-color: #157a2c;
- color: #fff;
- &:active {
- background-color: #0f5e20;
- }
- }
- }
- }
- }
- }
- }
- </style>
|