ContentCategory1.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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/ContentCategory1/Table";
  38. import Modal from "./components/ContentCategory1/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. methods: {
  63. // 获取某一页面的数据,展示在表格
  64. changePage: function (page) {
  65. this.currentPage = page;
  66. this.getDateList(this.currentPage, this.pageSize);
  67. },
  68. // 点击上一页,下一页,首页,尾页
  69. jumpPage: function (item) {
  70. switch (item) {
  71. case 1:
  72. this.currentPage = 1;
  73. break;
  74. case 2:
  75. this.currentPage = this.currentPage - 1;
  76. break;
  77. case 3:
  78. this.currentPage = this.currentPage + 1;
  79. break;
  80. case 4:
  81. this.currentPage = this.totalPage;
  82. break;
  83. }
  84. this.getDateList(this.currentPage, this.pageSize);
  85. },
  86. // 展示、隐藏模态框
  87. showModal: function () {
  88. this.modalFlag = !this.modalFlag;
  89. },
  90. // 点击编辑
  91. edit(index, newName) {
  92. this.updataDict(newName, index).then(() => {
  93. this.getDateList(this.currentPage, this.pageSize);
  94. });
  95. },
  96. // 点击删除
  97. deleteData(index) {
  98. this.deleteDict(index).then(() => {
  99. this.currentPage = Math.ceil((this.sum - 1) / this.pageSize);
  100. this.getDateList(this.currentPage, this.pageSize);
  101. });
  102. },
  103. // 新增车型模态框 保存
  104. submit: function (name) {
  105. this.addList(name).then(() => {
  106. this.currentPage = Math.ceil((this.sum + 1) / this.pageSize);
  107. this.getDateList(this.currentPage, this.pageSize);
  108. });
  109. this.modalFlag = false;
  110. },
  111. // 获取内容分类、媒体平台、常用参数接口的标识,再调接口时需要用到
  112. selectSysDataDictList: function () {
  113. return new Promise((resolve, reject) => {
  114. this.$http({
  115. method: "post",
  116. url: "/sys/dataDict/selectSysDataDictList",
  117. data: {},
  118. })
  119. .then((res) => {
  120. if (res.data && res.data.code === 200) {
  121. this.dictList = res.data.data;
  122. resolve();
  123. } else {
  124. console.log(res);
  125. reject();
  126. }
  127. })
  128. .catch((err) => {
  129. console.log(err);
  130. reject();
  131. });
  132. });
  133. },
  134. // 获取列表数据 接口
  135. getDateList: function (page, rows) {
  136. this.$http({
  137. method: "post",
  138. url: "/sys/dataDict/selectSysDataDictPage",
  139. data: {
  140. dictCode: this.dictList[1]["dictCode"],
  141. parentId: this.dictList[1]["id"],
  142. page,
  143. rows
  144. },
  145. })
  146. .then((res) => {
  147. if (res.data && res.data.code === 200) {
  148. console.log(res.data.data);
  149. this.tableData = res.data.data;
  150. this.sum = res.data.count;
  151. } else {
  152. console.log(res);
  153. }
  154. })
  155. .catch((err) => {
  156. console.log(err);
  157. });
  158. },
  159. // 新增
  160. addList: function (name) {
  161. return new Promise((resolve, reject) => {
  162. this.$http({
  163. url: "/sys/dataDict/addSysDataDictInfo",
  164. method: "post",
  165. data: {
  166. dictName: name,
  167. parentId: this.dictList[1]["id"],
  168. dictCode: this.dictList[1]["dictCode"],
  169. },
  170. })
  171. .then((res) => {
  172. if (res.data && res.data.code === 200) {
  173. console.log(res);
  174. resolve();
  175. } else {
  176. alert("新增失败,请重试");
  177. console.log(res);
  178. }
  179. })
  180. .catch((err) => {
  181. alert("新增失败,请重试");
  182. reject(err);
  183. });
  184. });
  185. },
  186. // 编辑 接口
  187. updataDict: function (newName, index) {
  188. return new Promise((resolve, reject) => {
  189. this.$http({
  190. url: "/sys/dataDict/updateSysDataDictInfo",
  191. method: "post",
  192. data: {
  193. dictName: newName,
  194. id: this.tableData[index]["id"],
  195. parentId: this.dictList[1]["id"],
  196. dictCode: this.dictList[1]["dictCode"],
  197. },
  198. })
  199. .then((res) => {
  200. if (res.data && res.data.code === 200) {
  201. console.log(res);
  202. resolve();
  203. } else {
  204. alert("编辑失败,请重试");
  205. console.log(res);
  206. }
  207. })
  208. .catch((err) => {
  209. alert("编辑失败,请重试");
  210. reject(err);
  211. });
  212. });
  213. },
  214. // 删除 接口
  215. deleteDict: function (index) {
  216. return new Promise((resolve, reject) => {
  217. this.$http({
  218. url: "/sys/dataDict/deleteSysDataDictInfo",
  219. method: "post",
  220. data: {
  221. id: this.tableData[index]["id"],
  222. parentId: this.dictList[1]["id"],
  223. // dictCode: this.dictList[1]['dictCode'],
  224. },
  225. })
  226. .then((res) => {
  227. if (res.data && res.data.code === 200) {
  228. console.log(res);
  229. resolve();
  230. } else {
  231. alert("删除失败,请重试");
  232. console.log(res);
  233. }
  234. })
  235. .catch((err) => {
  236. alert("删除失败,请重试");
  237. reject(err);
  238. });
  239. });
  240. },
  241. },
  242. created() {
  243. this.selectSysDataDictList()
  244. .then(() => {
  245. this.getDateList(this.currentPage, this.pageSize);
  246. })
  247. .catch((err) => {
  248. console.log(err);
  249. });
  250. },
  251. };
  252. </script>
  253. <style scoped lang="less">
  254. .car_series {
  255. .count {
  256. height: 40px;
  257. width: 100%;
  258. display: flex;
  259. justify-content: space-between;
  260. align-items: center;
  261. button {
  262. width: 86px;
  263. height: 30px;
  264. position: relative;
  265. bottom: -5px;
  266. margin: 0;
  267. border-radius: 2px;
  268. }
  269. }
  270. }
  271. </style>