changShang.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="notice_changShang">
  3. <div v-if="isFather">
  4. <div style="color: #80808059; border: 1px solid"></div>
  5. <button @click="announce()">发布公告</button>
  6. <div class="tableD">
  7. <div class="table_template">
  8. <table class="table">
  9. <thead>
  10. <tr :style="tableHeadStyle">
  11. <td
  12. v-for="(item, index) in tableHeaderD"
  13. :key="index"
  14. :style="tableHeadStyle"
  15. >
  16. {{ item }}
  17. </td>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. <tr
  22. v-for="(obj, index) in tableData"
  23. :key="index"
  24. :class="{ table_gray: !discolor && index % 2 === 1 }"
  25. >
  26. <td class="titleStyle" @click="goDetailPage(obj)">{{ obj.title || "-" }}</td>
  27. <td>重要通知</td>
  28. <td>
  29. <!--{{-->
  30. <!--(obj.addtime || "")-->
  31. <!--.replace("T", " ")-->
  32. <!--.slice(0, -4)-->
  33. <!--.replace(RegExp("-", "g"), "/")-->
  34. <!--}}-->
  35. {{obj.addtime.substr(0,10)}}
  36. </td>
  37. <td v-if="operation" :style="trStyle" class="operationStyle">
  38. <div class="operationBox">
  39. <span
  40. style="cursor: pointer"
  41. v-for="(operationObj, i) in operation"
  42. :key="i"
  43. @click="operationObj.function(obj, index)"
  44. >{{ operationObj.name }}
  45. </span>
  46. </div>
  47. </td>
  48. </tr>
  49. </tbody>
  50. </table>
  51. </div>
  52. </div>
  53. <div class="pageD">
  54. <TablePage
  55. :totalPage="totalPage"
  56. :currentPage="currentPage"
  57. @change_page="changePage"
  58. @jump_page="jumpPage"
  59. />
  60. <p>共{{ totalPage }}页,共{{ sum }}条数据</p>
  61. </div>
  62. </div>
  63. <router-view :key="this.$route.path"></router-view>
  64. </div>
  65. </template>
  66. <script>
  67. import TablePage from "../../components/TablePage";
  68. import { env_url , php_url } from "../../config/env";
  69. import axiosPhp from "axios";
  70. export default {
  71. components: {
  72. TablePage,
  73. },
  74. data() {
  75. return {
  76. unifiedUrl:'/lexus_php/api/',
  77. tableHeaderD: ["标题", "信息类型", "创建时间", "操作"],
  78. operation: [
  79. {
  80. name: "编辑",
  81. function: (obj) => {
  82. this.edit(obj);
  83. },
  84. },
  85. {
  86. name: "删除",
  87. function: (obj) => {
  88. this.delNotice(obj.id)
  89. },
  90. },
  91. ],
  92. // 表格配置
  93. sum: 0, // 一共有多少条数据
  94. pageSize: 20, // 每页展示的数据
  95. discolor: false, // flase是隔行变色
  96. currentPage: 1,
  97. tableData: [],
  98. tableFileData: [],
  99. tableHeadStyle: {
  100. background: "#848484",
  101. height: "36px",
  102. color: "white",
  103. },
  104. trStyle: {
  105. minwidth: "150px",
  106. overflow: "hidden",
  107. },
  108. onlineUrl: env_url, //'http://8.140.188.129:8080'线上 //http://8.136.230.133:8080 //测试
  109. userId: localStorage.getItem("userId") || "",
  110. };
  111. },
  112. computed: {
  113. // 表格总页数
  114. totalPage() {
  115. return Math.ceil(this.sum / this.pageSize);
  116. },
  117. isFather: function () {
  118. return this.$route.path === '/changShang';
  119. },
  120. },
  121. methods: {
  122. goDetailPage(param){
  123. this.$router.push({
  124. path: "/changShang/itemDetail",
  125. query: {
  126. id:param.id
  127. },
  128. });
  129. },
  130. // 获取某一页面的数据,展示在表格
  131. changePage: function (page) {
  132. this.currentPage = page;
  133. this.getDataList()
  134. },
  135. // 点击上一页,下一页,首页,尾页
  136. jumpPage: function (item) {
  137. switch (item) {
  138. case 1:
  139. this.currentPage = 1;
  140. break;
  141. case 2:
  142. this.currentPage = this.currentPage - 1;
  143. break;
  144. case 3:
  145. this.currentPage = this.currentPage + 1;
  146. break;
  147. case 4:
  148. this.currentPage = this.totalPage;
  149. break;
  150. }
  151. this.getDataList()
  152. },
  153. //编辑
  154. edit: function (config) {
  155. console.log(config,'father')
  156. if(typeof (config.area) === 'string'){
  157. config.area = (config.area).split(',');
  158. }
  159. this.$router.push({
  160. path: "/changShang/editPage",
  161. query: config,
  162. });
  163. },
  164. getDataList: function () {
  165. axiosPhp({
  166. method: "post",
  167. url: php_url + this.unifiedUrl + "notice_list.php",
  168. data: {
  169. Page: this.currentPage,
  170. Rows: this.pageSize,
  171. },
  172. })
  173. .then((res) => {
  174. if (res.data.code === 200) {
  175. this.sum = res.data.count;
  176. this.tableData = res.data.data;
  177. }
  178. })
  179. .catch((err) => {
  180. console.log(err);
  181. });
  182. },
  183. delNotice: function (id) {
  184. axiosPhp({
  185. method: "post",
  186. url: php_url + this.unifiedUrl + "notice_del.php",
  187. data: {
  188. ids:id
  189. },
  190. })
  191. .then((res) => {
  192. if (res.data.code === 200) {
  193. alert(res.data.msg);
  194. this.getDataList();
  195. }
  196. })
  197. .catch((err) => {
  198. alert(err)
  199. });
  200. },
  201. /* 发布公告 */
  202. announce: function () {
  203. this.$router.push({
  204. path: "/changShang/editPage",
  205. query: {
  206. title:'',
  207. content:``,
  208. id:'',
  209. files:[],
  210. area:['全区']
  211. },
  212. });
  213. },
  214. },
  215. watch: {
  216. // 如果路由发生变化,再次执行该方法
  217. "$route": "getDataList"
  218. },
  219. created() {
  220. },
  221. mounted() {
  222. this.getDataList()
  223. }
  224. };
  225. </script>
  226. <style scoped lang="less">
  227. .titleStyle {
  228. color: #0000ff;
  229. cursor: pointer;
  230. }
  231. /* 查看详情样式 */
  232. .table_template {
  233. text-align: center;
  234. .table {
  235. background-color: #fff;
  236. border-collapse: collapse;
  237. border: none;
  238. width: 100%;
  239. td {
  240. border: 1px solid #ccc;
  241. height: 36px;
  242. width: 25%;
  243. }
  244. span {
  245. &:hover {
  246. cursor: pointer;
  247. }
  248. }
  249. }
  250. }
  251. .table_gray {
  252. background-color: #f5f5f5;
  253. }
  254. .operationStyle span {
  255. color: #0000ff;
  256. }
  257. .operationBox {
  258. width: 100%;
  259. display: flex;
  260. justify-content: space-around;
  261. }
  262. .HeadLeft {
  263. border: 1px solid #ccc;
  264. }
  265. .pageD {
  266. display: flex;
  267. justify-content: flex-end;
  268. align-items: center;
  269. margin-top: 10px;
  270. }
  271. .pageD p {
  272. margin-left: 16px;
  273. }
  274. .reportStyle {
  275. text-decoration: underline;
  276. cursor: pointer;
  277. }
  278. .showItemOperationStyle {
  279. display: none;
  280. }
  281. .noJump {
  282. color: rgb(173, 162, 162);
  283. cursor: text !important;
  284. text-decoration: underline;
  285. }
  286. .canJump {
  287. text-decoration: underline;
  288. }
  289. .notice_changShang button:nth-of-type(1) {
  290. position: relative;
  291. float: right;
  292. margin: 8px 8px;
  293. padding: 8px 16px;
  294. width: 100px;
  295. height: 35px;
  296. border-radius: 5px;
  297. }
  298. </style>