list.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="industry-list">
  3. <tables
  4. :buttonList="buttonList"
  5. :data-api="getIndustry"
  6. :delete-api="updateIndustry"
  7. :columns="columns"
  8. @create="create"
  9. @toEdit="toEdit"
  10. placeholder="输入行业名称"
  11. ref="table"
  12. />
  13. <cModal :show="modalShow" :width="526" title="新增行业" @close="modalShow=false" @submit="createIndustry">
  14. <div class="form">
  15. <Form :label-width="86">
  16. <FormItem label="行业名称">
  17. <Input size="large" v-model="form.name" />
  18. </FormItem>
  19. </Form>
  20. </div>
  21. </cModal>
  22. </div>
  23. </template>
  24. <script>
  25. import { getIndustry, createIndustry, updateIndustry } from '@/api/company'
  26. import tables from 'components/tables'
  27. import cModal from 'components/Modal'
  28. export default {
  29. data () {
  30. return {
  31. getIndustry,
  32. // 传递给tables的表格列数据
  33. buttonList: [
  34. {
  35. text: '新增',
  36. handle: 'create'
  37. }
  38. ],
  39. dataApi: getIndustry,
  40. deleteApi: getIndustry,
  41. columns: [
  42. {
  43. type: 'index',
  44. title: '序号',
  45. align: 'center',
  46. width: 80
  47. },
  48. {
  49. title: '行业名称',
  50. key: 'name',
  51. align: 'center'
  52. },
  53. {
  54. title: '状态',
  55. key: 'isValide',
  56. align: 'center',
  57. render: (h, params) => {
  58. return h('i-switch', {
  59. props: {
  60. trueValue: 1,
  61. falseValue: 0,
  62. value: params.row.isValide,
  63. // disabled: params.row.roleKey === 'admin'
  64. },
  65. on: {
  66. 'on-change': (val) => {
  67. updateIndustry(Object.assign(params.row, {isValide: val}))
  68. }
  69. }
  70. })
  71. }
  72. },
  73. {
  74. title: '创建时间',
  75. key: 'createTime',
  76. align: 'center',
  77. render: (h, params) => h('p', params.row.createTime.replace('T', ' '))
  78. },
  79. {
  80. title: '操作',
  81. slot: 'action',
  82. tools: ['edit', 'del' ],
  83. align: 'center'
  84. }
  85. ],
  86. modalShow: false,
  87. form: {
  88. name: ''
  89. }
  90. }
  91. },
  92. components: {
  93. tables,
  94. cModal
  95. },
  96. methods: {
  97. create () {
  98. this.form = {
  99. name: ''
  100. }
  101. this.modalShow = true
  102. },
  103. toEdit (item) {
  104. this.modalShow = true
  105. this.form = Object.assign({}, item)
  106. },
  107. async createIndustry () {
  108. let api = this.form.id ? updateIndustry : createIndustry
  109. let res = await api(this.form)
  110. this.$refs['table'].handleTableData()
  111. this.modalShow = false
  112. },
  113. async updateIndustry(row) {
  114. row[0].enable = 0
  115. await updateIndustry(row[0])
  116. this.$Message.success({
  117. content: '删除成功'
  118. })
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="less" scoped>
  124. .industry-list {
  125. padding: 30px;
  126. }
  127. </style>