ContentCategory2.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div>
  3. <div class="car_series">
  4. <div class="count">
  5. <button @click="showModal">新增类别</button>
  6. <Count :sum="sum"></Count>
  7. </div>
  8. <div class="table">
  9. <Table
  10. :tableData="tableData"
  11. @edit="edit"
  12. @delet_data="deleteData"
  13. :pageSize="sum"
  14. ></Table>
  15. </div>
  16. <div class="page" v-if="sum > 0">
  17. <Tablepage
  18. :totalPage="totalPage"
  19. :currentPage="currentPage"
  20. @change_page="changePage"
  21. @jump_page="jumpPage"
  22. ></Tablepage>
  23. </div>
  24. <div class="modal" v-if="modalFlag">
  25. <Modal
  26. :modalFlag="modalFlag"
  27. @submit="submit"
  28. @hide_modal="showModal"
  29. ></Modal>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import Count from "../../components/Count";
  36. import Tablepage from "../../components/TablePage";
  37. import Table from "./components/ContentCategory2/Table";
  38. import Modal from "./components/ContentCategory2/Modal";
  39. export default {
  40. components: {
  41. Count,
  42. Table,
  43. Tablepage,
  44. Modal,
  45. },
  46. data() {
  47. return {
  48. sum: 0, // 一共有多少条数据
  49. pageSize: 20, // 每页展示的数据
  50. currentPage: 1,
  51. tableData: [],
  52. modalFlag: false, // 控制模态框展示
  53. dictList: [],
  54. };
  55. },
  56. computed: {
  57. // 表格总页数
  58. totalPage() {
  59. return Math.ceil(this.sum / this.pageSize);
  60. },
  61. // 获取路由参数
  62. queryTag() {
  63. console.log(111, this.$route.query);
  64. return this.$route.query && this.$route.query.tag ? 0 : 1;
  65. },
  66. },
  67. methods: {
  68. // 获取某一页面的数据,展示在表格
  69. changePage: function (page) {
  70. this.currentPage = page;
  71. this.getDateList(this.currentPage, this.pageSize);
  72. },
  73. // 点击上一页,下一页,首页,尾页
  74. jumpPage: function (item) {
  75. switch (item) {
  76. case 1:
  77. this.currentPage = 1;
  78. break;
  79. case 2:
  80. this.currentPage = this.currentPage - 1;
  81. break;
  82. case 3:
  83. this.currentPage = this.currentPage + 1;
  84. break;
  85. case 4:
  86. this.currentPage = this.totalPage;
  87. break;
  88. }
  89. this.getDateList(this.currentPage, this.pageSize);
  90. },
  91. // 展示、隐藏模态框
  92. showModal: function () {
  93. this.modalFlag = !this.modalFlag;
  94. },
  95. // 点击编辑
  96. edit(index, newName) {
  97. this.updataDict(newName, index).then(() => {
  98. this.getDateList(this.currentPage, this.pageSize);
  99. });
  100. },
  101. // 点击删除
  102. deleteData(index) {
  103. this.deleteDict(index).then(() => {
  104. this.currentPage = Math.ceil((this.sum - 1) / this.pageSize);
  105. this.getDateList(this.currentPage, this.pageSize);
  106. });
  107. },
  108. // 新增分类模态框 保存
  109. submit: function (name) {
  110. this.addList(name).then(() => {
  111. this.currentPage = Math.ceil((this.sum + 1) / this.pageSize);
  112. this.getDateList(this.currentPage, this.pageSize);
  113. });
  114. this.modalFlag = false;
  115. },
  116. // 获取内容分类、媒体平台、常用参数接口的标识,再调接口时需要用到
  117. selectSysDataDictList: function () {
  118. return new Promise((resolve, reject) => {
  119. this.$http({
  120. method: "post",
  121. url: "/sys/dataDict/selectSysDataDictList",
  122. data: {},
  123. })
  124. .then((res) => {
  125. if (res.data && res.data.code === 200) {
  126. this.dictList = res.data.data;
  127. resolve();
  128. } else {
  129. console.log(res);
  130. reject();
  131. }
  132. })
  133. .catch((err) => {
  134. console.log(err);
  135. reject();
  136. });
  137. });
  138. },
  139. // 获取列表数据 接口
  140. getDateList: function (page, rows) {
  141. this.$http({
  142. method: "post",
  143. url: "/sys/dataDict/selectSysDataDictPage",
  144. data: {
  145. dictCode: this.dictList[2]["dictCode"],
  146. parentId: this.dictList[2]["id"],
  147. page,
  148. rows,
  149. },
  150. })
  151. .then((res) => {
  152. if (res.data && res.data.code === 200) {
  153. this.tableData = res.data.data;
  154. this.sum = res.data.count;
  155. console.log(res);
  156. } else {
  157. console.log(res);
  158. }
  159. })
  160. .catch((err) => {
  161. console.log(err);
  162. });
  163. },
  164. // 新增 接口
  165. addList: function (name) {
  166. return new Promise((resolve, reject) => {
  167. this.$http({
  168. url: "/sys/dataDict/addSysDataDictInfo",
  169. method: "post",
  170. data: {
  171. dictName: name,
  172. parentId: this.dictList[2]["id"],
  173. dictCode: this.dictList[2]["dictCode"],
  174. },
  175. })
  176. .then((res) => {
  177. if (res.data && res.data.code === 200) {
  178. console.log(res);
  179. resolve();
  180. } else {
  181. alert(res.data.message);
  182. console.log(res);
  183. }
  184. })
  185. .catch((err) => {
  186. alert("新增失败,请重试");
  187. reject(err);
  188. });
  189. });
  190. },
  191. // 编辑 接口
  192. updataDict: function (newName, index) {
  193. return new Promise((resolve, reject) => {
  194. this.$http({
  195. url: "/sys/dataDict/updateSysDataDictInfo",
  196. method: "post",
  197. data: {
  198. dictName: newName,
  199. id: this.tableData[index]["id"],
  200. parentId: this.dictList[2]["id"],
  201. dictCode: this.dictList[2]["dictCode"],
  202. },
  203. })
  204. .then((res) => {
  205. if (res.data && res.data.code === 200) {
  206. console.log(res);
  207. resolve();
  208. } else {
  209. alert("编辑失败,请重试");
  210. console.log(res);
  211. }
  212. })
  213. .catch((err) => {
  214. alert("编辑失败,请重试");
  215. reject(err);
  216. });
  217. });
  218. },
  219. // 删除 接口
  220. deleteDict: function (index) {
  221. return new Promise((resolve, reject) => {
  222. this.$http({
  223. url: "/sys/dataDict/deleteSysDataDictInfo",
  224. method: "post",
  225. data: {
  226. id: this.tableData[index]["id"],
  227. parentId: this.dictList[2]["id"],
  228. dictCode: this.dictList[2]["dictCode"],
  229. },
  230. })
  231. .then((res) => {
  232. if (res.data && res.data.code === 200) {
  233. console.log(res);
  234. resolve();
  235. } else {
  236. alert("删除失败,请重试");
  237. console.log(res);
  238. }
  239. })
  240. .catch((err) => {
  241. alert("删除失败,请重试");
  242. reject(err);
  243. });
  244. });
  245. },
  246. },
  247. created() {
  248. this.selectSysDataDictList()
  249. .then(() => {
  250. this.getDateList(1, this.pageSize);
  251. console.log(this.dictList);
  252. })
  253. .catch((err) => {
  254. console.log(err);
  255. });
  256. },
  257. };
  258. </script>
  259. <style scoped lang="less">
  260. .car_series {
  261. .count {
  262. height: 40px;
  263. width: 100%;
  264. display: flex;
  265. justify-content: space-between;
  266. align-items: center;
  267. button {
  268. width: 86px;
  269. height: 30px;
  270. position: relative;
  271. bottom: -5px;
  272. margin: 0;
  273. border-radius: 2px;
  274. }
  275. }
  276. }
  277. </style>