cate-index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <style>
  2. .el-table th>.cell {
  3. color: #333;
  4. font-weight: bold;
  5. font-size: 14px;
  6. }
  7. .table1 .el-table__footer-wrapper,
  8. .table1 .el-table__header-wrapper {
  9. border-bottom: 1.4px solid #D6D6D6;
  10. }
  11. </style>
  12. <div id="app">
  13. <div class="table-body" style="min-width: 1000px;">
  14. <div slot="header" class="clearfix" style="height: 20px;">
  15. <span>定金预售分类</span>
  16. <div style="float: right; margin: -5px 0">
  17. <el-button type="primary" size="small" @click="handleEdit(0)">新增</el-button>
  18. </div>
  19. </div>
  20. <div slot="header" class="clearfix" style="margin-top: 20px;">
  21. </div>
  22. <template>
  23. <el-table :data="list" stripe style="width: 100%" v-loading="listLoading" class="table1">
  24. <el-table-column prop="id" label="编号" width="150" align="center"></el-table-column>
  25. <el-table-column prop="name" label="名称" align="center"></el-table-column>
  26. <el-table-column prop="status" label="状态" width="150" >
  27. <template slot-scope="scope">
  28. <el-tag v-if="scope.row.status == 0" size="small" type="danger" @click="updateStatus(scope.row.id,1)">禁用</el-tag>
  29. <el-tag v-if="scope.row.status == 1" size="small" type="success" @click="updateStatus(scope.row.id,0)">启用</el-tag>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="添加时间" width="300" align="center">
  33. <template slot-scope="scope">
  34. <span> {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="操作" width="300" align="center">
  38. <template slot-scope="scope">
  39. <el-button @click="handleEdit(scope.row.id)" type="text" size="small">编辑</el-button>
  40. <el-button @click="updateStatus(scope.row.id,-1)" type="text" size="small">删除</el-button>
  41. </template>
  42. </el-table-column>
  43. </el-table>
  44. <div flex="main:right cross:center" style="margin-top: 20px;">
  45. <el-pagination v-if="pagination" :page-size="pagination.defaultPageSize"
  46. style="display: inline-block;float: right;" background @current-change="pageChange"
  47. layout="prev, pager, next" :total="pagination.totalCount">
  48. </el-pagination>
  49. </div>
  50. </template>
  51. </div>
  52. <el-dialog :title="form.id==0 ? '新增' : '修改'" :visible.sync="dialogFormVisible" @close="handleClose()">
  53. <el-form :model="form" :rules="rules" ref="form" >
  54. <el-form-item label="名称" :label-width="formLabelWidth" prop="name">
  55. <el-input v-model="form.name" autocomplete="off"></el-input>
  56. </el-form-item>
  57. </el-form>
  58. <div slot="footer" class="dialog-footer">
  59. <el-button @click="dialogFormVisible = false">取 消</el-button>
  60. <el-button type="primary" @click="postEdit('form')">确 定</el-button>
  61. </div>
  62. </el-dialog>
  63. </div>
  64. <script>
  65. const app = new Vue({
  66. el: '#app',
  67. data() {
  68. return {
  69. listLoading: false,
  70. dialogFormVisible: false,
  71. form: {
  72. id: 0,
  73. name: '',
  74. },
  75. formLabelWidth: '120px',
  76. rules: {
  77. name: [{
  78. required: true,
  79. message: '请输入名称',
  80. trigger: 'blur'
  81. },
  82. ],
  83. },
  84. list: [],
  85. pagination: {
  86. total: 0
  87. },
  88. LoadDataType: -1, //默认显示全部数据
  89. search: {
  90. page: 1,
  91. },
  92. }
  93. },
  94. methods: {
  95. pageChange(page) {
  96. this.search.page = page;
  97. this.loadData();
  98. },
  99. loadData() {
  100. this.listLoading = true;
  101. let params = {
  102. r: 'deposit-presale/default/cate-index'
  103. };
  104. // params = Object.assign(params, this.search);
  105. request({
  106. params: params,
  107. method: 'get',
  108. }).then(e => {
  109. let res = e.data;
  110. this.listLoading = false;
  111. if (res.code === 0) {
  112. this.list = res.data.list;
  113. this.pagination = res.data.pagination;
  114. } else {
  115. this.$message.error(res.msg);
  116. }
  117. }).catch(e => {});
  118. },
  119. handleEdit(id) {
  120. this.dialogFormVisible = true;
  121. if(id!=0){
  122. this.$request({
  123. params: {
  124. r:'deposit-presale/default/cate-edit',
  125. id:id,
  126. },
  127. }).then(e => {
  128. if (e.data.code == 0) {
  129. this.form.id = e.data.data.id;
  130. this.form.name = e.data.data.name;
  131. }
  132. }).catch(e => {
  133. });
  134. }
  135. },
  136. postEdit(formName){
  137. this.$refs[formName].validate((valid) => {
  138. if(valid){
  139. this.$request({
  140. method:"post",
  141. params: {
  142. r:'deposit-presale/default/cate-edit',
  143. },
  144. data:this.form
  145. }).then(e => {
  146. if(e.data.code==0){
  147. this.dialogFormVisible = false;
  148. this.$message({
  149. message: e.data.msg,
  150. type: 'success'
  151. });
  152. this.loadData();
  153. }else{
  154. this.$message.error(e.data.msg);
  155. }
  156. }).catch(e => {
  157. });
  158. }
  159. });
  160. },
  161. updateStatus(id,status){
  162. this.$request({
  163. method:"post",
  164. params: {
  165. r:'deposit-presale/default/cate-edit',
  166. },
  167. data:{
  168. id:id,
  169. status:status
  170. }
  171. }).then(e => {
  172. if(e.data.code==0){
  173. this.$message({
  174. message: e.data.msg,
  175. type: 'success'
  176. });
  177. this.loadData();
  178. }else{
  179. this.$message.error(e.data.msg);
  180. }
  181. }).catch(e => {
  182. });
  183. },
  184. handleClose(){
  185. this.form = {
  186. id: 0,
  187. name: '',
  188. };
  189. }
  190. },
  191. mounted() {
  192. this.LoadDataType = -1;
  193. this.loadData();
  194. }
  195. })
  196. </script>