index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
  4. <el-form-item label="标题" prop="titleName">
  5. <el-input
  6. v-model="queryParams.titleName"
  7. placeholder="请输入标题"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="是否置顶" prop="isTop">
  13. <el-select v-model="queryParams.isTop" placeholder="是否置顶" clearable>
  14. <el-option
  15. v-for="dict in isTops"
  16. :key="dict.value"
  17. :label="dict.label"
  18. :value="dict.value"
  19. />
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item label="是否政策推荐" prop="isGovernment">
  23. <el-select v-model="queryParams.isGovernment" placeholder="是否政策推荐" clearable>
  24. <el-option
  25. v-for="dict in isGovernments"
  26. :key="dict.value"
  27. :label="dict.label"
  28. :value="dict.value"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['jnb:information:add']"
  46. >新增
  47. </el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['jnb:information:edit']"
  58. >修改
  59. </el-button>
  60. </el-col>
  61. <el-col :span="1.5">
  62. <el-button
  63. type="danger"
  64. plain
  65. icon="el-icon-delete"
  66. size="mini"
  67. :disabled="multiple"
  68. @click="handleDelete"
  69. v-hasPermi="['jnb:information:remove']"
  70. >删除
  71. </el-button>
  72. </el-col>
  73. <el-col :span="1.5">
  74. <el-button
  75. type="warning"
  76. plain
  77. icon="el-icon-download"
  78. size="mini"
  79. @click="handleExport"
  80. v-hasPermi="['jnb:information:export']"
  81. >导出
  82. </el-button>
  83. </el-col>
  84. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  85. </el-row>
  86. <el-table v-loading="loading" :data="serverList" @selection-change="handleSelectionChange">
  87. <el-table-column type="selection" width="55" align="center"/>
  88. <el-table-column label="序号" align="center" type="index"/>
  89. <el-table-column label="标题" align="center" prop="titleName" show-overflow-tooltip/>
  90. <el-table-column label="是否政策推荐" align="center" prop="isGovernment">
  91. <template slot-scope="scope">
  92. <el-tag type="success" v-if="scope.row.isGovernment == '1'">是</el-tag>
  93. <el-tag type="warning" v-if="scope.row.isGovernment == '0'">否</el-tag>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="是否置顶" align="center" prop="isTop">
  97. <template slot-scope="scope">
  98. <el-tag type="success" v-if="scope.row.isTop == '1'">是</el-tag>
  99. <el-tag type="warning" v-if="scope.row.isTop == '0'">否</el-tag>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="点赞数" align="center" prop="likeNum" show-overflow-tooltip/>
  103. <el-table-column label="浏览数" align="center" prop="watchNum" show-overflow-tooltip/>
  104. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  105. <template slot-scope="scope">
  106. <el-button
  107. size="mini"
  108. type="text"
  109. icon="el-icon-edit"
  110. @click="handleUpdate(scope.row)"
  111. v-hasPermi="['jnb:information:edit']"
  112. >修改
  113. </el-button>
  114. <el-button
  115. size="mini"
  116. type="text"
  117. icon="el-icon-delete"
  118. @click="handleDelete(scope.row)"
  119. v-hasPermi="['jnb:information:remove']"
  120. >删除
  121. </el-button>
  122. </template>
  123. </el-table-column>
  124. </el-table>
  125. <pagination
  126. v-show="total>0"
  127. :total="total"
  128. :page.sync="queryParams.pageNum"
  129. :limit.sync="queryParams.pageSize"
  130. @pagination="getList"
  131. />
  132. <!-- 添加或修改资讯对话框 -->
  133. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  134. <el-form ref="form" :model="form" :rules="rules" label-width="110px">
  135. <el-row :gutter="20">
  136. <el-col :span="12">
  137. <el-form-item label="标题" prop="titleName">
  138. <el-input v-model="form.titleName" placeholder="请输入标题" maxlength="50"/>
  139. </el-form-item>
  140. </el-col>
  141. </el-row>
  142. <el-row :gutter="20">
  143. <el-col :span="12">
  144. <el-form-item label="是否置顶" prop="isTop">
  145. <el-switch
  146. v-model="form.isTop"
  147. :active-value="1"
  148. :inactive-value="0">
  149. </el-switch>
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="12">
  153. <el-form-item label="是否政策推荐" prop="isGovernment">
  154. <el-switch
  155. v-model="form.isGovernment"
  156. :active-value="1"
  157. :inactive-value="0">
  158. </el-switch>
  159. </el-form-item>
  160. </el-col>
  161. </el-row>
  162. <el-row :gutter="20">
  163. </el-row>
  164. <el-row :gutter="20">
  165. <el-col :span="12">
  166. <el-form-item label="浏览数" prop="watchNum">
  167. <el-input-number v-model="form.watchNum" :min="0" :max="999999999" label="浏览数"></el-input-number>
  168. </el-form-item>
  169. </el-col>
  170. <el-col :span="12">
  171. <el-form-item label="点赞数" prop="likeNum">
  172. <el-input-number v-model="form.likeNum" :min="0" :max="999999999" label="点赞数"></el-input-number>
  173. </el-form-item>
  174. </el-col>
  175. </el-row>
  176. <el-row :gutter="20">
  177. <el-col :span="24">
  178. <el-form-item label="正文" prop="textDetails">
  179. <editor v-model="form.textDetails" :min-height="192"/>
  180. </el-form-item>
  181. </el-col>
  182. </el-row>
  183. <el-row :gutter="20">
  184. <el-col :span="24">
  185. <el-form-item label="图片" prop="imgUrlList">
  186. <image-upload v-model="form.imgUrlList"/>
  187. </el-form-item>
  188. </el-col>
  189. </el-row>
  190. </el-form>
  191. <div slot="footer" class="dialog-footer">
  192. <el-button type="primary" @click="submitForm">确 定</el-button>
  193. <el-button @click="cancel">取 消</el-button>
  194. </div>
  195. </el-dialog>
  196. </div>
  197. </template>
  198. <script>
  199. import {listServer, getServer, delServer, addServer, updateServer} from "@/api/information/information";
  200. export default {
  201. name: "information",
  202. data() {
  203. return {
  204. // 遮罩层
  205. loading: true,
  206. // 选中数组
  207. ids: [],
  208. isGovernments: [{label: '是', value: '1'}, {label: '否', value: '0'}],
  209. isTops: [{label: '是', value: '1'}, {label: '否', value: '0'}],
  210. // 非单个禁用
  211. single: true,
  212. // 非多个禁用
  213. multiple: true,
  214. // 显示搜索条件
  215. showSearch: true,
  216. // 总条数
  217. total: 0,
  218. // 资讯表格数据
  219. serverList: [],
  220. // 弹出层标题
  221. title: "",
  222. // 是否显示弹出层
  223. open: false,
  224. // 查询参数
  225. queryParams: {
  226. pageNum: 1,
  227. pageSize: 10,
  228. titleName: null,
  229. isGovernment: null,
  230. isTop: null,
  231. type: this.$route.query.type,
  232. delFlag: 0,
  233. },
  234. // 表单参数
  235. form: {},
  236. // 表单校验
  237. rules: {
  238. titleName: [
  239. {required: true, message: "标题不能为空", trigger: "blur"},
  240. ],
  241. titleDetails: [
  242. {required: true, message: "正文不能为空", trigger: "blur"},
  243. ],
  244. isGovernment: [
  245. {required: true, message: "政策推荐不能为空", trigger: "change"},
  246. ],
  247. isTop: [
  248. {required: true, message: "置顶不能为空", trigger: "change"},
  249. ],
  250. likeNum: [
  251. {required: true, message: "点赞数不能为空", trigger: ["change",'blur']},
  252. ],
  253. watchNum: [
  254. {required: true, message: "浏览数不能为空", trigger: ["change",'blur']},
  255. ],
  256. }
  257. };
  258. },
  259. created() {
  260. this.queryParams.type = this.$route.query.type;
  261. this.getList();
  262. },
  263. methods: {
  264. /** 查询资讯列表 */
  265. getList() {
  266. this.loading = true;
  267. listServer(this.queryParams).then(response => {
  268. this.serverList = response.rows;
  269. this.total = response.total;
  270. this.loading = false;
  271. });
  272. },
  273. // 取消按钮
  274. cancel() {
  275. this.open = false;
  276. this.reset();
  277. },
  278. // 表单重置
  279. reset() {
  280. this.form = {
  281. id: null,
  282. titleName: null,
  283. textDetails: null,
  284. type: this.$route.query.type,
  285. createTime: null,
  286. watchNum: 0,
  287. likeNum: 0,
  288. isTop: '0',
  289. isGovernment: '0',
  290. updateBy: null,
  291. updateTime: null,
  292. imgUrlList: '',
  293. delFlag: 0,
  294. };
  295. },
  296. /** 搜索按钮操作 */
  297. handleQuery() {
  298. this.queryParams.pageNum = 1;
  299. this.getList();
  300. },
  301. /** 重置按钮操作 */
  302. resetQuery() {
  303. this.resetForm("queryForm");
  304. this.handleQuery();
  305. },
  306. // 多选框选中数据
  307. handleSelectionChange(selection) {
  308. this.ids = selection.map(item => item.id)
  309. this.single = selection.length !== 1
  310. this.multiple = !selection.length
  311. },
  312. /** 新增按钮操作 */
  313. async handleAdd() {
  314. await this.reset();
  315. this.open = true;
  316. let str = ''
  317. if (this.$route.query.type == 10) {
  318. str = '惠民通'
  319. } else if (this.$route.query.type == 11) {
  320. str = '法律下乡'
  321. } else if (this.$route.query.type == 12) {
  322. str = '资讯'
  323. }
  324. this.title = "新增" + str;
  325. },
  326. /** 修改按钮操作 */
  327. async handleUpdate(row) {
  328. await this.reset();
  329. const id = row.id || this.ids
  330. getServer(id,row.type).then(response => {
  331. this.form = response.data;
  332. this.open = true;
  333. let str = ''
  334. if (this.$route.query.type == 10) {
  335. str = '惠民通'
  336. } else if (this.$route.query.type == 11) {
  337. str = '法律下乡'
  338. } else if (this.$route.query.type == 12) {
  339. str = '资讯'
  340. }
  341. this.title = "修改" + str;
  342. });
  343. },
  344. /** 提交按钮 */
  345. submitForm() {
  346. this.$refs["form"].validate(valid => {
  347. if (valid) {
  348. if (this.form.id != null) {
  349. updateServer(this.form).then(response => {
  350. this.$modal.msgSuccess("修改成功");
  351. this.open = false;
  352. this.getList();
  353. });
  354. } else {
  355. addServer(this.form).then(response => {
  356. this.$modal.msgSuccess("新增成功");
  357. this.open = false;
  358. this.getList();
  359. });
  360. }
  361. }
  362. });
  363. },
  364. /** 删除按钮操作 */
  365. handleDelete(row) {
  366. const ids = row.id || this.ids;
  367. const type = this.$route.query.type
  368. this.$modal.confirm('是否确认删除数据项?').then(function () {
  369. return delServer(ids,type);
  370. }).then(() => {
  371. this.getList();
  372. this.$modal.msgSuccess("删除成功");
  373. }).catch(() => {
  374. });
  375. },
  376. /** 导出按钮操作 */
  377. handleExport() {
  378. this.download('jnb/information/export', {
  379. ...this.queryParams
  380. }, `Excel_${new Date().getTime()}.xlsx`)
  381. }
  382. }
  383. };
  384. </script>