cate-index.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <com-list-page :crumbs="crumbs" id="application">
  2. <com-list-table
  3. ref="table"
  4. :api="'bargain/default/cate-index'"
  5. >
  6. <el-table-column prop="id" label="编号" width="150" align="center"></el-table-column>
  7. <el-table-column prop="name" label="名称" align="center"></el-table-column>
  8. <el-table-column prop="status" label="状态" width="150">
  9. <template slot-scope="scope">
  10. <el-tag v-if="scope.row.status == 0" size="small" type="danger" @click="updateStatus(scope.row.id,1)">禁用</el-tag>
  11. <el-tag v-if="scope.row.status == 1" size="small" type="success" @click="updateStatus(scope.row.id,0)">启用</el-tag>
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="添加时间" width="300" align="center">
  15. <template slot-scope="scope">
  16. <span> {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</span>
  17. </template>
  18. </el-table-column>
  19. <el-table-column label="操作" width="300" align="right">
  20. <template slot-scope="scope">
  21. <el-button @click="handleEdit(scope.row.id)" type="text" :loading="btnLoad" size="small">编辑</el-button>
  22. <el-button @click="updateStatus(scope.row.id,-1)" type="text" size="small">删除</el-button>
  23. </template>
  24. </el-table-column>
  25. <template slot="header-left">
  26. <el-button
  27. type="primary"
  28. size="mini"
  29. icon="el-icon-plus"
  30. @click="handleEdit(0)">新增分类</el-button>
  31. </template>
  32. </com-list-table>
  33. <el-dialog :title="form.id==0 ? '新增' : '修改'" :visible.sync="dialogFormVisible" @close="handleClose()" width="20%">
  34. <el-form :model="form" :rules="rules" ref="form">
  35. <el-form-item label="名称" :label-width="formLabelWidth" prop="name">
  36. <el-input v-model="form.name" autocomplete="off"></el-input>
  37. </el-form-item>
  38. </el-form>
  39. <div slot="footer" class="dialog-footer">
  40. <el-button @click="dialogFormVisible = false">取 消</el-button>
  41. <el-button type="primary" @click="postEdit('form')">确 定</el-button>
  42. </div>
  43. </el-dialog>
  44. </com-list-page>
  45. <script>
  46. const application = new Vue({
  47. el: '#application',
  48. data: {
  49. crumbs: [{
  50. title: '砍价',
  51. },
  52. {
  53. title: '砍价分类',
  54. }
  55. ],
  56. dialogFormVisible: false,
  57. btnLoad: false,
  58. form: {
  59. id: 0,
  60. name: '',
  61. },
  62. formLabelWidth: '80px',
  63. rules: {
  64. name: [
  65. {
  66. required: true,
  67. message: '请输入名称',
  68. trigger: 'blur'
  69. },
  70. ],
  71. },
  72. },
  73. methods: {
  74. handleEdit(id) {
  75. if (id != 0) {
  76. this.btnLoad = true
  77. this.$request({
  78. params: {
  79. r: 'bargain/default/cate-edit',
  80. id: id,
  81. },
  82. }).then(e => {
  83. if (e.data.code == 0) {
  84. this.form.id = e.data.data.id;
  85. this.form.name = e.data.data.name;
  86. this.btnLoad = false
  87. this.dialogFormVisible = true;
  88. }
  89. }).catch(e => {});
  90. } else {
  91. this.dialogFormVisible = true;
  92. }
  93. },
  94. postEdit(formName) {
  95. this.$refs[formName].validate((valid) => {
  96. if (valid) {
  97. this.$request({
  98. method: "post",
  99. params: {
  100. r: 'bargain/default/cate-edit',
  101. },
  102. data: this.form
  103. }).then(e => {
  104. if (e.data.code == 0) {
  105. this.dialogFormVisible = false;
  106. this.$message({
  107. message: e.data.msg,
  108. type: 'success'
  109. });
  110. this.$nextTick(function() {
  111. this.$refs.table.handleSearch();
  112. })
  113. } else {
  114. this.$message.error(e.data.msg);
  115. }
  116. }).catch(e => {});
  117. }
  118. });
  119. },
  120. updateStatus(id, status) {
  121. this.$request({
  122. method: "post",
  123. params: {
  124. r: 'bargain/default/cate-edit',
  125. },
  126. data: {
  127. id: id,
  128. status: status
  129. }
  130. }).then(e => {
  131. if (e.data.code == 0) {
  132. this.$message({
  133. message: e.data.msg,
  134. type: 'success'
  135. });
  136. this.$nextTick(function() {
  137. this.$refs.table.handleSearch();
  138. })
  139. } else {
  140. this.$message.error(e.data.msg);
  141. }
  142. }).catch(e => {});
  143. },
  144. handleClose() {
  145. this.form = {
  146. id: 0,
  147. name: '',
  148. };
  149. },
  150. }
  151. })
  152. </script>
  153. <style lang="scss" scoped>
  154. .el-form-item {
  155. margin-bottom: 0;
  156. }
  157. </style>