commendList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="app-container calendar-list-container">
  3. <!-- 查询和其他操作 -->
  4. <div class="filter-container">
  5. <el-select v-model="listQuery.type" clearable placeholder="表彰类型" style="top: -4px; width: 200px">
  6. <el-option :key="item.type" v-for="item in typeList" :label="item.name" :value="item.type">
  7. </el-option>
  8. </el-select>
  9. <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查找</el-button>
  10. <el-button class="filter-item" type="primary" @click="handleCreate" icon="el-icon-edit">添加</el-button>
  11. </div>
  12. <!-- 查询结果 -->
  13. <el-table size="small" :data="list" v-loading="listLoading"
  14. element-loading-text="正在查询中。。。" border fit highlight-current-row>
  15. <el-table-column type="index" label="序号" header-align="center" align="center">
  16. </el-table-column>
  17. <el-table-column align="center" min-width="100px" label="标题" prop="title">
  18. <template slot-scope="scope">
  19. <router-link :to="{name: 'commendDataList', params: { id: scope.row.commendId }}">
  20. <div style="color: #337ab7;cursor: pointer;">{{ scope.row.title }}</div>
  21. </router-link>
  22. </template>
  23. </el-table-column>
  24. <el-table-column align="center" min-width="80px" label="类型" prop="typeName">
  25. </el-table-column>
  26. <el-table-column align="center" min-width="80px" label="日期" prop="createTime">
  27. </el-table-column>
  28. <el-table-column align="center" label="操作" width="300px" class-name="small-padding fixed-width">
  29. <template slot-scope="scope">
  30. <el-button :disabled="scope.row.status == 1?true:false" type="primary" size="small" @click="handleUpdate(scope.row, false)">编辑</el-button>
  31. <el-button :disabled="scope.row.status == 1?true:false" v-if="scope.row.status == 0" type="success" size="small"
  32. @click="changeState(scope.row.commendId, 1)">开启</el-button>
  33. <el-button :disabled="scope.row.status == 1?true:false" v-if="scope.row.status == 1" type="warning" size="small"
  34. @click="changeState(scope.row.commendId, 0)">关闭</el-button>
  35. <el-button :disabled="scope.row.status == 1?true:false" type="danger" size="mini" @click="handleDelete(scope.row.commendId, -1)">删除</el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <!-- 分页 -->
  40. <div class="pagination-container">
  41. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  42. :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
  43. layout="total, sizes, prev, pager, next, jumper" :total="total">
  44. </el-pagination>
  45. </div>
  46. <!-- 添加或修改对话框 -->
  47. <el-dialog :close-on-click-modal="false" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="40%">
  48. <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="80px"
  49. style="width: 700px; margin-left: 50px">
  50. <el-form-item label="标题" prop="title">
  51. <el-input style="width: 350px" v-model="dataForm.title"></el-input>
  52. </el-form-item>
  53. <el-form-item label="类型" prop="type">
  54. <el-select v-model="dataForm.type" filterable placeholder="请选择" style="width: 350px">
  55. <el-option :key="item.type" v-for="item in typeList" :label="item.name" :value="item.type">
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. </el-form>
  60. <div slot="footer" class="dialog-footer">
  61. <el-button @click="dialogFormVisible = false">取消</el-button>
  62. <el-button v-if="dialogStatus == 'create'" type="primary" @click="createData">确定</el-button>
  63. <el-button v-else type="primary" @click="updateData">确定</el-button>
  64. </div>
  65. </el-dialog>
  66. </div>
  67. </template>
  68. <style>
  69. .demo-table-expand {
  70. font-size: 0;
  71. }
  72. .demo-table-expand label {
  73. width: 200px;
  74. color: #99a9bf;
  75. }
  76. .demo-table-expand .el-form-item {
  77. margin-right: 0;
  78. margin-bottom: 0;
  79. }
  80. </style>
  81. <script>
  82. import {
  83. createItem,
  84. updateItem,
  85. list,
  86. state,
  87. types,
  88. } from "@/api/commendManage";
  89. import waves from "@/directive/waves"; // 水波纹指令
  90. import Tinymce from "@/components/Tinymce";
  91. export default {
  92. components: { Tinymce },
  93. directives: { waves },
  94. data() {
  95. return {
  96. typeList: [],
  97. list: [
  98. ],
  99. total: 0,
  100. listLoading: false,
  101. listQuery: {
  102. page: 1,
  103. limit: 10,
  104. type: "",
  105. },
  106. dataForm: {
  107. type: undefined,
  108. title: undefined,
  109. },
  110. dialogFormVisible: false,
  111. dialogStatus: "",
  112. textMap: {
  113. update: "编辑",
  114. create: "创建",
  115. },
  116. rules: {
  117. title: [{ required: true, message: "标题不能为空", trigger: "blur" }],
  118. type: [{ required: true, message: "请选择类型", trigger: "blur" }],
  119. },
  120. };
  121. },
  122. created() {
  123. this.getTypeList();
  124. this.getList();
  125. },
  126. methods: {
  127. getTypeList(){
  128. types().then(response => {
  129. this.typeList = response.data.data;
  130. })
  131. },
  132. changeState(commendId, index) {
  133. state({ commendId: commendId, status: index }).then(response => {
  134. this.$notify({
  135. title: '成功',
  136. message: '状态修改成功',
  137. type: 'success',
  138. duration: 2000
  139. })
  140. this.getList()
  141. })
  142. },
  143. resetForm() {
  144. this.dataForm = {
  145. type: undefined,
  146. title: undefined,
  147. };
  148. },
  149. handleCreate() {
  150. this.resetForm();
  151. this.dialogFormVisible = true;
  152. this.dialogStatus = "create";
  153. this.$nextTick(() => {
  154. this.$refs["dataForm"].clearValidate();
  155. });
  156. },
  157. createData() {
  158. this.$refs["dataForm"].validate((valid) => {
  159. if (valid) {
  160. createItem(this.dataForm)
  161. .then(() => {
  162. this.getList();
  163. this.dialogFormVisible = false;
  164. this.$notify({
  165. title: "成功",
  166. message: "创建成功",
  167. type: "success",
  168. duration: 2000,
  169. });
  170. this.reload();
  171. })
  172. .catch(() => { });
  173. }
  174. });
  175. },
  176. getList() {
  177. this.listLoading = true;
  178. list(this.listQuery)
  179. .then((response) => {
  180. this.list = response.data.data.items;
  181. this.total = response.data.data.total;
  182. this.listLoading = false;
  183. })
  184. .catch(() => {
  185. this.list = [];
  186. this.total = 0;
  187. this.listLoading = false;
  188. });
  189. },
  190. handleFilter() {
  191. this.listQuery.page = 1;
  192. this.getList();
  193. },
  194. handleSizeChange(val) {
  195. this.listQuery.limit = val;
  196. this.getList();
  197. },
  198. handleCurrentChange(val) {
  199. this.listQuery.page = val;
  200. this.getList();
  201. },
  202. handleUpdate(row) {
  203. this.dataForm = Object.assign({}, row);
  204. this.dialogStatus = "update";
  205. this.dialogFormVisible = true;
  206. this.$nextTick(() => {
  207. this.$refs["dataForm"].clearValidate();
  208. });
  209. },
  210. updateData() {
  211. this.$refs["dataForm"].validate((valid) => {
  212. if (valid) {
  213. updateItem(this.dataForm).then(() => {
  214. this.dialogFormVisible = false;
  215. this.$notify({
  216. title: "成功",
  217. message: "更新成功",
  218. type: "success",
  219. duration: 2000,
  220. });
  221. this.getList();
  222. });
  223. }
  224. });
  225. },
  226. handleDelete(commendId, status) {
  227. this.$confirm("确认删除吗?", "提示", {
  228. confirmButtonText: "确定",
  229. cancelButtonText: "取消",
  230. type: "warning",
  231. })
  232. .then(() => {
  233. state({commendId:commendId,status:status}).then((response) => {
  234. this.$notify({
  235. title: "成功",
  236. message: "删除成功",
  237. type: "success",
  238. duration: 2000,
  239. });
  240. this.getList();
  241. });
  242. })
  243. .catch(() => { });
  244. },
  245. },
  246. };
  247. </script>
  248. <style>
  249. .ad-avatar-uploader .el-upload {
  250. border: 1px dashed #d9d9d9;
  251. border-radius: 6px;
  252. cursor: pointer;
  253. position: relative;
  254. overflow: hidden;
  255. }
  256. .ad-avatar-uploader .el-upload:hover {
  257. border-color: #409eff;
  258. }
  259. .ad-avatar-uploader-icon {
  260. font-size: 28px;
  261. color: #8c939d;
  262. width: 178px;
  263. height: 178px;
  264. line-height: 178px;
  265. text-align: center;
  266. }
  267. .ad-avatar {
  268. display: block;
  269. }
  270. </style>