ContentCategory2.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 if ((res.data && res.data.code === 400 && res.data.message === '不可重复添加')) {
  181. alert('不可重复添加');
  182. } else {
  183. alert("新增失败,请重试");
  184. console.log(res);
  185. }
  186. })
  187. .catch((err) => {
  188. alert("新增失败,请重试");
  189. reject(err);
  190. });
  191. });
  192. },
  193. // 编辑 接口
  194. updataDict: function (newName, index) {
  195. return new Promise((resolve, reject) => {
  196. this.$http({
  197. url: "/sys/dataDict/updateSysDataDictInfo",
  198. method: "post",
  199. data: {
  200. dictName: newName,
  201. id: this.tableData[index]["id"],
  202. parentId: this.dictList[2]["id"],
  203. dictCode: this.dictList[2]["dictCode"],
  204. },
  205. })
  206. .then((res) => {
  207. if (res.data && res.data.code === 200) {
  208. console.log(res);
  209. resolve();
  210. } else {
  211. alert("编辑失败,请重试");
  212. console.log(res);
  213. }
  214. })
  215. .catch((err) => {
  216. alert("编辑失败,请重试");
  217. reject(err);
  218. });
  219. });
  220. },
  221. // 删除 接口
  222. deleteDict: function (index) {
  223. return new Promise((resolve, reject) => {
  224. this.$http({
  225. url: "/sys/dataDict/deleteSysDataDictInfo",
  226. method: "post",
  227. data: {
  228. id: this.tableData[index]["id"],
  229. parentId: this.dictList[2]["id"],
  230. dictCode: this.dictList[2]["dictCode"],
  231. },
  232. })
  233. .then((res) => {
  234. if (res.data && res.data.code === 200) {
  235. console.log(res);
  236. resolve();
  237. } else {
  238. alert("删除失败,请重试");
  239. console.log(res);
  240. }
  241. })
  242. .catch((err) => {
  243. alert("删除失败,请重试");
  244. reject(err);
  245. });
  246. });
  247. },
  248. },
  249. created() {
  250. this.selectSysDataDictList()
  251. .then(() => {
  252. this.getDateList(1, this.pageSize);
  253. console.log(this.dictList);
  254. })
  255. .catch((err) => {
  256. console.log(err);
  257. });
  258. },
  259. };
  260. </script>
  261. <style scoped lang="less">
  262. .car_series {
  263. .count {
  264. height: 40px;
  265. width: 100%;
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: center;
  269. button {
  270. width: 86px;
  271. height: 30px;
  272. position: relative;
  273. bottom: -5px;
  274. margin: 0;
  275. border-radius: 2px;
  276. }
  277. }
  278. }
  279. </style>