list.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <script>
  2. import Vue from 'vue'
  3. import { getFormList, setFormStatus, deleteForm } from '@/api/form'
  4. export default Vue.extend({
  5. name: 'Index',
  6. data() {
  7. return {
  8. formList: [],
  9. current_page: 0,
  10. last_page: 1,
  11. total: 0,
  12. page_size: 20,
  13. searchWord: '',
  14. searchTimer: null,
  15. loading: false
  16. }
  17. },
  18. mounted() {
  19. this.getList()
  20. },
  21. methods: {
  22. handleCreate() {
  23. this.$router.push({ path: '/preRegister/add' })
  24. },
  25. search(event) {
  26. if (this.searchTimer) {
  27. clearTimeout(this.searchTimer)
  28. }
  29. this.searchTimer = setTimeout(() => {
  30. this.current_page = 1
  31. this.getList()
  32. }, 500)
  33. },
  34. edit(row) {
  35. if (row.is_use) {
  36. this.$notify({
  37. title: '提示',
  38. message: '此表单已经发布,无法修改',
  39. type: 'warning'
  40. })
  41. return
  42. }
  43. this.$router.push({ path: '/preRegister/edit/' + row.id })
  44. },
  45. copy(row) {
  46. this.$router.push({ path: '/preRegister/add?copy=' + row.id })
  47. },
  48. setStatus(row) {
  49. this.loading = true
  50. setFormStatus(row.id, row.status ? 0 : 1).then(res => {
  51. this.loading = false
  52. this.refresh()
  53. }).catch(err => {
  54. this.loading = false
  55. })
  56. },
  57. del(row) {
  58. if (row.is_use) {
  59. this.$notify({
  60. title: '提示',
  61. message: '此表单已经发布,无法修改',
  62. type: 'warning'
  63. })
  64. return
  65. }
  66. this.$confirm('确定删除表单"' + row.template_name + '"吗?此操作无法撤销!', '删除表单', {
  67. confirmButtonText: '确定',
  68. cancelButtonText: '取消',
  69. type: 'warning',
  70. callback: action => {
  71. if (action === 'confirm') {
  72. deleteForm(row.id).then(res => {
  73. this.loading = false
  74. this.refresh()
  75. }).catch(err => {
  76. this.loading = false
  77. })
  78. }
  79. }
  80. })
  81. },
  82. refresh() {
  83. if (this.loading || this.current_page > this.last_page) return
  84. this.loading = true
  85. getFormList(this.current_page, this.page_size, this.searchWord).then(res => {
  86. this.current_page = res.data.current_page
  87. this.last_page = res.data.last_page
  88. this.total = res.data.total
  89. this.formList = res.data.data
  90. this.loading = false
  91. })
  92. },
  93. getList() {
  94. if (this.loading || this.current_page >= this.last_page) return
  95. this.loading = true
  96. getFormList(this.current_page, this.page_size, this.searchWord).then(res => {
  97. this.current_page = res.data.current_page
  98. this.last_page = res.data.last_page
  99. this.total = res.data.total
  100. this.formList = res.data.data
  101. this.loading = false
  102. })
  103. }
  104. }
  105. })
  106. </script>
  107. <template>
  108. <div class="main-box">
  109. <div class="head">
  110. <el-input v-model="searchWord" v-permission="'preReg.search'" prefix-icon="el-icon-search" placeholder="搜索表单名称" class="input" @input="search">
  111. <el-button v-if="searchWord" slot="append" icon="el-icon-delete" @click="searchWord='';search()" />
  112. </el-input>
  113. <el-button v-permission="'preReg.creat'" icon="el-icon-plus" type="primary" @click="handleCreate">创建表单</el-button>
  114. <!-- <el-button icon="el-icon-copy-document">批量复制</el-button>-->
  115. </div>
  116. <div class="body">
  117. <el-table v-loading="loading" :data="formList" height="100%" class="table">
  118. <el-table-column
  119. :show-overflow-tooltip="true"
  120. label="表单名称"
  121. prop="template_name"
  122. width="300"
  123. />
  124. <el-table-column
  125. label="状态"
  126. width="80"
  127. >
  128. <template slot-scope="scope">
  129. <div :class="['status','type-'+scope.row.status]">
  130. {{ ['正常','禁用'][scope.row.status] }}
  131. </div>
  132. </template>
  133. </el-table-column>
  134. <el-table-column
  135. :show-overflow-tooltip="true"
  136. label="表单描述"
  137. prop="description"
  138. />
  139. <el-table-column
  140. label="最后编辑"
  141. prop="update_time"
  142. width="200"
  143. />
  144. <el-table-column
  145. label="操作"
  146. fixed="right"
  147. width="200"
  148. >
  149. <template slot-scope="scope">
  150. <span v-permission="'preReg.handelEdit'" :class="['button',scope.row.is_use?'disable':'']" @click="edit(scope.row)">编辑</span>
  151. <span v-permission="'preReg.handelCopy'" class="button" @click="copy(scope.row)">复制</span>
  152. <span v-permission="'preReg.handelDisable'" class="button" @click="setStatus(scope.row)">{{ scope.row.status?'启用':'禁用' }}</span>
  153. <span v-permission="'preReg.handelDelete'" :class="['button','del',scope.row.is_use?'disable':'']" @click="del(scope.row)">删除</span>
  154. </template>
  155. </el-table-column>
  156. </el-table>
  157. </div>
  158. <div class="foot">
  159. <el-pagination
  160. background
  161. :page-size="page_size"
  162. layout="total"
  163. :total="total"
  164. />
  165. <el-pagination
  166. v-permission="'preReg.changePage'"
  167. background
  168. :page-size="page_size"
  169. layout="prev, pager, next"
  170. :total="total"
  171. @current-change="current_page=$event;getList()"
  172. />
  173. </div>
  174. </div>
  175. </template>
  176. <style scoped lang="scss">
  177. @use '@/styles/variables.scss' as *;
  178. .main-box{
  179. height: 100%;
  180. display: grid;
  181. grid-template-rows: auto 1fr auto;
  182. grid-gap: 24px;
  183. .head{
  184. display: flex;
  185. .input{
  186. width: 50%;
  187. margin-right: auto;
  188. }
  189. }
  190. .body{
  191. position: relative;
  192. height: 100%;
  193. .table{
  194. width: 100%;
  195. height: 100%;
  196. position: absolute;
  197. top: 0;
  198. left: 0;
  199. .button{
  200. cursor: pointer;
  201. padding: 0 5px;
  202. color: $menuActiveText;
  203. &.del{
  204. color: #DC2626;
  205. }
  206. &.disable{
  207. cursor: not-allowed;
  208. color: grey;
  209. }
  210. }
  211. .status{
  212. padding: 0 12px;
  213. border-radius: 32px;
  214. width: fit-content;
  215. &.type-0{
  216. background: #DCFCE7;
  217. color: #166534;
  218. }
  219. &.type-1{
  220. background: #FEE2E2;
  221. color: #991B1B;
  222. }
  223. }
  224. }
  225. }
  226. .foot{
  227. display: flex;
  228. justify-content: space-between;
  229. }
  230. }
  231. </style>