cert_pro.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div id="withdraw">
  3. <div class="table">
  4. <el-table
  5. v-if="tableData.length"
  6. height="100%"
  7. border
  8. style="width: 100%"
  9. :data="tableData"
  10. :row-class-name="tableRowClassName"
  11. >
  12. <el-table-column
  13. v-for="(prop, index) of tableProps"
  14. :key="index"
  15. :prop="prop"
  16. :label="tableHeaders[index]"
  17. >
  18. <template slot-scope="scope">
  19. <el-button
  20. type="text"
  21. v-if="prop === 'name'"
  22. @click="clickName(scope.row)"
  23. >{{scope.row[prop]}}</el-button>
  24. <el-button type="text" v-else-if="prop === 'ctrl'" @click="clickCtrl(scope.row, index)">编辑</el-button>
  25. <section v-else-if="prop === 'price'">
  26. <div>原价¥{{scope.row.origin_price}}</div>
  27. <div>现价¥{{scope.row.real_price}}</div>
  28. <div>会员价¥{{scope.row.vip_price}}</div>
  29. </section>
  30. <img class="img" v-else-if="prop === 'img'" :src="scope.row.img" alt="img">
  31. <span v-else>{{scope.row[prop]}}</span>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. </div>
  36. <el-pagination
  37. background
  38. @current-change="getTableData"
  39. @size-change="changePageSize"
  40. :current-page.sync="currentPage"
  41. :page-sizes="[10, 20, 30, 40]"
  42. :page-size="20"
  43. layout="total, sizes, prev, pager, next, jumper"
  44. :total="totalCount"
  45. ></el-pagination>
  46. </div>
  47. </template>
  48. <script>
  49. const tableHeaders = [
  50. "名称",
  51. "状态",
  52. "排序",
  53. "价格",
  54. "配图",
  55. "简介",
  56. "证书",
  57. "说明",
  58. "操作",
  59. ]
  60. const tableProps = [
  61. "name",
  62. "status_name",
  63. "order",
  64. "price",
  65. "img",
  66. "introduction",
  67. "content",
  68. "description",
  69. "ctrl",
  70. ]
  71. let env = 'test'
  72. export default {
  73. data() {
  74. return {
  75. // 数据总条目
  76. totalCount: 0,
  77. currentPage: 1,
  78. currentPageSize: 20,
  79. // 列表头显示内容
  80. tableHeaders,
  81. // 列表头字段
  82. tableProps,
  83. // 列表数据
  84. tableData: []
  85. }
  86. },
  87. mounted() {
  88. this.getTableData()
  89. },
  90. methods: {
  91. clickCtrl(item, index) {
  92. this.$router.push({
  93. path: '/main/cert_edit',
  94. query: {
  95. id: item.id
  96. }
  97. })
  98. },
  99. // 点击用户的 uid
  100. clickName(item) {
  101. if(env === 'test')window.open(`https://dev.test.proginn.com/cert/type/${item.id}`)
  102. else window.open(`https://www.proginn.com/cert/type/${item.id}`)
  103. },
  104. // 根据状态显示图表样式
  105. tableRowClassName({ row, rowIndex }) {
  106. let className = ""
  107. if(row.status === "1") className = "success-row"
  108. return className
  109. },
  110. // 格式化列表数据
  111. formatTableData(data) {
  112. return data.map(i => ({
  113. ...i,
  114. statusShow: i.status === "1" ? "到账" : "失败",
  115. created_atShow: new Date(Number(i.created_at) * 1000).toLocaleString(),
  116. taken_atShow: new Date(Number(i.taken_at) * 1000).toLocaleString(),
  117. ctrl: 1
  118. }))
  119. },
  120. changePageSize(pageSize) {
  121. this.currentPageSize = pageSize
  122. this.getTableData()
  123. },
  124. // 获取列表数据
  125. async getTableData(page = 1) {
  126. this.tableData = []
  127. let body = { page: this.currentPage,page_size:this.currentPageSize}
  128. const res = await this.$post("/api/admin/cert/getList", body)
  129. // console.log(res)
  130. const data = res.data
  131. env = data.current_env
  132. this.tableData = this.formatTableData(res.data.list)
  133. this.totalCount = Number(data.total)
  134. this.totalPage = data.totalPage
  135. }
  136. }
  137. };
  138. </script>
  139. <style scoped>
  140. .table {
  141. height: calc(100% - 40px);
  142. }
  143. .img {
  144. width: 100%;
  145. height: auto;
  146. }
  147. </style>