dataList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="data-list">
  3. <el-table
  4. :data="dataList"
  5. style="width: 100%"
  6. header-row-class-name="headerBg"
  7. empty-text="没有文档信息"
  8. >
  9. <el-table-column prop="id" label="ID" align="center" width="80" />
  10. <el-table-column
  11. prop="title"
  12. label="文档名称"
  13. align="left"
  14. min-width="180"
  15. />
  16. <el-table-column
  17. prop="user_name"
  18. label="创建人"
  19. align="center"
  20. width="150"
  21. />
  22. <el-table-column
  23. prop="category.name"
  24. label="所属分类"
  25. align="center"
  26. width="150"
  27. />
  28. <el-table-column
  29. prop="createTime"
  30. label="创建时间"
  31. align="center"
  32. width="150"
  33. />
  34. <el-table-column
  35. prop="status"
  36. label="文档状态"
  37. align="center"
  38. width="150"
  39. >
  40. <template #default="scope">
  41. <div v-if="scope.row.status == 5">启用</div>
  42. <div v-if="scope.row.status == 6">停用</div>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="操作" align="center" :width="editWidth()">
  46. <template #default="scope">
  47. <div class="btns">
  48. <el-button
  49. type="primary"
  50. size="small"
  51. v-if="allowEdit"
  52. @click="btnEdit(scope.row.id)"
  53. ><svg-icon icon-class="edit" />编辑</el-button
  54. >
  55. <el-button
  56. type="danger"
  57. size="small"
  58. v-if="allowDelete"
  59. @click="btnDelete(scope.row.id)"
  60. ><svg-icon icon-class="delete" />删除</el-button
  61. >
  62. </div>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <div class="page-info">
  67. <el-pagination
  68. :currentPage="queryForm.page"
  69. :page-size="queryForm.pageSize"
  70. :total="recordCount"
  71. :page-count="pageTotal"
  72. background
  73. layout="prev, pager, next"
  74. @current-change="ChangePage"
  75. >
  76. </el-pagination>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import { searchDocument, deleteDocument } from "@/api/document";
  82. export default {
  83. props: {
  84. queryForm: {
  85. type: Object,
  86. default: () => {
  87. return {
  88. page: 1,
  89. pageSize: 10,
  90. title: "",
  91. category_id: "",
  92. status: "",
  93. };
  94. },
  95. },
  96. allowEdit: {
  97. type: Boolean,
  98. default: false,
  99. },
  100. allowDelete: {
  101. type: Boolean,
  102. default: false,
  103. },
  104. },
  105. watch: {
  106. queryForm: {
  107. handler: function (val) {
  108. this.search();
  109. },
  110. // immediate: true,//立即执行
  111. deep: true,
  112. },
  113. },
  114. data() {
  115. return {
  116. dialogVisible: false, //控制产品审核
  117. currentDataId: 0,
  118. recordCount: 0,
  119. pageTotal: 1,
  120. dataList: [],
  121. currentData: {},
  122. };
  123. },
  124. mounted() {
  125. this.search();
  126. },
  127. methods: {
  128. editWidth() {
  129. if (this.allowDelete && this.allowEdit) {
  130. return 200;
  131. }
  132. if (this.allowDelete || this.allowEdit) {
  133. return 120;
  134. }
  135. return 100;
  136. },
  137. onFocusVal(e) {
  138. let _this = this;
  139. _this.currentDataId = e.target.dataset.id;
  140. },
  141. onChangeVal(e) {
  142. let _this = this;
  143. let par = {
  144. id: _this.currentDataId,
  145. val: e,
  146. };
  147. },
  148. btnDelete(e) {
  149. let _this = this;
  150. let par = {
  151. id: e,
  152. };
  153. _this
  154. .$confirm("您是否确认删除该记录?", "提示", {
  155. confirmButtonText: "确认",
  156. cancelButtonText: "取消",
  157. type: "warning",
  158. })
  159. .then((res) => {
  160. // console.log("AAA")
  161. deleteDocument(par).then((res) => {
  162. _this.search();
  163. });
  164. })
  165. .catch(() => {});
  166. },
  167. searchData() {
  168. let _this = this;
  169. _this.dialogVisible = false;
  170. _this.search();
  171. },
  172. //编辑
  173. btnEdit(e) {
  174. let _this = this;
  175. let a = document.createElement("a");
  176. a.href = "#/document/create?articleId=" + e; // 使用 hash
  177. a.target = "_blank";
  178. a.click();
  179. // _this.$router.push({path:"/document/create",query:{articleId:e}})
  180. },
  181. handleClose() {
  182. let _this = this;
  183. _this.currentData = {};
  184. _this.dialogVisible = false;
  185. },
  186. //搜索
  187. search() {
  188. let _this = this;
  189. searchDocument(_this.queryForm).then((res) => {
  190. if (!res) return;
  191. /* res.data.dataList.filter(el => el.is_template == 0)
  192. console.log(res.data.dataList); */
  193. _this.dataList = res.data.dataList.filter(el => el.is_template == 0);
  194. _this.recordCount = res.data.totalRecord;
  195. _this.pageTotal = res.data.pageTotal;
  196. });
  197. },
  198. //修改分页
  199. ChangePage(e) {
  200. let _this = this;
  201. _this.queryForm.page = e;
  202. _this.search();
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="scss">
  208. @import "./dataList.scss";
  209. </style>