index.vue 16 KB

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