index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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="cateName">
  5. <el-input
  6. v-model="queryParams.cateName"
  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>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['his:doctorArticleCate:add']"
  37. >新增</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="success"
  42. plain
  43. icon="el-icon-edit"
  44. size="mini"
  45. :disabled="single"
  46. @click="handleUpdate"
  47. v-hasPermi="['his:doctorArticleCate:edit']"
  48. >修改</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="danger"
  53. plain
  54. icon="el-icon-delete"
  55. size="mini"
  56. :disabled="multiple"
  57. @click="handleDelete"
  58. v-hasPermi="['his:doctorArticleCate:remove']"
  59. >删除</el-button>
  60. </el-col>
  61. <el-col :span="1.5">
  62. <el-button
  63. type="warning"
  64. plain
  65. icon="el-icon-download"
  66. size="mini"
  67. :loading="exportLoading"
  68. @click="handleExport"
  69. v-hasPermi="['his:doctorArticleCate:export']"
  70. >导出</el-button>
  71. </el-col>
  72. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  73. </el-row>
  74. <el-table v-loading="loading" :data="doctorArticleCateList" @selection-change="handleSelectionChange" border>
  75. <el-table-column type="selection" width="55" align="center" />
  76. <el-table-column label="ID" align="center" prop="cateId" />
  77. <el-table-column label="图片" align="center" prop="imgUrl" width="120px">
  78. <template slot-scope="scope">
  79. <el-popover
  80. placement="right"
  81. title=""
  82. trigger="hover">
  83. <img slot="reference" :src="scope.row.imgUrl" width="100px">
  84. <img :src="scope.row.imgUrl" style="max-width: 150px;">
  85. </el-popover>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="分类名称" align="center" prop="cateName" />
  89. <el-table-column label="状态" align="center" prop="status">
  90. <template slot-scope="scope">
  91. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="排序号" align="center" prop="sort" />
  95. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  96. <template slot-scope="scope">
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-edit"
  101. @click="handleUpdate(scope.row)"
  102. v-hasPermi="['his:doctorArticleCate:edit']"
  103. >修改</el-button>
  104. <el-button
  105. size="mini"
  106. type="text"
  107. icon="el-icon-delete"
  108. @click="handleDelete(scope.row)"
  109. v-hasPermi="['his:doctorArticleCate:remove']"
  110. >删除</el-button>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. <pagination
  115. v-show="total>0"
  116. :total="total"
  117. :page.sync="queryParams.pageNum"
  118. :limit.sync="queryParams.pageSize"
  119. @pagination="getList"
  120. />
  121. <!-- 添加或修改医生文章分类对话框 -->
  122. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  123. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  124. <el-form-item label="分类名称" prop="cateName">
  125. <el-input v-model="form.cateName" placeholder="请输入分类名称" />
  126. </el-form-item>
  127. <el-form-item label="图片" prop="imgUrl">
  128. <el-upload
  129. v-model="form.imgUrl"
  130. class="avatar-uploader"
  131. :action="uploadUrl"
  132. :headers="uploadHeaders"
  133. :show-file-list="false"
  134. :on-success="handleAvatarSuccess"
  135. :before-upload="beforeAvatarUpload">
  136. <img v-if="form.imgUrl" :src="form.imgUrl" class="avatar" width="300px">
  137. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  138. </el-upload>
  139. </el-form-item>
  140. <el-form-item label="状态" prop="status">
  141. <el-select v-model="form.status" placeholder="请选择状态">
  142. <el-option
  143. v-for="dict in statusOptions"
  144. :key="dict.dictValue"
  145. :label="dict.dictLabel"
  146. :value="parseInt(dict.dictValue)"
  147. ></el-option>
  148. </el-select>
  149. </el-form-item>
  150. <el-form-item label="排序号" prop="sort">
  151. <el-input-number v-model="form.sort" label="请输入排序号"></el-input-number>
  152. </el-form-item>
  153. </el-form>
  154. <div slot="footer" class="dialog-footer">
  155. <el-button type="primary" @click="submitForm">确 定</el-button>
  156. <el-button @click="cancel">取 消</el-button>
  157. </div>
  158. </el-dialog>
  159. </div>
  160. </template>
  161. <script>
  162. import { listDoctorArticleCate, getDoctorArticleCate, delDoctorArticleCate, addDoctorArticleCate, updateDoctorArticleCate, exportDoctorArticleCate } from "@/api/his/doctorArticleCate";
  163. import { getToken } from "@/utils/auth";
  164. export default {
  165. name: "DoctorArticleCate",
  166. data() {
  167. return {
  168. // 遮罩层
  169. loading: true,
  170. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
  171. // el-upload 不会走 axios 拦截器,需手动带上 token
  172. uploadHeaders: { Authorization: "Bearer " + getToken() },
  173. baseUrl: process.env.VUE_APP_BASE_API,
  174. // 导出遮罩层
  175. exportLoading: false,
  176. // 选中数组
  177. ids: [],
  178. // 非单个禁用
  179. single: true,
  180. // 非多个禁用
  181. multiple: true,
  182. // 显示搜索条件
  183. showSearch: true,
  184. // 总条数
  185. total: 0,
  186. // 医生文章分类表格数据
  187. doctorArticleCateList: [],
  188. // 弹出层标题
  189. title: "",
  190. // 是否显示弹出层
  191. open: false,
  192. // 查询参数
  193. queryParams: {
  194. pageNum: 1,
  195. pageSize: 10,
  196. cateName: null,
  197. status: null,
  198. isDel: null,
  199. imgUrl: null,
  200. sort: null
  201. },
  202. // 表单参数
  203. form: {},
  204. // 表单校验
  205. rules: {
  206. cateName: [
  207. { required: true, message: "分类名称不能为空", trigger: "blur" }
  208. ],
  209. status: [
  210. { required: true, message: "状态 1正常 0禁用不能为空", trigger: "change" }
  211. ],
  212. sort: [
  213. { required: true, message: "排序号不能为空", trigger: "blur" }
  214. ]
  215. }
  216. };
  217. },
  218. created() {
  219. this.getList();
  220. this.getDicts("sys_company_status").then(response => {
  221. this.statusOptions = response.data;
  222. });
  223. },
  224. methods: {
  225. /** 查询医生文章分类列表 */
  226. getList() {
  227. this.loading = true;
  228. listDoctorArticleCate(this.queryParams).then(response => {
  229. this.doctorArticleCateList = response.rows;
  230. this.total = response.total;
  231. this.loading = false;
  232. });
  233. },
  234. handleAvatarSuccess(res, file) {
  235. if(res.code==200){
  236. this.form.imgUrl=res.url;
  237. this.$forceUpdate()
  238. }
  239. else{
  240. this.msgError(res.msg);
  241. }
  242. },
  243. beforeAvatarUpload(file) {
  244. // 上传前刷新 token
  245. this.uploadHeaders.Authorization = "Bearer " + getToken();
  246. const isLt1M = file.size / 1024 / 1024 < 1;
  247. if (!isLt1M) {
  248. this.$message.error('上传图片大小不能超过 1MB!');
  249. }
  250. return isLt1M;
  251. },
  252. // 取消按钮
  253. cancel() {
  254. this.open = false;
  255. this.reset();
  256. },
  257. // 表单重置
  258. reset() {
  259. this.form = {
  260. cateId: null,
  261. cateName: null,
  262. status: 0,
  263. isDel: null,
  264. imgUrl: null,
  265. sort: null
  266. };
  267. this.resetForm("form");
  268. },
  269. /** 搜索按钮操作 */
  270. handleQuery() {
  271. this.queryParams.pageNum = 1;
  272. this.getList();
  273. },
  274. /** 重置按钮操作 */
  275. resetQuery() {
  276. this.resetForm("queryForm");
  277. this.handleQuery();
  278. },
  279. // 多选框选中数据
  280. handleSelectionChange(selection) {
  281. this.ids = selection.map(item => item.cateId)
  282. this.single = selection.length!==1
  283. this.multiple = !selection.length
  284. },
  285. /** 新增按钮操作 */
  286. handleAdd() {
  287. this.reset();
  288. this.open = true;
  289. this.title = "添加医生文章分类";
  290. },
  291. /** 修改按钮操作 */
  292. handleUpdate(row) {
  293. this.reset();
  294. const cateId = row.cateId || this.ids
  295. getDoctorArticleCate(cateId).then(response => {
  296. this.form = response.data;
  297. this.open = true;
  298. this.title = "修改医生文章分类";
  299. });
  300. },
  301. /** 提交按钮 */
  302. submitForm() {
  303. this.$refs["form"].validate(valid => {
  304. if (valid) {
  305. if (this.form.cateId != null) {
  306. updateDoctorArticleCate(this.form).then(response => {
  307. this.msgSuccess("修改成功");
  308. this.open = false;
  309. this.getList();
  310. });
  311. } else {
  312. addDoctorArticleCate(this.form).then(response => {
  313. this.msgSuccess("新增成功");
  314. this.open = false;
  315. this.getList();
  316. });
  317. }
  318. }
  319. });
  320. },
  321. /** 删除按钮操作 */
  322. handleDelete(row) {
  323. const cateIds = row.cateId || this.ids;
  324. this.$confirm('是否确认删除医生文章分类编号为"' + cateIds + '"的数据项?', "警告", {
  325. confirmButtonText: "确定",
  326. cancelButtonText: "取消",
  327. type: "warning"
  328. }).then(function() {
  329. return delDoctorArticleCate(cateIds);
  330. }).then(() => {
  331. this.getList();
  332. this.msgSuccess("删除成功");
  333. }).catch(() => {});
  334. },
  335. /** 导出按钮操作 */
  336. handleExport() {
  337. const queryParams = this.queryParams;
  338. this.$confirm('是否确认导出所有医生文章分类数据项?', "警告", {
  339. confirmButtonText: "确定",
  340. cancelButtonText: "取消",
  341. type: "warning"
  342. }).then(() => {
  343. this.exportLoading = true;
  344. return exportDoctorArticleCate(queryParams);
  345. }).then(response => {
  346. this.download(response.msg);
  347. this.exportLoading = false;
  348. }).catch(() => {});
  349. }
  350. }
  351. };
  352. </script>
  353. <style>
  354. .avatar-uploader .el-upload {
  355. border: 1px dashed #d9d9d9;
  356. border-radius: 6px;
  357. cursor: pointer;
  358. position: relative;
  359. overflow: hidden;
  360. }
  361. .avatar-uploader .el-upload:hover {
  362. border-color: #409EFF;
  363. }
  364. .avatar-uploader-icon {
  365. font-size: 28px;
  366. color: #8c939d;
  367. width: 150px;
  368. height: 150px;
  369. line-height: 150px;
  370. text-align: center;
  371. }
  372. </style>