myCard.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <!-- 在最外层容器添加点击事件 -->
  3. <view class="card_container" @click="handleCardClick">
  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="select-tag" v-if="showRadio" @click.stop>
  17. <!-- 单选模式 -->
  18. <u-radio-group
  19. v-if="selectionMode === 'single'"
  20. v-model="radioValueModel"
  21. placement="row"
  22. @change="handleRadioChange"
  23. >
  24. <u-radio
  25. :name="item.id"
  26. :iconSize="44"
  27. activeColor="#3c9cff"
  28. :labelSize="0"
  29. ></u-radio>
  30. </u-radio-group>
  31. <!-- 多选模式 -->
  32. <u-checkbox
  33. v-else
  34. :name="item.id"
  35. :checked="isChecked"
  36. :iconSize="44"
  37. activeColor="#3c9cff"
  38. :labelSize="0"
  39. @change="handleCheckboxChange"
  40. ></u-checkbox>
  41. </view>
  42. </view>
  43. <!-- 内容区域 -->
  44. <view class="item_box rx-bc" v-for="(_item, i) in columns" :key="i">
  45. <template v-for="val in _item">
  46. <view
  47. class="perce50"
  48. :class="[val.className, { 'full-width': val.isFullWidth }]"
  49. :style="val.style"
  50. :key="val.prop"
  51. v-if="!val.isNone"
  52. >
  53. <view class="item_one rx-sc" v-if="val.type == 'action'">
  54. <view class="lable">{{ val.label }}</view>
  55. <view class="text" style="flex-wrap: wrap">
  56. <template v-for="(btn, bI) in btnList">
  57. <u-button
  58. :plain="true"
  59. :hairline="true"
  60. size="mini"
  61. :type="btn.btnType"
  62. v-if="judge(btn)"
  63. :text="btn.name"
  64. @click="action(btn)"
  65. :key="bI"
  66. ></u-button>
  67. </template>
  68. </view>
  69. </view>
  70. <view class="item_one rx-sc kk" v-else>
  71. <view class="lable">{{ val.label }}</view>
  72. <view class="text" :class="val.valueClass" v-if="val.formatter">{{
  73. val.formatter(item) || ''
  74. }}</view>
  75. <view class="text" :class="val.valueClass" v-else-if="val.slot">
  76. <slot :name="val.slot"></slot>
  77. </view>
  78. <view class="text" :class="val.valueClass" v-else>{{
  79. item[val.prop] || ''
  80. }}</view>
  81. </view>
  82. </view>
  83. </template>
  84. </view>
  85. <!-- 查看详情(阻止冒泡) -->
  86. <view class="footer-link" v-if="showDetail" @click.stop="goDetail">
  87. <text>查看详情</text>
  88. <u-icon name="arrow-right" size="24" color="#999999"></u-icon>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. export default {
  95. props: {
  96. btnList: { type: Array, default: () => [] },
  97. item: { type: Object, default: () => ({}) },
  98. columns: { type: Array, default: () => [] },
  99. title: { type: String, default: '' },
  100. status: { type: String, default: '' },
  101. index: { type: [String, Number], default: '' },
  102. showDetail: { type: Boolean, default: true },
  103. showRadio: { type: Boolean, default: false },
  104. radioValue: { type: [String, Number], default: null },
  105. selectionMode: { type: String, default: 'single' }, // 'single' or 'multiple'
  106. checkboxValue: { type: Array, default: () => [] },
  107. // 是否允许点击卡片切换选中(默认true)
  108. clickable: { type: Boolean, default: true },
  109. },
  110. computed: {
  111. judge() {
  112. return (item) => {
  113. if (item.judge) {
  114. let is = true;
  115. item.judge.forEach(({ key, value, authorities, fn }) => {
  116. if (authorities) {
  117. is = this.$isAuthorities(authorities);
  118. }
  119. if (value && !value.includes(this.item[key])) {
  120. is = false;
  121. }
  122. if (fn) {
  123. is = fn(this.item);
  124. }
  125. });
  126. return is;
  127. } else {
  128. return true;
  129. }
  130. };
  131. },
  132. // 单选模式下的绑定值
  133. radioValueModel: {
  134. get() {
  135. return this.radioValue;
  136. },
  137. set(val) {
  138. if (val === this.item.id) {
  139. this.$emit('radioChange', this.item);
  140. }
  141. },
  142. },
  143. // 多选模式下的选中状态
  144. isChecked() {
  145. return this.checkboxValue.includes(this.item.id);
  146. },
  147. },
  148. methods: {
  149. action(item) {
  150. if (item.type == 1) {
  151. uni.navigateTo({
  152. url: item.pageUrl + '?id=' + this.item.id + (item.query || ''),
  153. });
  154. } else {
  155. this.$emit(item.apiName);
  156. }
  157. },
  158. goDetail() {
  159. this.$emit('goDetail', this.item);
  160. },
  161. handleRadioChange(val) {
  162. if (val === this.item.id) {
  163. this.$emit('radioChange', this.item);
  164. }
  165. },
  166. handleCheckboxChange(e) {
  167. this.$emit('checkboxChange', {
  168. checked: e,
  169. item: this.item,
  170. });
  171. },
  172. // ============ 点击整个卡片 ============
  173. handleCardClick() {
  174. // 如果不可点击,直接返回
  175. if (!this.clickable) return;
  176. // 如果没有开启选择模式,返回
  177. if (!this.showRadio) return;
  178. // 单选模式:直接触发选中
  179. if (this.selectionMode === 'single') {
  180. // 如果当前卡片已选中,则取消选中(允许取消)
  181. if (this.radioValue === this.item.id) {
  182. this.$emit('radioChange', null);
  183. } else {
  184. this.$emit('radioChange', this.item);
  185. }
  186. return;
  187. }
  188. // 多选模式:切换选中状态
  189. const isChecked = this.checkboxValue.includes(this.item.id);
  190. this.$emit('checkboxChange', {
  191. checked: !isChecked,
  192. item: this.item,
  193. });
  194. },
  195. },
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .card_container {
  200. padding: 16rpx 0;
  201. // 增加点击反馈
  202. &:active {
  203. .card_box {
  204. transform: scale(0.99);
  205. transition: transform 0.15s ease;
  206. }
  207. }
  208. }
  209. .card_box {
  210. background: #ffffff;
  211. border-radius: 24rpx;
  212. padding: 24rpx;
  213. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  214. position: relative;
  215. transition: transform 0.15s ease;
  216. .rx-bc {
  217. display: flex;
  218. align-items: flex-start;
  219. flex-flow: row wrap;
  220. > view {
  221. margin-top: 24rpx;
  222. &:first-child,
  223. &:nth-child(2) {
  224. margin-top: 0;
  225. }
  226. }
  227. }
  228. .rx-sc {
  229. display: flex;
  230. align-items: flex-start;
  231. }
  232. .header_box {
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. width: 100%;
  237. position: relative;
  238. background: linear-gradient(135deg, #eef5ff 0%, #f5f9ff 100%);
  239. padding: 20rpx 24rpx;
  240. border-radius: 20rpx 20rpx 0 0;
  241. margin: -24rpx -24rpx 24rpx -24rpx;
  242. width: calc(100% + 48rpx);
  243. box-sizing: border-box;
  244. .round {
  245. width: 44rpx;
  246. height: 44rpx;
  247. line-height: 44rpx;
  248. border-radius: 50%;
  249. background: $theme-color;
  250. color: #fff;
  251. text-align: center;
  252. font-size: 24rpx;
  253. font-weight: 600;
  254. flex-shrink: 0;
  255. }
  256. .orderId {
  257. color: #1f2b3c;
  258. font-size: 30rpx;
  259. font-weight: 600;
  260. white-space: nowrap;
  261. overflow: hidden;
  262. text-overflow: ellipsis;
  263. }
  264. .title_left {
  265. display: flex;
  266. align-items: center;
  267. flex: 1;
  268. padding-right: 120rpx;
  269. overflow: hidden;
  270. }
  271. .status-tag {
  272. background: #e3f2fd;
  273. color: #2196f3;
  274. font-size: 24rpx;
  275. padding: 6rpx 20rpx;
  276. border-radius: 30rpx;
  277. font-weight: 500;
  278. position: absolute;
  279. top: 50%;
  280. transform: translateY(-50%);
  281. right: 24rpx;
  282. z-index: 1;
  283. }
  284. .select-tag {
  285. position: absolute;
  286. top: 50%;
  287. transform: translateY(-50%);
  288. right: 24rpx;
  289. z-index: 2;
  290. background: transparent;
  291. /deep/ .u-radio-group,
  292. /deep/ .u-checkbox-group {
  293. .u-radio,
  294. .u-checkbox {
  295. padding: 0;
  296. margin-right: 0;
  297. }
  298. }
  299. }
  300. }
  301. .item_box {
  302. .text {
  303. display: flex;
  304. flex: 1;
  305. uni-button:after {
  306. border: none;
  307. }
  308. uni-button {
  309. width: 100rpx;
  310. margin-left: 10rpx;
  311. margin-right: 0;
  312. color: #fff !important;
  313. border: none;
  314. background: #157a2c;
  315. margin-top: 3px;
  316. }
  317. }
  318. .kk .text {
  319. overflow: hidden;
  320. text-overflow: ellipsis;
  321. white-space: nowrap;
  322. display: block;
  323. }
  324. .item_one {
  325. width: 100%;
  326. font-size: 28rpx;
  327. line-height: 44rpx;
  328. display: flex;
  329. align-items: flex-start;
  330. .lable {
  331. color: #8e9aae;
  332. flex-shrink: 0;
  333. margin-right: 16rpx;
  334. font-size: 26rpx;
  335. }
  336. .text {
  337. color: #1f2b3c;
  338. font-size: 28rpx;
  339. flex: 1;
  340. white-space: nowrap;
  341. overflow: hidden;
  342. text-overflow: ellipsis;
  343. min-width: 0;
  344. &.highlight {
  345. color: #4caf50;
  346. }
  347. }
  348. }
  349. .perce50 {
  350. width: 50%;
  351. box-sizing: border-box;
  352. padding-right: 20rpx;
  353. &:nth-child(2n) {
  354. padding-right: 0;
  355. padding-left: 20rpx;
  356. }
  357. }
  358. .perce100 {
  359. width: 100%;
  360. }
  361. .full-width {
  362. width: 100% !important;
  363. padding-left: 0 !important;
  364. padding-right: 0 !important;
  365. }
  366. }
  367. .footer-link {
  368. display: flex;
  369. justify-content: center;
  370. align-items: center;
  371. margin-top: 24rpx;
  372. padding-top: 20rpx;
  373. border-top: 2rpx solid #f0f2f5;
  374. color: #8e9aae;
  375. font-size: 28rpx;
  376. cursor: pointer;
  377. gap: 8rpx;
  378. &:active {
  379. opacity: 0.7;
  380. }
  381. }
  382. }
  383. </style>