| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <template>
- <view class="card_container">
- <view class="card_box">
- <!-- 标题区域 -->
- <view class="header_box" v-if="title">
- <view class="title_left">
- <view class="round" v-if="index">{{ index }}</view>
- <view class="orderId" :style="{ marginLeft: index ? '16rpx' : '' }">{{
- title
- }}</view>
- </view>
- <!-- 状态标签 -->
- <view class="status-tag" v-if="status">{{ status }}</view>
- <!-- 单选/多选控件 -->
- <view class="select-tag" v-if="showRadio" @click.stop>
- <!-- 单选模式:使用 u-radio-group(每个卡片独立,互斥) -->
- <u-radio-group
- v-if="selectionMode === 'single'"
- v-model="radioValueModel"
- placement="row"
- @change="handleRadioChange"
- >
- <u-radio
- :name="item.id"
- :iconSize="44"
- activeColor="#3c9cff"
- :labelSize="0"
- ></u-radio>
- </u-radio-group>
- <!-- 多选模式:使用独立 u-checkbox,由父组件控制选中状态 -->
- <u-checkbox
- v-else
- :name="item.id"
- :checked="isChecked"
- :iconSize="44"
- activeColor="#3c9cff"
- :labelSize="0"
- @change="handleCheckboxChange"
- ></u-checkbox>
- </view>
- </view>
- <!-- 内容区域(与原代码相同,省略...) -->
- <view class="item_box rx-bc" v-for="(_item, i) in columns" :key="i">
- <template v-for="val in _item">
- <view
- class="perce50"
- :class="[val.className, { 'full-width': val.isFullWidth }]"
- :style="val.style"
- :key="val.prop"
- v-if="!val.isNone"
- >
- <view class="item_one rx-sc" v-if="val.type == 'action'">
- <view class="lable">{{ val.label }}</view>
- <view class="text" style="flex-wrap: wrap">
- <template v-for="(btn, bI) in btnList">
- <u-button
- :plain="true"
- :hairline="true"
- size="mini"
- :type="btn.btnType"
- v-if="judge(btn)"
- :text="btn.name"
- @click="action(btn)"
- :key="bI"
- ></u-button>
- </template>
- </view>
- </view>
- <view class="item_one rx-sc kk" v-else>
- <view class="lable">{{ val.label }}</view>
- <view class="text" :class="val.valueClass" v-if="val.formatter">{{
- val.formatter(item) || ''
- }}</view>
- <view class="text" :class="val.valueClass" v-else-if="val.slot">
- <slot :name="val.slot"></slot>
- </view>
- <view class="text" :class="val.valueClass" v-else>{{
- item[val.prop] || ''
- }}</view>
- </view>
- </view>
- </template>
- </view>
- <view class="footer-link" v-if="showDetail" @click="goDetail">
- <text>查看详情</text>
- <u-icon name="arrow-right" size="24" color="#999999"></u-icon>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- btnList: { type: Array, default: () => [] },
- item: { type: Object, default: () => ({}) },
- columns: { type: Array, default: () => [] },
- title: { type: String, default: '' },
- status: { type: String, default: '' },
- index: { type: [String, Number], default: '' },
- showDetail: { type: Boolean, default: true },
- showRadio: { type: Boolean, default: false },
- radioValue: { type: [String, Number], default: null },
- selectionMode: { type: String, default: 'single' }, // 'single' or 'multiple'
- checkboxValue: { type: Array, default: () => [] }, // 父组件传入的选中ID数组
- },
- computed: {
- judge() {
- return (item) => {
- if (item.judge) {
- let is = true;
- item.judge.forEach(({ key, value, authorities, fn }) => {
- if (authorities) {
- is = this.$isAuthorities(authorities);
- }
- if (value && !value.includes(this.item[key])) {
- is = false;
- }
- if (fn) {
- is = fn(this.item);
- }
- });
- return is;
- } else {
- return true;
- }
- };
- },
- // 单选模式下的绑定值
- radioValueModel: {
- get() {
- return this.radioValue;
- },
- set(val) {
- if (val === this.item.id) {
- this.$emit('radioChange', this.item);
- }
- },
- },
- // 多选模式下的选中状态(根据 checkboxValue 数组判断)
- isChecked() {
- return this.checkboxValue.includes(this.item.id);
- },
- },
- methods: {
- action(item) {
- if (item.type == 1) {
- uni.navigateTo({
- url: item.pageUrl + '?id=' + this.item.id + (item.query || ''),
- });
- } else {
- this.$emit(item.apiName);
- }
- },
- goDetail() {
- this.$emit('goDetail', this.item);
- },
- handleRadioChange(val) {
- if (val === this.item.id) {
- this.$emit('radioChange', this.item);
- }
- },
- // 多选:点击 checkbox 时,通知父组件变更
- handleCheckboxChange(e) {
- this.$emit('checkboxChange', {
- checked: e, // e 为 boolean,表示当前 checkbox 是否被选中
- item: this.item,
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .card_container {
- padding: 16rpx 0;
- }
- .card_box {
- background: #ffffff;
- border-radius: 24rpx;
- padding: 24rpx;
- box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
- position: relative;
- .rx-bc {
- display: flex;
- align-items: flex-start;
- flex-flow: row wrap;
- > view {
- margin-top: 24rpx;
- &:first-child,
- &:nth-child(2) {
- margin-top: 0;
- }
- }
- }
- .rx-sc {
- display: flex;
- align-items: flex-start;
- }
- .header_box {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 100%;
- position: relative;
- background: linear-gradient(135deg, #eef5ff 0%, #f5f9ff 100%);
- padding: 20rpx 24rpx;
- border-radius: 20rpx 20rpx 0 0;
- margin: -24rpx -24rpx 24rpx -24rpx;
- width: calc(100% + 48rpx);
- box-sizing: border-box;
- .round {
- width: 44rpx;
- height: 44rpx;
- line-height: 44rpx;
- border-radius: 50%;
- background: $theme-color;
- color: #fff;
- text-align: center;
- font-size: 24rpx;
- font-weight: 600;
- flex-shrink: 0;
- }
- .orderId {
- color: #1f2b3c;
- font-size: 30rpx;
- font-weight: 600;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .title_left {
- display: flex;
- align-items: center;
- flex: 1;
- padding-right: 120rpx;
- overflow: hidden;
- }
- .status-tag {
- background: #e3f2fd;
- color: #2196f3;
- font-size: 24rpx;
- padding: 6rpx 20rpx;
- border-radius: 30rpx;
- font-weight: 500;
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- right: 24rpx;
- z-index: 1;
- }
- .select-tag {
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- right: 24rpx;
- z-index: 2;
- background: transparent;
- /deep/ .u-radio-group,
- /deep/ .u-checkbox-group {
- .u-radio,
- .u-checkbox {
- padding: 0;
- margin-right: 0;
- }
- }
- }
- }
- .item_box {
- .text {
- display: flex;
- flex: 1;
- uni-button:after {
- border: none;
- }
- uni-button {
- width: 100rpx;
- margin-left: 10rpx;
- margin-right: 0;
- color: #fff !important;
- border: none;
- background: #157a2c;
- margin-top: 3px;
- }
- }
- .kk .text {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- display: block;
- }
- .item_one {
- width: 100%;
- font-size: 28rpx;
- line-height: 44rpx;
- display: flex;
- align-items: flex-start;
- .lable {
- color: #8e9aae;
- flex-shrink: 0;
- margin-right: 16rpx;
- font-size: 26rpx;
- }
- .text {
- color: #1f2b3c;
- font-size: 28rpx;
- flex: 1;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- min-width: 0;
- &.highlight {
- color: #4caf50;
- }
- }
- }
- .perce50 {
- width: 50%;
- box-sizing: border-box;
- padding-right: 20rpx;
- &:nth-child(2n) {
- padding-right: 0;
- padding-left: 20rpx;
- }
- }
- .perce100 {
- width: 100%;
- }
- .full-width {
- width: 100% !important;
- padding-left: 0 !important;
- padding-right: 0 !important;
- }
- }
- .footer-link {
- display: flex;
- justify-content: center;
- align-items: center;
- margin-top: 24rpx;
- padding-top: 20rpx;
- border-top: 2rpx solid #f0f2f5;
- color: #8e9aae;
- font-size: 28rpx;
- cursor: pointer;
- gap: 8rpx;
- &:active {
- opacity: 0.7;
- }
- }
- }
- </style>
|