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

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