index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="page-content">
  3. <view class="cu-form-group justify-between">
  4. <view class="" @tap="cancal()">取消</view>
  5. <view class="text-title">{{title}}</view>
  6. <view :style="{color: themeColor}" @tap="submit()">确认</view>
  7. </view>
  8. <scroll-view scroll-y style="max-height: 600rpx;">
  9. <template v-if="checkedList.length">
  10. <block v-for="(item, index) in checkedList" :key="index">
  11. <view class="cu-form-group justify-between" @tap="changeCheck(item)">
  12. <view class="my-items-title">{{item[showParam]}} <text style="margin-left: 10rpx;">{{item[showParam]?item[showOther] :""}}</text></view>
  13. <template v-if="item.isCheck">
  14. <view class="iconfont icon-duihao" :style="{color: themeColor}"></view>
  15. </template>
  16. </view>
  17. </block>
  18. </template>
  19. <template v-else>
  20. <view class="text-center">暂无数据~</view>
  21. </template>
  22. </scroll-view>
  23. <slot></slot>
  24. </view>
  25. </template>
  26. <script>
  27. Object.clone = (obj, func = false) => {
  28. if (!obj || !(obj instanceof Object) || (typeof obj == "function")) {
  29. if (typeof obj == "function" && func) {
  30. return null;
  31. }
  32. return obj;
  33. }
  34. var constructor = obj.constructor;
  35. var result = new constructor();
  36. for (var key in obj) {
  37. if (obj.hasOwnProperty(key)) {
  38. result[key] = Object.clone(obj[key]);
  39. }
  40. }
  41. return result;
  42. };
  43. /**********
  44. * @author fjj
  45. * @list 需要选择的列表数据,如果没有传空数组
  46. * @showParam 显示字段
  47. * @defaultValue 默认选中数据,数据对象格式
  48. * @title 标题名称
  49. * @isMultiple 是否多选,默认多选
  50. * @cancel 方法 点击取消时触发
  51. * @change 方法 点击确定时触发 返回selectedList数据
  52. * ********/
  53. export default {
  54. props: {
  55. list: {
  56. require: true,
  57. type: Array,
  58. default () {
  59. return [];
  60. },
  61. },
  62. isMultiple: {
  63. require: false,
  64. type: Boolean,
  65. default: true,
  66. },
  67. showParam: {
  68. require: true,
  69. type: String,
  70. default: 'name',
  71. },
  72. showOther: {
  73. require: true,
  74. type: String,
  75. default: '',
  76. },
  77. defaultValue: {
  78. require: true,
  79. type: Array,
  80. default () {
  81. return [];
  82. },
  83. },
  84. title: {
  85. require: true,
  86. type: String,
  87. },
  88. },
  89. watch: {
  90. list(arr) {
  91. this.checkedList = Object.clone(arr);
  92. this.resetDefaultValueFun();
  93. },
  94. },
  95. computed: {
  96. },
  97. data() {
  98. return {
  99. checkedList: [],
  100. themeColor: this.$ThemeColor || '#1890FF',
  101. };
  102. },
  103. mounted() {
  104. this.checkedList = Object.clone(this.list);
  105. this.resetDefaultValueFun();
  106. },
  107. methods: {
  108. resetDefaultValueFun() {
  109. if (this.defaultValue.length) {
  110. this.defaultValue.map(arrParam => {
  111. for (let i = 0; i < this.checkedList.length; i++) {
  112. if (arrParam === this.checkedList[i][this.showParam]) {
  113. this.checkedList[i].isCheck = true;
  114. return;
  115. }
  116. }
  117. });
  118. }
  119. },
  120. resetCheckedList() {
  121. this.checkedList = Object.clone(this.list);
  122. this.resetDefaultValueFun();
  123. },
  124. cancal() {
  125. this.resetCheckedList();
  126. this.$emit("cancel");
  127. },
  128. submit() {
  129. this.$emit("change", {
  130. selectedList: this.checkedList.filter((item) => {
  131. return item.isCheck === true;
  132. }),
  133. })
  134. },
  135. changeCheck(item) {
  136. if (!this.isMultiple) {
  137. this.checkedList.map((item) => {
  138. return item.isCheck = false;
  139. })
  140. }
  141. item.isCheck = item.isCheck ? false : true;
  142. this.$forceUpdate();
  143. },
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .page-content {
  149. background: #FFFFFF;
  150. padding: 0;
  151. .text-title {
  152. color: $uni-text-color;
  153. }
  154. .text-theme {
  155. //设定自己的主题色
  156. }
  157. .cu-form-group {
  158. font-size: 30rpx;
  159. color: $uni-text-color;
  160. background-color: #ffffff;
  161. padding: 1rpx 30rpx;
  162. display: flex;
  163. -webkit-box-align: center;
  164. align-items: center;
  165. min-height: 100rpx;
  166. }
  167. .justify-between {
  168. -webkit-box-pack: justify;
  169. justify-content: space-between;
  170. }
  171. .text-center {
  172. text-align: center;
  173. }
  174. }
  175. //勾选符号
  176. // @font-face {
  177. // font-family: "iconfont";
  178. // src: url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAKMAAsAAAAABjQAAAJCAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCCcApAXAE2AiQDCAsGAAQgBYRtBzAbggXIHpIkRaoQRWE8BAUAhAg+9vv9nmuIa1TNKpEhUQKVBCVQOoRK8vy1hHc1bfdP6w7cjv8uKbWo1L2kX+ayoTeP0Yzv40HyjuJQSNJSa9Mn7p3+CfRBRj2g3PaksSZN6gLq4kAKcC+MukhKKOOGsQtcwn0ClXplpHZGp5dZrYy1LBB3jqWx2lxYJmO5cqGo2ZuJJ7ny5CF5wzyG34//SlFLIk9ZDfu3Iybr/1VlF6T3pWPXPiFCQIdzpJjGZMRxbXpXhWBchcp0pUFsX7XBr6pSyXeJvdoF++us6mrQDRX3pHSXCpDAbY1Vi45RbyVqr+4+Vv41lNf8mPUeld/ee48O4td8LZrlbRstDQ91t8/t+uHP0te0gaUQLDR1zCstK//lVRn4WRjsDm2Zfl6mfA+e4E8oe/ZkutpyJpmqrB1M1J6hqVIlSrC/0ddYS8tp86FcywhvmZ4UqXLDZMZOI1dlBoVy66g0ZexwlSZShcgqMOkCINS7l+/T9AKRqvdOZuwncq3+UKiPClQ6jaYzq4yGU78tUSM0Qd8BxxAhd9xUH9UuopX4msyqQ34VZezEoJgrFHNjGKKcY0O8aZWIOHApAhgFj6HvC4ikcNGgnE0UdebzvO5FOUMErN42CWkIMgHdDuAwCCHuDyf1pc8vQpaETyNbumqyq5AUcyYHRTmFHuSYIezVdS/PxDZZSgjhACcJATAKZiGfTwBR/SwXMpAce0Qy0ilv9+N9Dbn1TcHXHYFKljUJe1qquEkcWxOMAQ==') format('woff2');
  179. // }
  180. .iconfont {
  181. border: 2px solid #007aff;
  182. border-left: 0;
  183. border-top: 0;
  184. height: 12px;
  185. width: 6px;
  186. transform-origin: center;
  187. /* #ifndef APP-NVUE */
  188. transition: all 0.3s;
  189. /* #endif */
  190. transform: rotate(45deg);
  191. }
  192. .icon-duihao:before {
  193. // content: "\e60b";
  194. }
  195. </style>