球星卡微信小程序
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.

235 lines
4.5 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'}">
  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'}">
  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. },
  67. data() {
  68. return {
  69. headerData:'',
  70. contentData:'',
  71. formWidth: '',
  72. formHeight: '',
  73. formRowHeight: '',
  74. length: 0
  75. };
  76. },
  77. created() {
  78. if(typeof this.width == 'string'){
  79. if(this.width.indexOf('rpx') > -1){
  80. this.formWidth = this.width;
  81. }
  82. if(this.width.indexOf('%') > -1){
  83. this.formWidth = this.width;
  84. }
  85. else{
  86. this.formWidth = this.width + 'rpx';
  87. }
  88. }else{
  89. this.formWidth = this.width + 'rpx';
  90. }
  91. if(typeof this.height == 'string'){
  92. if(this.height.indexOf('rpx') > -1){
  93. this.formHeight = this.height;
  94. }
  95. if(this.height.indexOf('%') > -1){
  96. this.formHeight = this.height;
  97. }
  98. else{
  99. this.formHeight = this.height + 'rpx';
  100. }
  101. }else{
  102. this.formHeight = this.height + 'rpx';
  103. }
  104. if(typeof this.rowHeight == 'string'){
  105. if(this.rowHeight.indexOf('rpx') > -1){
  106. this.formRowHeight = this.rowHeight + 'rpx';
  107. }
  108. if(this.rowHeight.indexOf('%') > -1){
  109. this.formRowHeight = this.rowHeight;
  110. }
  111. else{
  112. this.formHeight = this.height + 'rpx';
  113. }
  114. }else{
  115. this.formRowHeight = this.rowHeight + 'rpx';
  116. }
  117. },
  118. methods:{
  119. // 计算总长度
  120. getLength(){
  121. for(let i = 0; i < this.Header.length; i++){
  122. this.length = this.length + this.Header[i].width * 1;
  123. }
  124. if(this.showNumber){
  125. this.length = this.length + 80;
  126. }
  127. },
  128. // 点击事件
  129. clickList(event,index) {
  130. let data = {
  131. content: event,
  132. index: index
  133. }
  134. this.$emit("clickList",data);
  135. }
  136. },
  137. mounted:function(){
  138. this.getLength();
  139. }
  140. }
  141. </script>
  142. <style lang="scss">
  143. .formBox{
  144. overflow: auto;
  145. position: relative;
  146. .headerBox{
  147. position: sticky;
  148. top: 0;
  149. display: flex;
  150. justify-content: flex-start;
  151. .numberBox,.headerTitle{
  152. display: inline-flex;
  153. align-items: center;
  154. justify-content: center;
  155. font-size: 30rpx;
  156. font-weight: 900;
  157. color: rgb(68, 68, 68);
  158. // background-color: #dddddd;
  159. background-color: #f7f5f6;
  160. border: 1px solid #F6F6F6;
  161. box-sizing: border-box;
  162. }
  163. .numberBox{
  164. width: 80rpx;
  165. }
  166. }
  167. .contentBox{
  168. .keyBox{
  169. display: inline-flex;
  170. align-items: center;
  171. justify-content: center;
  172. font-size: 30rpx;
  173. font-weight: 900;
  174. border: 1px solid #F6F6F6;
  175. box-sizing: border-box;
  176. }
  177. }
  178. // .contentBox:nth-child(2n){
  179. // background-color: #F1F1F1;
  180. // }
  181. .titel{
  182. text-align: center;
  183. margin-top: 80rpx;
  184. color: #007AFF;
  185. }
  186. }
  187. /* .headerBox{
  188. height: 60rpx;
  189. position: sticky;
  190. top: 0;
  191. } */
  192. // .headerBoxII{
  193. // height: 60rpx;
  194. // line-height: 60rpx;
  195. // display: inline-block;
  196. // text-align: center;
  197. // font-size: 30rpx;
  198. // font-weight: 900;
  199. // color: rgb(68, 68, 68);
  200. // }
  201. // .headerBoxIII{
  202. // background-color: #dddddd;
  203. // border: 1px solid rgb(235, 238, 245);
  204. // }
  205. // .contentBox{
  206. // height: 60rpx;
  207. // line-height: 60rpx;
  208. // float: left;
  209. // text-align: center;
  210. // }
  211. // .contentBoxII{
  212. // height: 60rpx;
  213. // line-height: 60rpx;
  214. // border: 1px solid rgb(235, 238, 245);
  215. // }
  216. // .contentBoxII:nth-child(2n){
  217. // background-color: #E6E6E6;
  218. // }
  219. // .tipsBox{
  220. // margin-top: 30rpx;
  221. // font-size: 40rpx;
  222. // text-align: center;
  223. // color: #999;
  224. // }
  225. </style>