myCard.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <!-- myCard.vue(增强版,添加单选功能) -->
  2. <template>
  3. <view class="card_container">
  4. <view class="card_box">
  5. <!-- 标题区域 -->
  6. <view class="header_box" v-if="title">
  7. <view class="title_left">
  8. <view class="round" v-if="index">{{ index }}</view>
  9. <view class="orderId" :style="{ marginLeft: index ? '16rpx' : '' }">{{
  10. title
  11. }}</view>
  12. </view>
  13. <!-- 状态标签 -->
  14. <view class="status-tag" v-if="status">{{ status }}</view>
  15. <!-- 单选按钮 -->
  16. <view class="radio-tag" v-if="showRadio" @click.stop="handleRadioClick">
  17. <u-radio-group v-model="radioValueModel" placement="row">
  18. <u-radio :name="item.id" :iconSize="32" activeColor="#3c9cff"></u-radio>
  19. </u-radio-group>
  20. </view>
  21. </view>
  22. <view class="item_box rx-bc" v-for="(_item, i) in columns" :key="i">
  23. <template v-for="val in _item">
  24. <view class="perce50" :class="[val.className, { 'full-width': val.isFullWidth }]"
  25. :style="val.style" :key="val.prop" v-if="!val.isNone">
  26. <!-- 操作行 -->
  27. <view class="item_one rx-sc" v-if="val.type == 'action'">
  28. <view class="lable">{{ val.label }}</view>
  29. <view class="text" style="flex-wrap: wrap">
  30. <template v-for="(btn, bI) in btnList">
  31. <u-button :plain="true" :hairline="true" size="mini" :type="btn.btnType"
  32. v-if="judge(btn)" :text="btn.name" @click="action(btn)" :key="bI">
  33. </u-button>
  34. </template>
  35. </view>
  36. </view>
  37. <!-- 普通信息行 -->
  38. <view class="item_one rx-sc kk" v-else>
  39. <view class="lable">{{ val.label }}</view>
  40. <view class="text" :class="val.valueClass" v-if="val.formatter">{{
  41. val.formatter(item) || ""
  42. }}</view>
  43. <view class="text" :class="val.valueClass" v-else-if="val.slot">
  44. <slot :name="val.slot"></slot>
  45. </view>
  46. <view class="text" :class="val.valueClass" v-else>{{
  47. item[val.prop] || ""
  48. }}</view>
  49. </view>
  50. </view>
  51. </template>
  52. </view>
  53. <!-- 查看详情 -->
  54. <view class="footer-link" v-if="showDetail" @click="goDetail">
  55. <text>查看详情</text>
  56. <u-icon name="arrow-right" size="24" color="#999999"></u-icon>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. props: {
  64. btnList: {
  65. type: Array,
  66. default: () => []
  67. },
  68. item: {
  69. type: Object,
  70. default: () => ({})
  71. },
  72. columns: {
  73. type: Array,
  74. default: () => []
  75. },
  76. title: {
  77. type: String,
  78. default: ""
  79. },
  80. status: {
  81. type: String,
  82. default: ""
  83. },
  84. index: {
  85. type: [String, Number],
  86. default: ""
  87. },
  88. showDetail: {
  89. type: Boolean,
  90. default: true
  91. },
  92. // 新增:是否显示单选按钮
  93. showRadio: {
  94. type: Boolean,
  95. default: false
  96. },
  97. // 新增:当前选中的值(父组件传入)
  98. radioValue: {
  99. type: [String, Number],
  100. default: null
  101. }
  102. },
  103. computed: {
  104. judge() {
  105. return (item) => {
  106. if (item.judge) {
  107. let is = true;
  108. item.judge.forEach(({
  109. key,
  110. value,
  111. authorities,
  112. fn
  113. }) => {
  114. if (authorities) {
  115. is = this.$isAuthorities(authorities);
  116. }
  117. if (value && !value.includes(this.item[key])) {
  118. is = false;
  119. }
  120. if (fn) {
  121. is = fn(this.item);
  122. }
  123. });
  124. return is;
  125. } else {
  126. return true;
  127. }
  128. };
  129. },
  130. radioValueModel: {
  131. get() {
  132. return this.radioValue;
  133. },
  134. set(val) {
  135. // 当单选值变化时触发事件
  136. if (val === this.item.id) {
  137. this.$emit('radioChange', this.item);
  138. }
  139. }
  140. }
  141. },
  142. methods: {
  143. action(item) {
  144. if (item.type == 1) {
  145. uni.navigateTo({
  146. url: item.pageUrl + "?id=" + this.item.id + (item.query || ""),
  147. });
  148. } else {
  149. this.$emit(item.apiName);
  150. }
  151. },
  152. goDetail() {
  153. this.$emit("goDetail", this.item);
  154. },
  155. handleRadioClick() {
  156. // 触发选中事件,与radioChange保持一致
  157. this.$emit('radioChange', this.item);
  158. }
  159. }
  160. };
  161. </script>
  162. <style lang="scss" scoped>
  163. .card_container {
  164. padding: 16rpx 0;
  165. }
  166. .card_box {
  167. background: #ffffff;
  168. border-radius: 24rpx;
  169. padding: 24rpx;
  170. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  171. position: relative;
  172. .rx-bc {
  173. display: flex;
  174. align-items: flex-start;
  175. flex-flow: row wrap;
  176. >view {
  177. margin-top: 24rpx;
  178. &:first-child,
  179. &:nth-child(2) {
  180. margin-top: 0;
  181. }
  182. }
  183. }
  184. .rx-sc {
  185. display: flex;
  186. align-items: flex-start;
  187. }
  188. .header_box {
  189. display: flex;
  190. justify-content: space-between;
  191. align-items: center;
  192. width: 100%;
  193. position: relative;
  194. background: linear-gradient(135deg, #eef5ff 0%, #f5f9ff 100%);
  195. padding: 20rpx 24rpx;
  196. border-radius: 20rpx 20rpx 0 0;
  197. margin: -24rpx -24rpx 24rpx -24rpx;
  198. width: calc(100% + 48rpx);
  199. box-sizing: border-box;
  200. .round {
  201. width: 44rpx;
  202. height: 44rpx;
  203. line-height: 44rpx;
  204. border-radius: 50%;
  205. background: $theme-color;
  206. color: #fff;
  207. text-align: center;
  208. font-size: 24rpx;
  209. font-weight: 600;
  210. flex-shrink: 0;
  211. }
  212. .orderId {
  213. color: #1f2b3c;
  214. font-size: 30rpx;
  215. font-weight: 600;
  216. white-space: nowrap;
  217. overflow: hidden;
  218. text-overflow: ellipsis;
  219. }
  220. .title_left {
  221. display: flex;
  222. align-items: center;
  223. flex: 1;
  224. padding-right: 120rpx;
  225. overflow: hidden;
  226. }
  227. .status-tag {
  228. background: #e3f2fd;
  229. color: #2196f3;
  230. font-size: 24rpx;
  231. padding: 6rpx 20rpx;
  232. border-radius: 30rpx;
  233. font-weight: 500;
  234. position: absolute;
  235. top: 50%;
  236. transform: translateY(-50%);
  237. right: 24rpx;
  238. z-index: 1;
  239. }
  240. .radio-tag {
  241. position: absolute;
  242. top: 50%;
  243. transform: translateY(-50%);
  244. right: 24rpx;
  245. z-index: 2;
  246. background: transparent;
  247. /deep/ .u-radio-group {
  248. .u-radio {
  249. padding: 0;
  250. margin-right: 0;
  251. }
  252. }
  253. }
  254. }
  255. .item_box {
  256. .text {
  257. display: flex;
  258. flex: 1;
  259. uni-button:after {
  260. border: none;
  261. }
  262. uni-button {
  263. width: 100rpx;
  264. margin-left: 10rpx;
  265. margin-right: 0;
  266. color: #fff !important;
  267. border: none;
  268. background: #157a2c;
  269. margin-top: 3px;
  270. }
  271. }
  272. .kk .text {
  273. overflow: hidden;
  274. text-overflow: ellipsis;
  275. white-space: nowrap;
  276. display: block;
  277. }
  278. .item_one {
  279. width: 100%;
  280. font-size: 28rpx;
  281. line-height: 44rpx;
  282. display: flex;
  283. align-items: flex-start;
  284. .lable {
  285. color: #8e9aae;
  286. flex-shrink: 0;
  287. margin-right: 16rpx;
  288. font-size: 26rpx;
  289. }
  290. .text {
  291. color: #1f2b3c;
  292. font-size: 28rpx;
  293. flex: 1;
  294. white-space: nowrap;
  295. overflow: hidden;
  296. text-overflow: ellipsis;
  297. min-width: 0;
  298. &.highlight {
  299. color: #4caf50;
  300. }
  301. }
  302. }
  303. .perce50 {
  304. width: 50%;
  305. box-sizing: border-box;
  306. padding-right: 20rpx;
  307. &:nth-child(2n) {
  308. padding-right: 0;
  309. padding-left: 20rpx;
  310. }
  311. }
  312. .perce100 {
  313. width: 100%;
  314. }
  315. .full-width {
  316. width: 100% !important;
  317. padding-left: 0 !important;
  318. padding-right: 0 !important;
  319. }
  320. }
  321. .footer-link {
  322. display: flex;
  323. justify-content: center;
  324. align-items: center;
  325. margin-top: 24rpx;
  326. padding-top: 20rpx;
  327. border-top: 2rpx solid #f0f2f5;
  328. color: #8e9aae;
  329. font-size: 28rpx;
  330. cursor: pointer;
  331. gap: 8rpx;
  332. &:active {
  333. opacity: 0.7;
  334. }
  335. }
  336. }
  337. </style>