球星卡微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
4.7 KiB

  1. <template>
  2. <view class="formBox" :style="{width: formWidth,height: formHeight}">
  3. <!-- 表头 -->
  4. <view class="headerBox" :style="{height: formRowHeight,width: length + 'rpx',lineHeight:formRowHeight}">
  5. <view class="numberBox" v-if="showNumber" :style="{height: formRowHeight}">
  6. 序号
  7. </view>
  8. <view
  9. class="headerTitle"
  10. v-for="itemH in Header"
  11. :style="{height: formRowHeight,width: itemH.width+'rpx', border: border ? '1px solid #F6F6F6' : 'none', 'background-color': headBgColor}">
  12. {{itemH.text}}
  13. </view>
  14. </view>
  15. <view class="titel" v-if="Content.length <= 0">
  16. 暂无数据
  17. </view>
  18. <view :style="{width: length + 'rpx'}">
  19. <view class="contentBox" v-for="(itemC,index) in Content" @click="clickList(itemC,index)">
  20. <block v-for="(itemH,index2) in Header">
  21. <view class="keyBox" :style="{height: formRowHeight,width: itemH.width+'rpx', border: border ? '1px solid #F6F6F6' : 'none'}">
  22. {{itemC[itemH.key]}}
  23. </view>
  24. </block>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. /*
  31. *
  32. *
  33. *
  34. */
  35. export default {
  36. name:'nk-form',
  37. props:{
  38. Header: {
  39. type: Array,
  40. default: ()=>{
  41. return []
  42. }
  43. },
  44. Content: {
  45. type: Array,
  46. default: ()=>{
  47. return []
  48. }
  49. },
  50. height: {
  51. type: [String,Number],
  52. default: 1000
  53. },
  54. width: {
  55. type: [String,Number],
  56. default: '600'
  57. },
  58. showNumber: {
  59. type: Boolean,
  60. default: true
  61. },
  62. rowHeight: {
  63. type: [String,Number],
  64. default: 80
  65. },
  66. border: {
  67. type: Boolean,
  68. default: true
  69. },
  70. headBgColor: {
  71. type: String,
  72. default: '#f7f5f6'
  73. }
  74. },
  75. data() {
  76. return {
  77. headerData:'',
  78. contentData:'',
  79. formWidth: '',
  80. formHeight: '',
  81. formRowHeight: '',
  82. length: 0
  83. };
  84. },
  85. created() {
  86. if(typeof this.width == 'string'){
  87. if(this.width.indexOf('rpx') > -1){
  88. this.formWidth = this.width;
  89. }
  90. if(this.width.indexOf('%') > -1){
  91. this.formWidth = this.width;
  92. }
  93. else{
  94. this.formWidth = this.width + 'rpx';
  95. }
  96. }else{
  97. this.formWidth = this.width + 'rpx';
  98. }
  99. if(typeof this.height == 'string'){
  100. if(this.height.indexOf('rpx') > -1){
  101. this.formHeight = this.height;
  102. }
  103. if(this.height.indexOf('%') > -1){
  104. this.formHeight = this.height;
  105. }
  106. else{
  107. this.formHeight = this.height + 'rpx';
  108. }
  109. }else{
  110. this.formHeight = this.height + 'rpx';
  111. }
  112. if(typeof this.rowHeight == 'string'){
  113. if(this.rowHeight.indexOf('rpx') > -1){
  114. this.formRowHeight = this.rowHeight + 'rpx';
  115. }
  116. if(this.rowHeight.indexOf('%') > -1){
  117. this.formRowHeight = this.rowHeight;
  118. }
  119. else{
  120. this.formHeight = this.height + 'rpx';
  121. }
  122. }else{
  123. this.formRowHeight = this.rowHeight + 'rpx';
  124. }
  125. },
  126. methods:{
  127. // 计算总长度
  128. getLength(){
  129. for(let i = 0; i < this.Header.length; i++){
  130. this.length = this.length + this.Header[i].width * 1;
  131. }
  132. if(this.showNumber){
  133. this.length = this.length + 80;
  134. }
  135. },
  136. // 点击事件
  137. clickList(event,index) {
  138. let data = {
  139. content: event,
  140. index: index
  141. }
  142. this.$emit("clickList",data);
  143. }
  144. },
  145. mounted:function(){
  146. this.getLength();
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. .formBox{
  152. overflow: auto;
  153. position: relative;
  154. .headerBox{
  155. position: sticky;
  156. top: 0;
  157. display: flex;
  158. justify-content: flex-start;
  159. .numberBox,.headerTitle{
  160. display: inline-flex;
  161. align-items: center;
  162. justify-content: center;
  163. font-size: 30rpx;
  164. font-weight: 900;
  165. color: rgb(68, 68, 68);
  166. // background-color: #dddddd;
  167. background-color: #f7f5f6;
  168. border: 1px solid #F6F6F6;
  169. box-sizing: border-box;
  170. }
  171. .numberBox{
  172. width: 80rpx;
  173. }
  174. }
  175. .contentBox{
  176. .keyBox{
  177. display: inline-flex;
  178. align-items: center;
  179. justify-content: center;
  180. font-size: 30rpx;
  181. font-weight: 900;
  182. border: 1px solid #F6F6F6;
  183. box-sizing: border-box;
  184. }
  185. }
  186. // .contentBox:nth-child(2n){
  187. // background-color: #F1F1F1;
  188. // }
  189. .titel{
  190. text-align: center;
  191. margin-top: 80rpx;
  192. color: #007AFF;
  193. }
  194. }
  195. /* .headerBox{
  196. height: 60rpx;
  197. position: sticky;
  198. top: 0;
  199. } */
  200. // .headerBoxII{
  201. // height: 60rpx;
  202. // line-height: 60rpx;
  203. // display: inline-block;
  204. // text-align: center;
  205. // font-size: 30rpx;
  206. // font-weight: 900;
  207. // color: rgb(68, 68, 68);
  208. // }
  209. // .headerBoxIII{
  210. // background-color: #dddddd;
  211. // border: 1px solid rgb(235, 238, 245);
  212. // }
  213. // .contentBox{
  214. // height: 60rpx;
  215. // line-height: 60rpx;
  216. // float: left;
  217. // text-align: center;
  218. // }
  219. // .contentBoxII{
  220. // height: 60rpx;
  221. // line-height: 60rpx;
  222. // border: 1px solid rgb(235, 238, 245);
  223. // }
  224. // .contentBoxII:nth-child(2n){
  225. // background-color: #E6E6E6;
  226. // }
  227. // .tipsBox{
  228. // margin-top: 30rpx;
  229. // font-size: 40rpx;
  230. // text-align: center;
  231. // color: #999;
  232. // }
  233. </style>