DetailPage.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 "./DetailPageTable";
  38. import Modal from "./DetailPageModal";
  39. import { php_url } from "../../../../config/env";
  40. import axiosPhp from "axios";
  41. export default {
  42. components: {
  43. Count,
  44. Table,
  45. Tablepage,
  46. Modal,
  47. },
  48. data() {
  49. return {
  50. sum: 0, // 一共有多少条数据
  51. pageSize: 20, // 每页展示的数据
  52. currentPage: 1,
  53. tableData: [],
  54. modalFlag: false, // 控制模态框展示
  55. parentId: (this.$route.query && this.$route.query.id) || "",
  56. unifiedUrl: "/lexus_php/api/",
  57. };
  58. },
  59. computed: {
  60. // 表格总页数
  61. totalPage() {
  62. return Math.ceil(this.sum / this.pageSize);
  63. },
  64. // 获取路由参数
  65. queryTag() {
  66. console.log(111, this.$route.query);
  67. return this.$route.query && this.$route.query.tag ? 0 : 1;
  68. },
  69. },
  70. methods: {
  71. // 获取某一页面的数据,展示在表格
  72. changePage: function (page) {
  73. this.currentPage = page;
  74. this.selectPublishPlatformPage(
  75. this.parentId,
  76. this.currentPage,
  77. this.pageSize
  78. );
  79. },
  80. // 点击上一页,下一页,首页,尾页
  81. jumpPage: function (item) {
  82. switch (item) {
  83. case 1:
  84. this.currentPage = 1;
  85. break;
  86. case 2:
  87. this.currentPage = this.currentPage - 1;
  88. break;
  89. case 3:
  90. this.currentPage = this.currentPage + 1;
  91. break;
  92. case 4:
  93. this.currentPage = this.totalPage;
  94. break;
  95. }
  96. this.selectPublishPlatformPage(
  97. this.parentId,
  98. this.currentPage,
  99. this.pageSize
  100. );
  101. },
  102. // 展示、隐藏模态框
  103. showModal: function () {
  104. this.modalFlag = !this.modalFlag;
  105. },
  106. // 点击编辑
  107. edit(index, newName) {
  108. let id = this.tableData[index]["id"];
  109. let parentId = this.parentId;
  110. this.updatePublishPlatformInfo(parentId, id, newName).then(() => {
  111. this.selectPublishPlatformPage(
  112. this.parentId,
  113. this.currentPage,
  114. this.pageSize
  115. );
  116. });
  117. },
  118. // 点击删除
  119. deleteData(index) {
  120. let parentId = this.parentId;
  121. let id = this.tableData[index]["id"];
  122. this.deletePublishPlatformInfo(parentId, id).then(() => {
  123. this.selectPublishPlatformPage(
  124. this.parentId,
  125. this.currentPage,
  126. this.pageSize
  127. );
  128. });
  129. },
  130. // 新增版块模态框 保存
  131. submit: function (platName) {
  132. let parentId = this.parentId;
  133. this.addPublishPlatformInfo(parentId, platName).then(() => {
  134. this.selectPublishPlatformPage(
  135. this.parentId,
  136. this.currentPage,
  137. this.pageSize
  138. );
  139. });
  140. this.modalFlag = false;
  141. },
  142. // 新增平台 接口
  143. addPublishPlatformInfo: function (parentId, platformName) {
  144. return new Promise((resolve, reject) => {
  145. axiosPhp({
  146. method: "post",
  147. url: php_url + this.unifiedUrl +"publish_platform_add.php",
  148. data:{
  149. parentId,
  150. platformName
  151. },
  152. }).then((res) => {
  153. if (res.data && res.data.code === 200) {
  154. console.log(res);
  155. resolve();
  156. } else {
  157. alert(res.data.message);
  158. console.log(res);
  159. }
  160. }).catch((err) => {
  161. console.log(err);
  162. reject(err);
  163. });
  164. });
  165. // return new Promise((resolve, reject) => {
  166. // this.$http({
  167. // method: "post",
  168. // url: "/base/publishPlatformManager/addPublishPlatformInfo",
  169. // data: {
  170. // parentId,
  171. // platformName,
  172. // },
  173. // })
  174. // .then((res) => {
  175. // if (res.data && res.data.code === 200) {
  176. // console.log(res);
  177. // resolve();
  178. // } else {
  179. // alert(res.data.message);
  180. // console.log(res);
  181. // }
  182. // })
  183. // .catch((err) => {
  184. // console.log(err);
  185. // reject(err);
  186. // });
  187. // });
  188. },
  189. // 获取列表 接口
  190. selectPublishPlatformPage: function (parentId, page, rows) {
  191. axiosPhp({
  192. method: "post",
  193. url: php_url + this.unifiedUrl +"publish_platform_list.php",
  194. data:{
  195. parentId,
  196. page,
  197. rows,
  198. },
  199. }).then((res) => {
  200. if (res.data && res.data.code === 200) {
  201. console.log(res);
  202. this.tableData = res.data.data;
  203. this.sum = Number(res.data.count);
  204. } else {
  205. console.log(res);
  206. }
  207. }).catch((err) => {
  208. console.log(err);
  209. });
  210. // this.$http({
  211. // method: "post",
  212. // url: "/base/publishPlatformManager/selectPublishPlatformPage",
  213. // data: {
  214. // parentId,
  215. // page,
  216. // rows,
  217. // },
  218. // })
  219. // .then((res) => {
  220. // if (res.data && res.data.code === 200) {
  221. // console.log(res);
  222. // this.tableData = res.data.data;
  223. // this.sum = res.data.count;
  224. // } else {
  225. // console.log(res);
  226. // }
  227. // })
  228. // .catch((err) => {
  229. // console.log(err);
  230. // });
  231. },
  232. // 编辑平台模块,接口
  233. updatePublishPlatformInfo: function (parentId, id, platformName) {
  234. return new Promise((resolve, reject) => {
  235. axiosPhp({
  236. method: "post",
  237. url: php_url + this.unifiedUrl +"publish_platform_update.php",
  238. data:{
  239. parentId,
  240. id,
  241. platformName
  242. },
  243. }).then((res) => {
  244. if (res.data && res.data.code === 200) {
  245. resolve();
  246. } else {
  247. alert("编辑失败,请重试");
  248. console.log(res);
  249. }
  250. }).catch((err) => {
  251. alert("编辑失败,请重试");
  252. console.log(err);
  253. reject(err);
  254. });
  255. });
  256. // return new Promise((resolve, reject) => {
  257. // this.$http({
  258. // method: "post",
  259. // url: "/base/publishPlatformManager/updatePublishPlatformInfo",
  260. // data: {
  261. // parentId,
  262. // id,
  263. // platformName,
  264. // },
  265. // })
  266. // .then((res) => {
  267. // console.log(res, 1111);
  268. // if (res.data && res.data.code === 200) {
  269. // console.log(res);
  270. // resolve();
  271. // } else {
  272. // alert("编辑失败,请重试");
  273. // console.log(res);
  274. // }
  275. // })
  276. // .catch((err) => {
  277. // alert("编辑失败,请重试");
  278. // console.log(err);
  279. // reject(err);
  280. // });
  281. // });
  282. },
  283. // 删除平台模块 接口
  284. deletePublishPlatformInfo: function (parentId, id) {
  285. return new Promise((resolve, reject) => {
  286. axiosPhp({
  287. method: "post",
  288. url: php_url + this.unifiedUrl +"publish_platform_del.php",
  289. data:{
  290. parentId,
  291. id,
  292. },
  293. }).then((res) => {
  294. if (res.data && res.data.code === 200) {
  295. resolve();
  296. } else {
  297. alert("删除失败,请重试");
  298. console.log(res);
  299. }
  300. }).catch((err) => {
  301. alert("删除失败,请重试");
  302. console.log(err);
  303. reject(err);
  304. });
  305. });
  306. // return new Promise((resolve, reject) => {
  307. // this.$http({
  308. // method: "post",
  309. // url: "/base/publishPlatformManager/deletePublishPlatformInfo",
  310. // data: {
  311. // parentId,
  312. // id,
  313. // },
  314. // })
  315. // .then((res) => {
  316. // if (res.data && res.data.code === 200) {
  317. // console.log(res);
  318. // resolve();
  319. // } else {
  320. // alert("编辑失败,请重试");
  321. // console.log(res);
  322. // }
  323. // })
  324. // .catch((err) => {
  325. // alert("编辑失败,请重试");
  326. // console.log(err);
  327. // reject(err);
  328. // });
  329. // });
  330. },
  331. },
  332. mounted() {
  333. this.selectPublishPlatformPage(
  334. this.parentId,
  335. this.currentPage,
  336. this.pageSize
  337. );
  338. },
  339. beforeRouteEnter(to, from, next) {
  340. console.log(from)
  341. let meta = to.meta;
  342. console.log(meta)
  343. meta[2].name = to.query.setion + '版块管理'
  344. next()
  345. }
  346. };
  347. </script>
  348. <style scoped lang="less">
  349. .car_series {
  350. .count {
  351. height: 40px;
  352. width: 100%;
  353. display: flex;
  354. justify-content: space-between;
  355. align-items: center;
  356. button {
  357. width: 86px;
  358. height: 30px;
  359. position: relative;
  360. bottom: -5px;
  361. margin: 0;
  362. border-radius: 2px;
  363. }
  364. }
  365. }
  366. </style>