Ctable.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <div class="address">
  3. <ul class="headTable clearfix">
  4. <li v-for="(item, index) in headArr" :class="'top_' + index" :style="getWidth(index)" >
  5. {{item}}
  6. </li>
  7. </ul>
  8. <ul class="contentTable clearfix" v-if="data.length > 0">
  9. <li v-for="(item, index) in data" :class="'clearfix content_' + index" :style="getHeight()" v-bind:key="index" @dblclick="clickTwo(index)">
  10. <div class="item" v-for="(childrenItem, childrenIndex) in item" v-bind:key="childrenIndex + 'child'" :style="getStyle(childrenIndex)">
  11. <template v-if="childrenItem === '操作' ">
  12. <div class="control">
  13. <div v-for="(control, controlIndex) in controlArray" v-bind:key="controlIndex" @click="controlClick(index, controlIndex)" class="controlItem" :class="{controlHeight : controlStyle !== 'row'}">
  14. {{control[0]}}
  15. </div>
  16. </div>
  17. </template>
  18. <template v-else-if="childrenItem === '序号' ">
  19. {{index + 1}}
  20. </template>
  21. <template v-else-if="childrenItem !== undefined && childrenItem[0] !== '' && childrenItem[0] === '规格书'">
  22. <a :href="childrenItem[1]" v-if="childrenItem[1]" class="guigeshu" target="_blank">
  23. </a>
  24. <span v-else>-</span>
  25. </template>
  26. <template v-else-if="childrenItem !== undefined && childrenItem[0] && childrenItem[0] === '设为默认'">
  27. <div class="setAuto" :class="{active : childrenItem[1] === 1}" @click="setAuto(index)">
  28. <i class="el-icon-success"></i>
  29. {{childrenItem[1] === 1 ? '默认地址' : '设为默认'}}
  30. </div>
  31. </template>
  32. <template v-else-if="childrenItem !== undefined && childrenItem[0] && childrenItem[0] === '报关单'">
  33. <div class="control">
  34. <div v-for="(control, controlIndex) in controlArray" v-bind:key="controlIndex" class="controlItem">
  35. <a :href="control[1] + childrenItem[1]">{{control[0]}}</a>
  36. </div>
  37. </div>
  38. </template>
  39. <template v-else-if="childrenItem !== undefined && childrenItem[0] && childrenItem[0] === '时间戳'">
  40. {{childrenItem[1]}}
  41. </template>
  42. <template v-else>
  43. <!-- 这里加多一个是为了解决处理父元素 display:table带来的影响,导致文本不能垂直居中问题 -->
  44. <div :style="getWidth2(childrenIndex)">{{childrenItem || '-'}}</div>
  45. </template>
  46. </div>
  47. </li>
  48. </ul>
  49. <div class="block clearfix" v-if="totalElements > 10" >
  50. <div class="pull-right">
  51. <el-pagination
  52. @current-change='handleCurrentChange'
  53. :current-page.sync='currentPage1'
  54. :page-size='10'
  55. layout='prev, pager, next'
  56. :total='totalElements'
  57. >
  58. </el-pagination>
  59. <ul class="pagination" style="float:right;margin: 0px;margin-left:20px;">
  60. <li>
  61. <input type="number" class="page-number" @keyup.13="changePage" v-model="currentPage2">
  62. </li>
  63. <li>
  64. <a class="page-a" @click="changePage">GO</a>
  65. </li>
  66. </ul>
  67. </div>
  68. </div>
  69. <div v-else-if="totalElements === 0" class="noContent" v-show="showNoCannet">
  70. <div>暂无数据</div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. export default {
  76. props: {
  77. headArr: {
  78. type: Array,
  79. default: []
  80. // default: ['联系人', '联系地址', '联系电话', '操作', '']
  81. },
  82. StyleWidth: {
  83. type: Array,
  84. default: []
  85. // default: [180, 524, 170, 164, 124]
  86. },
  87. StyleHeight: {
  88. type: Number,
  89. default: 60
  90. },
  91. // 这一块传进来的数据源
  92. data: {
  93. type: Array,
  94. // default: [['张三', '李四', '王五', '操作', ['设为默认', '1']]]
  95. default: []
  96. },
  97. controlArray: {
  98. type: Array,
  99. default: []
  100. // default: [['编辑', 'updateItem'],['删除', 'deleteItem']]
  101. // [['显示文本', '执行函数']]
  102. },
  103. currentPage: {
  104. type: Number,
  105. default: 1
  106. },
  107. totalElements: {
  108. type: Number,
  109. default: 1
  110. },
  111. controlStyle: {
  112. type: String,
  113. default: 'row'
  114. },
  115. showNoCannet:{
  116. type: Boolean,
  117. default: true
  118. }
  119. },
  120. watch: {
  121. currentPage(newVal) {
  122. this.currentPage2 = newVal
  123. this.currentPage1 = newVal
  124. }
  125. },
  126. data() {
  127. return {
  128. currentPage1: 1,
  129. currentPage2: this.currentPage
  130. }
  131. },
  132. methods: {
  133. changePage() {
  134. this.currentPage1 = this.currentPage2
  135. this.handleCurrentChange(this.currentPage1)
  136. },
  137. // 控制点击
  138. controlClick(index, controlIndex) {
  139. // index 为当前点击的这一行的索引 controlIndex 为当前所点击的控制器按钮的索引
  140. this.$emit(this.controlArray[controlIndex][1], index)
  141. },
  142. // 设为默认
  143. setAuto(index) {
  144. this.$emit('setAutoFn', index)
  145. },
  146. // 双击
  147. clickTwo(index) {
  148. this.$emit('clickTwo', index)
  149. },
  150. // 分页调整数据
  151. handleCurrentChange (page) {
  152. this.$emit('handleCurrentChange', page)
  153. },
  154. getWidth(i) {
  155. return {
  156. width: this.StyleWidth[i] + 'px'
  157. }
  158. },
  159. getWidth2(i) {
  160. return {
  161. // 这里减22是因为,父元素 display: table-cell带来的影响
  162. width: this.StyleWidth[i] - 22 + 'px'
  163. }
  164. },
  165. getHeight() {
  166. return {
  167. minHeight: this.StyleHeight + 'px'
  168. }
  169. },
  170. getStyle(i) {
  171. if (i % 2 == 0) {
  172. return {
  173. width: this.StyleWidth[i] + 'px',
  174. minHeight: this.StyleHeight + 'px',
  175. borderLeft: '1px solid rgba(0, 0, 0, 0)',
  176. borderRight: '1px solid rgba(0, 0, 0, 0)'
  177. }
  178. } else {
  179. return {
  180. width: this.StyleWidth[i] + 'px',
  181. minHeight: this.StyleHeight + 'px',
  182. borderLeft: '1px solid #f0f7fe',
  183. borderRight: '1px solid #f0f7fe'
  184. }
  185. }
  186. }
  187. }
  188. }
  189. </script>
  190. <style type="text/scss" lang="scss">
  191. .pull-right div {
  192. display: inline-block;
  193. }
  194. .address {
  195. padding: 0 12px;
  196. }
  197. .pagination {
  198. display: inline-block;
  199. padding-left: 0;
  200. margin: 20px 0;
  201. border-radius: 4px;
  202. }
  203. .pagination>li {
  204. display: inline;
  205. }
  206. input.page-number {
  207. vertical-align: inherit;
  208. display: inline-block;
  209. width: 40px;
  210. height: 31px;
  211. padding: 6px 6px;
  212. font-size: 14px;
  213. line-height: 1.42857143;
  214. color: #9B9792;
  215. text-align: center;
  216. background-color: #F6F5F4;
  217. background-image: none;
  218. border: 1px solid #c9c9c9;
  219. border-top-left-radius: 4px;
  220. border-bottom-left-radius: 4px;
  221. box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
  222. transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
  223. }
  224. .page-a {
  225. background: #0d5ffe !important;
  226. color: #fff !important;
  227. float: right!important;
  228. }
  229. .page-a {
  230. color: #fff;
  231. border-color: #0d5ffe;
  232. padding: 6px 6px!important;
  233. font-size: 14px!important;
  234. border-top-right-radius: 4px!important;
  235. border-bottom-right-radius: 4px!important;
  236. text-decoration: none;
  237. height: 31px;
  238. }
  239. .headTable{
  240. height: 48px;
  241. line-height: 48px;
  242. /*background: #f6f6f6;*/
  243. border: 1px solid #ebeef5;
  244. background: #deeffe;
  245. font-size: 14px;
  246. color: #333;
  247. &::after {
  248. clear: both;
  249. display: block;
  250. content: ' ';
  251. visibility: hidden;
  252. zoom: 1;
  253. }
  254. li {
  255. text-align: center;
  256. float: left;
  257. border-right:1px solid #ebeef5;
  258. &:nth-last-of-type(1) {
  259. border-right: 0px;
  260. }
  261. }
  262. }
  263. .contentTable {
  264. border: 1px solid #ebeef5;
  265. /*border-top: 0px;*/
  266. &::after {
  267. clear: both;
  268. display: block;
  269. content: ' ';
  270. visibility: hidden;
  271. zoom: 1;
  272. }
  273. li {
  274. display: table;
  275. &:nth-child(2n) {
  276. background: #f0f7fe;
  277. }
  278. &:nth-child(2n - 1) {
  279. background: #fff;
  280. }
  281. .item {
  282. text-align: center;
  283. display: table-cell;
  284. vertical-align: middle;
  285. /*float: left;*/
  286. position: relative;
  287. word-wrap:break-word;
  288. padding: 10px;
  289. .control {
  290. .controlItem {
  291. display: inline-block;
  292. color: #666;
  293. font-size: 12px;
  294. margin-right: 10px;
  295. width: 48px;
  296. height: 26px;
  297. line-height: 26px;
  298. &.controlItem {
  299. margin-right: 0px;
  300. }
  301. &:hover {
  302. color: #fff;
  303. cursor: pointer;
  304. background: #f97f25;
  305. a {
  306. color: #fff !important;
  307. }
  308. }
  309. &:nth-last-of-type(1) {
  310. margin-right: 0px
  311. }
  312. }
  313. }
  314. .setAuto {
  315. color: #666;
  316. font-size: 12px;
  317. cursor: pointer;
  318. &.active {
  319. color: #f97f25
  320. }
  321. &:hover {
  322. color: #f97f25
  323. }
  324. }
  325. }
  326. &.justly {
  327. line-height: 24px;
  328. }
  329. .guigeshu {
  330. width: 39px;
  331. height:39px;
  332. background: url(/spirit.png) no-repeat 0px -100px;
  333. margin: 0 auto;
  334. cursor: pointer;
  335. display: block;
  336. }
  337. }
  338. }
  339. .noContent {
  340. border: 1px solid #ebeef5;
  341. /*border-top: 0px;*/
  342. color: #909399;
  343. height: 60px;
  344. line-height: 60px;
  345. text-align: center;
  346. }
  347. .block {
  348. .pull-right {
  349. margin-right: 10px;
  350. margin-top: 20px;
  351. }
  352. }
  353. input.page-number {
  354. -moz-appearance:textfield;
  355. }
  356. input.page-number::-webkit-inner-spin-button,
  357. input.page-number::-webkit-outer-spin-button {
  358. -webkit-appearance: none;
  359. margin: 0;
  360. }
  361. .el-pager li{
  362. color: #0d5ffe;
  363. text-decoration: none;
  364. background-color: #fff;
  365. border: 1px solid #c9c9c9;
  366. font-size: 10px;
  367. min-width: 33px;
  368. height: 30px;
  369. border-right: none;
  370. }
  371. .el-pager li:not(.active):hover, .el-pagination button:hover {
  372. z-index: 3;
  373. color: #fff;
  374. background-color: #0d5ffe;
  375. border-color: #c9c9c9;
  376. }
  377. .el-pager li.active {
  378. background: #0d5ffe!important;
  379. color:#fff;
  380. }
  381. .el-pagination {
  382. padding: 0;
  383. }
  384. .el-pagination .btn-next, .el-pagination .btn-prev {
  385. color: #0d5ffe;
  386. width: 33px;
  387. height: 30px;
  388. }
  389. .el-pagination .btn-next {
  390. border-top-right-radius: 4px;
  391. border-bottom-right-radius: 4px;
  392. border: 1px solid #c9c9c9;
  393. padding-left: 8px;
  394. }
  395. .el-pagination .btn-prev {
  396. border-top-left-radius: 4px;
  397. border-bottom-left-radius: 4px;
  398. border: 1px solid #c9c9c9;
  399. border-right:0;
  400. padding-right: 8px;
  401. }
  402. .el-icon-arrow-left:before {
  403. content: "\f100";
  404. font-family: FontAwesome;
  405. }
  406. .el-icon-arrow-right:before {
  407. content: "\f101";
  408. font-family: FontAwesome;
  409. }
  410. </style>