index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="标题名称" prop="advTitle">
  5. <el-input
  6. v-model="queryParams.advTitle"
  7. placeholder="请输入标题名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="状态" clearable size="small">
  15. <el-option
  16. v-for="dict in statusOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="显示类型" prop="showType">
  24. <el-select v-model="queryParams.showType" placeholder="展示类型" clearable size="small">
  25. <el-option
  26. v-for="dict in showOptions"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="dict.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="广告类型" prop="advType">
  34. <el-select v-model="queryParams.advType" placeholder="广告类型" clearable size="small">
  35. <el-option
  36. v-for="dict in devOptions"
  37. :key="dict.dictValue"
  38. :label="dict.dictLabel"
  39. :value="dict.dictValue"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  45. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button
  51. type="primary"
  52. plain
  53. icon="el-icon-plus"
  54. size="mini"
  55. @click="handleAdd"
  56. v-hasPermi="['his:adv:add']"
  57. >新增</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="success"
  62. plain
  63. icon="el-icon-edit"
  64. size="mini"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['his:adv:edit']"
  68. >修改</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="danger"
  73. plain
  74. icon="el-icon-delete"
  75. size="mini"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. v-hasPermi="['his:adv:remove']"
  79. >删除</el-button>
  80. </el-col>
  81. <el-col :span="1.5">
  82. <el-button
  83. type="warning"
  84. plain
  85. icon="el-icon-download"
  86. size="mini"
  87. :loading="exportLoading"
  88. @click="handleExport"
  89. v-hasPermi="['his:adv:export']"
  90. >导出</el-button>
  91. </el-col>
  92. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  93. </el-row>
  94. <el-table v-loading="loading" :data="advList" @selection-change="handleSelectionChange" border>
  95. <el-table-column type="selection" width="55" align="center" />
  96. <el-table-column label="标题名称" align="center" prop="advTitle" width="150px"/>
  97. <el-table-column label="图片" align="center" prop="imageUrl" width="150px">
  98. <template slot-scope="scope">
  99. <el-popover
  100. placement="right"
  101. title=""
  102. trigger="hover">
  103. <img slot="reference" :src="scope.row.imageUrl" width="100">
  104. <img :src="scope.row.imageUrl" style="max-width: 150px;">
  105. </el-popover>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="地址" show-overflow-tooltip align="center" prop="advUrl" width="150px" />
  109. <el-table-column label="排序" align="center" prop="sort" />
  110. <el-table-column label="类型" align="center" prop="advType" width="130px">
  111. <template slot-scope="scope">
  112. <dict-tag :options="devOptions" :value="scope.row.advType"/>
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="显示类型" align="center" prop="showType" width="130px">
  116. <template slot-scope="scope">
  117. <dict-tag :options="showOptions" :value="scope.row.showType"/>
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="状态" align="center" prop="status" >
  121. <template slot-scope="scope">
  122. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="创建时间" align="center" prop="createTime" width="150px" />
  126. <el-table-column label="修改时间" align="center" prop="updateTime" width="150px" />
  127. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
  128. <template slot-scope="scope">
  129. <el-button
  130. size="mini"
  131. type="text"
  132. icon="el-icon-edit"
  133. @click="handleUpdate(scope.row)"
  134. v-hasPermi="['his:adv:edit']"
  135. >修改</el-button>
  136. <el-button
  137. size="mini"
  138. type="text"
  139. icon="el-icon-delete"
  140. @click="handleDelete(scope.row)"
  141. v-hasPermi="['his:adv:remove']"
  142. >删除</el-button>
  143. </template>
  144. </el-table-column>
  145. </el-table>
  146. <pagination
  147. v-show="total>0"
  148. :total="total"
  149. :page.sync="queryParams.pageNum"
  150. :limit.sync="queryParams.pageSize"
  151. @pagination="getList"
  152. />
  153. <!-- 添加或修改广告对话框 -->
  154. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  155. <el-form ref="form" :model="form" :rules="rules" label-width="90px">
  156. <el-form-item label="标题名称" prop="advTitle">
  157. <el-input v-model="form.advTitle" placeholder="请输入广告标题" />
  158. </el-form-item>
  159. <el-form-item label="图片" prop="imageUrl" >
  160. <el-upload
  161. v-model="form.imageUrl"
  162. class="avatar-uploader"
  163. :action="uploadUrl"
  164. :show-file-list="false"
  165. :on-success="handleAvatarSuccess"
  166. :before-upload="beforeAvatarUpload">
  167. <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar" width="300px">
  168. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  169. </el-upload>
  170. </el-form-item>
  171. <el-form-item label="类型" prop="advType">
  172. <el-select v-model="form.advType" placeholder="请选择类型" >
  173. <el-option
  174. v-for="item in devOptions"
  175. :key="item.dictValue"
  176. :label="item.dictLabel"
  177. :value="item.dictValue"
  178. ></el-option>
  179. </el-select>
  180. </el-form-item>
  181. <el-form-item label="显示类型" prop="showType">
  182. <el-radio-group v-model="form.showType">
  183. <el-radio :label="item.dictValue" v-for="item in showOptions" >{{item.dictLabel}}</el-radio>
  184. </el-radio-group>
  185. </el-form-item>
  186. <el-form-item label="公众号链接" prop="advUrl" v-if="form.showType==1">
  187. <el-input v-model="form.advUrl" placeholder="请输入公众号链接" />
  188. </el-form-item>
  189. <el-form-item label="小程序地址" prop="advUrl" v-if="form.showType==2">
  190. <el-input v-model="form.advUrl" placeholder="请输入小程序地址" />
  191. </el-form-item>
  192. <el-form-item label="APP地址" prop="advUrl" v-if="form.showType==2||form.showType==4 ">
  193. <el-input v-model="form.appAdvUrl" placeholder="请输入APP地址" />
  194. </el-form-item>
  195. <el-form-item label="文章内容" v-show="form.showType==3">
  196. <editor ref="myeditor" @on-text-change="updateText" />
  197. </el-form-item>
  198. <el-form-item label="活动" prop="activeId" v-show="form.showType === '5'">
  199. <el-select v-model="form.activeId" placeholder="请选择活动" >
  200. <el-option
  201. v-for="item in activeOptions"
  202. :key="item.dictValue"
  203. :label="item.dictLabel"
  204. :value="item.dictValue"
  205. ></el-option>
  206. </el-select>
  207. </el-form-item>
  208. <el-form-item label="排序">
  209. <el-input-number v-model="form.sort" label="排序"></el-input-number>
  210. </el-form-item>
  211. <el-form-item label="状态">
  212. <el-radio-group v-model="form.status">
  213. <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
  214. </el-radio-group>
  215. </el-form-item>
  216. </el-form>
  217. <div slot="footer" class="dialog-footer">
  218. <el-button type="primary" @click="submitForm">确 定</el-button>
  219. <el-button @click="cancel">取 消</el-button>
  220. </div>
  221. </el-dialog>
  222. </div>
  223. </template>
  224. <script>
  225. import { listAdv, getAdv, delAdv, addAdv, updateAdv, exportAdv } from "@/api/his/adv";
  226. import Editor from '@/components/Editor/wang';
  227. import { getPromotionalActiveOption } from '@/api/his/promotionalActive'
  228. export default {
  229. name: "Adv",
  230. components: { Editor },
  231. data() {
  232. return {
  233. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
  234. baseUrl: process.env.VUE_APP_BASE_API,
  235. showOptions: [],
  236. devOptions: [],
  237. statusOptions: [],
  238. activeOptions: [],
  239. // 遮罩层
  240. loading: true,
  241. // 导出遮罩层
  242. exportLoading: false,
  243. // 选中数组
  244. ids: [],
  245. // 非单个禁用
  246. single: true,
  247. // 非多个禁用
  248. multiple: true,
  249. // 显示搜索条件
  250. showSearch: true,
  251. // 总条数
  252. total: 0,
  253. // 广告表格数据
  254. advList: [],
  255. // 弹出层标题
  256. title: "",
  257. // 是否显示弹出层
  258. open: false,
  259. // 查询参数
  260. queryParams: {
  261. pageNum: 1,
  262. pageSize: 10,
  263. advTitle: null,
  264. imageUrl: null,
  265. advUrl: null,
  266. content: null,
  267. status: null,
  268. sort: null,
  269. advType: null,
  270. showType: null
  271. },
  272. // 表单参数
  273. form: {},
  274. // 表单校验
  275. rules: {
  276. advTitle: [
  277. { required: true, message: "标题不能为空", trigger: "blur" }
  278. ],
  279. status: [
  280. { required: true, message: "状态不能为空", trigger: "blur" }
  281. ],
  282. sort: [
  283. { required: true, message: "排序不能为空", trigger: "blur" }
  284. ],
  285. advType: [
  286. { required: true, message: "类别不能为空", trigger: "blur" }
  287. ],
  288. showType: [
  289. { required: true, message: "显示类别不能为空", trigger: "blur" }
  290. ],
  291. }
  292. };
  293. },
  294. created() {
  295. this.getList();
  296. this.getDicts("sys_company_status").then(response => {
  297. this.statusOptions = response.data;
  298. });
  299. this.getDicts("sys_adv_show").then(response => {
  300. this.showOptions = response.data;
  301. });
  302. this.getDicts("sys_adv_type").then(response => {
  303. this.devOptions = response.data;
  304. });
  305. this.getActiveOption()
  306. },
  307. methods: {
  308. getActiveOption() {
  309. getPromotionalActiveOption().then(response => {
  310. console.log(response)
  311. this.activeOptions = response.list;
  312. });
  313. },
  314. updateText(text){
  315. this.form.content=text
  316. },
  317. handleAvatarSuccess(res, file) {
  318. if(res.code==200){
  319. this.form.imageUrl=res.url;
  320. self.$forceUpdate()
  321. }
  322. else{
  323. this.msgError(res.msg);
  324. }
  325. },
  326. beforeAvatarUpload(file) {
  327. const isLt1M = file.size / 1024 / 1024 < 1;
  328. if (!isLt1M) {
  329. this.$message.error('上传图片大小不能超过 1MB!');
  330. }
  331. return isLt1M;
  332. },
  333. /** 查询广告列表 */
  334. getList() {
  335. this.loading = true;
  336. listAdv(this.queryParams).then(response => {
  337. this.advList = response.rows;
  338. this.total = response.total;
  339. this.loading = false;
  340. });
  341. },
  342. // 取消按钮
  343. cancel() {
  344. this.open = false;
  345. this.reset();
  346. },
  347. // 表单重置
  348. reset() {
  349. this.form = {
  350. advId: null,
  351. advTitle: null,
  352. imageUrl: null,
  353. advUrl: null,
  354. appAdvUrl: null,
  355. content: null,
  356. createTime: null,
  357. updateTime: null,
  358. status: "0",
  359. sort: null,
  360. advType: null,
  361. showType: null,
  362. activeId: null
  363. };
  364. this.resetForm("form");
  365. },
  366. /** 搜索按钮操作 */
  367. handleQuery() {
  368. this.queryParams.pageNum = 1;
  369. this.getList();
  370. },
  371. /** 重置按钮操作 */
  372. resetQuery() {
  373. this.resetForm("queryForm");
  374. this.handleQuery();
  375. },
  376. // 多选框选中数据
  377. handleSelectionChange(selection) {
  378. this.ids = selection.map(item => item.advId)
  379. this.single = selection.length!==1
  380. this.multiple = !selection.length
  381. },
  382. /** 新增按钮操作 */
  383. handleAdd() {
  384. this.reset();
  385. this.open = true;
  386. this.title = "添加广告";
  387. setTimeout(() => {
  388. this.$refs.myeditor.setText("");
  389. }, 100);
  390. },
  391. /** 修改按钮操作 */
  392. handleUpdate(row) {
  393. this.reset();
  394. const advId = row.advId || this.ids
  395. getAdv(advId).then(response => {
  396. this.form = response.data;
  397. this.open = true;
  398. this.title = "修改广告";
  399. this.form.advType = String(this.form.advType)
  400. this.form.showType = String(this.form.showType)
  401. setTimeout(() => {
  402. if(this.form.content==null){
  403. this.$refs.myeditor.setText("");
  404. }
  405. else{
  406. this.$refs.myeditor.setText(this.form.content);
  407. }
  408. }, 1);
  409. });
  410. },
  411. /** 提交按钮 */
  412. submitForm() {
  413. this.$refs["form"].validate(valid => {
  414. if (valid) {
  415. if (this.form.advId != null) {
  416. updateAdv(this.form).then(response => {
  417. this.msgSuccess("修改成功");
  418. this.open = false;
  419. this.getList();
  420. });
  421. } else {
  422. addAdv(this.form).then(response => {
  423. this.msgSuccess("新增成功");
  424. this.open = false;
  425. this.getList();
  426. });
  427. }
  428. }
  429. });
  430. },
  431. /** 删除按钮操作 */
  432. handleDelete(row) {
  433. const advIds = row.advId || this.ids;
  434. this.$confirm('是否确认删除广告编号为"' + advIds + '"的数据项?', "警告", {
  435. confirmButtonText: "确定",
  436. cancelButtonText: "取消",
  437. type: "warning"
  438. }).then(function() {
  439. return delAdv(advIds);
  440. }).then(() => {
  441. this.getList();
  442. this.msgSuccess("删除成功");
  443. }).catch(() => {});
  444. },
  445. /** 导出按钮操作 */
  446. handleExport() {
  447. const queryParams = this.queryParams;
  448. this.$confirm('是否确认导出所有广告数据项?', "警告", {
  449. confirmButtonText: "确定",
  450. cancelButtonText: "取消",
  451. type: "warning"
  452. }).then(() => {
  453. this.exportLoading = true;
  454. return exportAdv(queryParams);
  455. }).then(response => {
  456. this.download(response.msg);
  457. this.exportLoading = false;
  458. }).catch(() => {});
  459. }
  460. }
  461. };
  462. </script>
  463. <style>
  464. .avatar-uploader .el-upload {
  465. border: 1px dashed #d9d9d9;
  466. border-radius: 6px;
  467. cursor: pointer;
  468. position: relative;
  469. overflow: hidden;
  470. }
  471. .avatar-uploader .el-upload:hover {
  472. border-color: #409EFF;
  473. }
  474. .avatar-uploader-icon {
  475. font-size: 28px;
  476. color: #8c939d;
  477. width: 150px;
  478. height: 150px;
  479. line-height: 150px;
  480. text-align: center;
  481. }
  482. </style>