index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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-radio-group v-model="form.status">
  210. <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
  211. </el-radio-group>
  212. </el-form-item>
  213. </el-form>
  214. <div slot="footer" class="dialog-footer">
  215. <el-button type="primary" @click="submitForm">确 定</el-button>
  216. <el-button @click="cancel">取 消</el-button>
  217. </div>
  218. </el-dialog>
  219. </div>
  220. </template>
  221. <script>
  222. import { listAdv, getAdv, delAdv, addAdv, updateAdv, exportAdv } from "@/api/his/adv";
  223. import Editor from '@/components/Editor/wang';
  224. import { getPromotionalActiveOption } from '@/api/his/promotionalActive'
  225. export default {
  226. name: "Adv",
  227. components: { Editor },
  228. data() {
  229. return {
  230. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
  231. baseUrl: process.env.VUE_APP_BASE_API,
  232. showOptions: [],
  233. devOptions: [],
  234. statusOptions: [],
  235. activeOptions: [],
  236. // 遮罩层
  237. loading: true,
  238. // 导出遮罩层
  239. exportLoading: false,
  240. // 选中数组
  241. ids: [],
  242. // 非单个禁用
  243. single: true,
  244. // 非多个禁用
  245. multiple: true,
  246. // 显示搜索条件
  247. showSearch: true,
  248. // 总条数
  249. total: 0,
  250. // 广告表格数据
  251. advList: [],
  252. // 弹出层标题
  253. title: "",
  254. // 是否显示弹出层
  255. open: false,
  256. // 查询参数
  257. queryParams: {
  258. pageNum: 1,
  259. pageSize: 10,
  260. advTitle: null,
  261. imageUrl: null,
  262. advUrl: null,
  263. content: null,
  264. status: null,
  265. sort: null,
  266. advType: null,
  267. showType: null
  268. },
  269. // 表单参数
  270. form: {},
  271. // 表单校验
  272. rules: {
  273. advTitle: [
  274. { required: true, message: "标题不能为空", trigger: "blur" }
  275. ],
  276. status: [
  277. { required: true, message: "状态不能为空", trigger: "blur" }
  278. ],
  279. sort: [
  280. { required: true, message: "排序不能为空", trigger: "blur" }
  281. ],
  282. advType: [
  283. { required: true, message: "类别不能为空", trigger: "blur" }
  284. ],
  285. showType: [
  286. { required: true, message: "显示类别不能为空", trigger: "blur" }
  287. ],
  288. }
  289. };
  290. },
  291. created() {
  292. this.getList();
  293. this.getDicts("sys_company_status").then(response => {
  294. this.statusOptions = response.data;
  295. });
  296. this.getDicts("sys_adv_show").then(response => {
  297. this.showOptions = response.data;
  298. });
  299. this.getDicts("sys_adv_type").then(response => {
  300. this.devOptions = response.data;
  301. });
  302. this.getActiveOption()
  303. },
  304. methods: {
  305. getActiveOption() {
  306. getPromotionalActiveOption().then(response => {
  307. console.log(response)
  308. this.activeOptions = response.list;
  309. });
  310. },
  311. updateText(text){
  312. this.form.content=text
  313. },
  314. handleAvatarSuccess(res, file) {
  315. if(res.code==200){
  316. this.form.imageUrl=res.url;
  317. self.$forceUpdate()
  318. }
  319. else{
  320. this.msgError(res.msg);
  321. }
  322. },
  323. beforeAvatarUpload(file) {
  324. const isLt1M = file.size / 1024 / 1024 < 1;
  325. if (!isLt1M) {
  326. this.$message.error('上传图片大小不能超过 1MB!');
  327. }
  328. return isLt1M;
  329. },
  330. /** 查询广告列表 */
  331. getList() {
  332. this.loading = true;
  333. listAdv(this.queryParams).then(response => {
  334. this.advList = response.rows;
  335. this.total = response.total;
  336. this.loading = false;
  337. });
  338. },
  339. // 取消按钮
  340. cancel() {
  341. this.open = false;
  342. this.reset();
  343. },
  344. // 表单重置
  345. reset() {
  346. this.form = {
  347. advId: null,
  348. advTitle: null,
  349. imageUrl: null,
  350. advUrl: null,
  351. appAdvUrl: null,
  352. content: null,
  353. createTime: null,
  354. updateTime: null,
  355. status: "0",
  356. sort: null,
  357. advType: null,
  358. showType: null,
  359. activeId: null
  360. };
  361. this.resetForm("form");
  362. },
  363. /** 搜索按钮操作 */
  364. handleQuery() {
  365. this.queryParams.pageNum = 1;
  366. this.getList();
  367. },
  368. /** 重置按钮操作 */
  369. resetQuery() {
  370. this.resetForm("queryForm");
  371. this.handleQuery();
  372. },
  373. // 多选框选中数据
  374. handleSelectionChange(selection) {
  375. this.ids = selection.map(item => item.advId)
  376. this.single = selection.length!==1
  377. this.multiple = !selection.length
  378. },
  379. /** 新增按钮操作 */
  380. handleAdd() {
  381. this.reset();
  382. this.open = true;
  383. this.title = "添加广告";
  384. setTimeout(() => {
  385. this.$refs.myeditor.setText("");
  386. }, 100);
  387. },
  388. /** 修改按钮操作 */
  389. handleUpdate(row) {
  390. this.reset();
  391. const advId = row.advId || this.ids
  392. getAdv(advId).then(response => {
  393. this.form = response.data;
  394. this.open = true;
  395. this.title = "修改广告";
  396. this.form.advType = String(this.form.advType)
  397. this.form.showType = String(this.form.showType)
  398. setTimeout(() => {
  399. if(this.form.content==null){
  400. this.$refs.myeditor.setText("");
  401. }
  402. else{
  403. this.$refs.myeditor.setText(this.form.content);
  404. }
  405. }, 1);
  406. });
  407. },
  408. /** 提交按钮 */
  409. submitForm() {
  410. this.$refs["form"].validate(valid => {
  411. if (valid) {
  412. if (this.form.advId != null) {
  413. updateAdv(this.form).then(response => {
  414. this.msgSuccess("修改成功");
  415. this.open = false;
  416. this.getList();
  417. });
  418. } else {
  419. addAdv(this.form).then(response => {
  420. this.msgSuccess("新增成功");
  421. this.open = false;
  422. this.getList();
  423. });
  424. }
  425. }
  426. });
  427. },
  428. /** 删除按钮操作 */
  429. handleDelete(row) {
  430. const advIds = row.advId || this.ids;
  431. this.$confirm('是否确认删除广告编号为"' + advIds + '"的数据项?', "警告", {
  432. confirmButtonText: "确定",
  433. cancelButtonText: "取消",
  434. type: "warning"
  435. }).then(function() {
  436. return delAdv(advIds);
  437. }).then(() => {
  438. this.getList();
  439. this.msgSuccess("删除成功");
  440. }).catch(() => {});
  441. },
  442. /** 导出按钮操作 */
  443. handleExport() {
  444. const queryParams = this.queryParams;
  445. this.$confirm('是否确认导出所有广告数据项?', "警告", {
  446. confirmButtonText: "确定",
  447. cancelButtonText: "取消",
  448. type: "warning"
  449. }).then(() => {
  450. this.exportLoading = true;
  451. return exportAdv(queryParams);
  452. }).then(response => {
  453. this.download(response.msg);
  454. this.exportLoading = false;
  455. }).catch(() => {});
  456. }
  457. }
  458. };
  459. </script>
  460. <style>
  461. .avatar-uploader .el-upload {
  462. border: 1px dashed #d9d9d9;
  463. border-radius: 6px;
  464. cursor: pointer;
  465. position: relative;
  466. overflow: hidden;
  467. }
  468. .avatar-uploader .el-upload:hover {
  469. border-color: #409EFF;
  470. }
  471. .avatar-uploader-icon {
  472. font-size: 28px;
  473. color: #8c939d;
  474. width: 150px;
  475. height: 150px;
  476. line-height: 150px;
  477. text-align: center;
  478. }
  479. </style>