index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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="foodName">
  5. <el-input
  6. v-model="queryParams.foodName"
  7. placeholder="请输入药膳名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="创建时间" prop="createTime">
  14. <el-date-picker clearable size="small"
  15. v-model="queryParams.createTime"
  16. type="date"
  17. value-format="yyyy-MM-dd"
  18. placeholder="选择创建时间">
  19. </el-date-picker>
  20. </el-form-item>
  21. <el-form-item label="状态" prop="status">
  22. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  23. <el-option
  24. v-for="dict in statusOptions"
  25. :key="dict.dictValue"
  26. :label="dict.dictLabel"
  27. :value="dict.dictValue"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  33. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. <el-row :gutter="10" class="mb8">
  37. <el-col :span="1.5">
  38. <el-button
  39. type="primary"
  40. plain
  41. icon="el-icon-plus"
  42. size="mini"
  43. @click="handleAdd"
  44. v-hasPermi="['his:medicatedFood:add']"
  45. >新增</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="success"
  50. plain
  51. icon="el-icon-edit"
  52. size="mini"
  53. :disabled="single"
  54. @click="handleUpdate"
  55. v-hasPermi="['his:medicatedFood:edit']"
  56. >修改</el-button>
  57. </el-col>
  58. <el-col :span="1.5">
  59. <el-button
  60. type="danger"
  61. plain
  62. icon="el-icon-delete"
  63. size="mini"
  64. :disabled="multiple"
  65. @click="handleDelete"
  66. v-hasPermi="['his:medicatedFood:remove']"
  67. >删除</el-button>
  68. </el-col>
  69. <el-col :span="1.5">
  70. <el-button
  71. type="warning"
  72. plain
  73. icon="el-icon-download"
  74. size="mini"
  75. :loading="exportLoading"
  76. @click="handleExport"
  77. v-hasPermi="['his:medicatedFood:export']"
  78. >导出</el-button>
  79. </el-col>
  80. <el-col :span="1.5">
  81. <el-button
  82. type="info"
  83. plain
  84. icon="el-icon-upload2"
  85. size="mini"
  86. @click="handleImport"
  87. >导入</el-button>
  88. </el-col>
  89. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  90. </el-row>
  91. <el-table height="660" v-loading="loading" :data="medicatedFoodList" @selection-change="handleSelectionChange">
  92. <el-table-column type="selection" width="55" align="center" />
  93. <el-table-column label="图片" align="center" prop="imgUrl" >
  94. <template slot-scope="scope">
  95. <el-popover
  96. placement="right"
  97. title=""
  98. trigger="hover">
  99. <img slot="reference" :src="scope.row.imgUrl" width="100px">
  100. <img :src="scope.row.imgUrl" style="max-width: 150px;">
  101. </el-popover>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="药膳名称" align="center" prop="foodName" />
  105. <el-table-column label="排序" align="center" prop="sort" />
  106. <el-table-column label="功效" align="center" prop="action" show-overflow-tooltip/>
  107. <el-table-column label="食材" align="center" prop="food" show-overflow-tooltip/>
  108. <el-table-column label="主治疾病" align="center" prop="indications" show-overflow-tooltip/>
  109. <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
  110. <el-table-column label="状态" align="center" prop="status">
  111. <template slot-scope="scope">
  112. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  116. <template slot-scope="scope">
  117. <el-button
  118. size="mini"
  119. type="text"
  120. icon="el-icon-edit"
  121. @click="handleUpdate(scope.row)"
  122. v-hasPermi="['his:medicatedFood:edit']"
  123. >修改</el-button>
  124. <el-button
  125. size="mini"
  126. type="text"
  127. @click="handledetails(scope.row)"
  128. >详情
  129. </el-button>
  130. <el-button
  131. size="mini"
  132. type="text"
  133. icon="el-icon-delete"
  134. @click="handleDelete(scope.row)"
  135. v-hasPermi="['his:medicatedFood:remove']"
  136. >删除</el-button>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. <pagination
  141. v-show="total>0"
  142. :total="total"
  143. :page.sync="queryParams.pageNum"
  144. :limit.sync="queryParams.pageSize"
  145. @pagination="getList"
  146. />
  147. <!-- 添加或修改药膳食疗对话框 -->
  148. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  149. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  150. <el-form-item label="图片" prop="imgUrl">
  151. <el-upload
  152. v-model="form.imgUrl"
  153. class="avatar-uploader"
  154. :action="uploadUrl"
  155. :show-file-list="false"
  156. :on-success="handleAvatarSuccess"
  157. :before-upload="beforeAvatarUpload">
  158. <img v-if="form.imgUrl" :src="form.imgUrl" class="avatar" width="200px">
  159. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  160. </el-upload>
  161. </el-form-item>
  162. <el-form-item label="药膳名称" prop="foodName">
  163. <el-input v-model="form.foodName" placeholder="请输入药膳名称" />
  164. </el-form-item>
  165. <el-form-item label="拼音" prop="pinyin">
  166. <el-input v-model="form.pinyin" placeholder="请输入拼音" />
  167. </el-form-item>
  168. <el-form-item label="功效概述" prop="pinyin">
  169. <el-input v-model="form.actionTitle" placeholder="请输入功效概述" />
  170. </el-form-item>
  171. <el-form-item label="排序" prop="sort">
  172. <el-input-number v-model="form.sort" :min="0" label="请输入排序"></el-input-number>
  173. </el-form-item>
  174. <el-form-item label="功效" prop="action">
  175. <el-select v-model="form.action" placeholder="请选择功效">
  176. <el-option
  177. v-for="dict in actionOptions"
  178. :key="dict.dictValue"
  179. :label="dict.dictLabel"
  180. :value="dict.dictValue"
  181. />
  182. </el-select>
  183. </el-form-item>
  184. <el-form-item label="食材" prop="food">
  185. <el-select v-model="form.food" placeholder="请选择食材">
  186. <el-option
  187. v-for="dict in foodOptions"
  188. :key="dict.dictValue"
  189. :label="dict.dictLabel"
  190. :value="dict.dictValue"
  191. />
  192. </el-select>
  193. </el-form-item>
  194. <el-form-item label="疾病" prop="indications">
  195. <el-select v-model="form.indications" placeholder="请选择疾病">
  196. <el-option
  197. v-for="dict in indicationOptions"
  198. :key="dict.dictValue"
  199. :label="dict.dictLabel"
  200. :value="dict.dictValue"
  201. />
  202. </el-select>
  203. </el-form-item>
  204. <el-form-item label="描述">
  205. <Editor ref="myeditor" @on-text-change="updateText"/>
  206. </el-form-item>
  207. <el-form-item label="状态">
  208. <el-radio-group v-model="form.status">
  209. <el-radio
  210. v-for="dict in statusOptions"
  211. :key="dict.dictValue"
  212. :label="parseInt(dict.dictValue)"
  213. >{{dict.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. <el-drawer
  223. :with-header="false"
  224. size="75%"
  225. :title="show.title" :visible.sync="show.open">
  226. <medicatedFoodDetails ref="Details" />
  227. </el-drawer>
  228. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  229. <el-upload
  230. ref="upload"
  231. :limit="1"
  232. accept=".xlsx, .xls"
  233. :headers="upload.headers"
  234. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  235. :disabled="upload.isUploading"
  236. :on-progress="handleFileUploadProgress"
  237. :on-success="handleFileSuccess"
  238. :auto-upload="false"
  239. drag
  240. >
  241. <i class="el-icon-upload"></i>
  242. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  243. <div class="el-upload__tip text-center" slot="tip">
  244. <div class="el-upload__tip" slot="tip">
  245. <!-- <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的数据 -->
  246. </div>
  247. <span>仅允许导入xls、xlsx格式文件。</span>
  248. <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
  249. </div>
  250. </el-upload>
  251. <div slot="footer" class="dialog-footer">
  252. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  253. <el-button @click="upload.open = false">取 消</el-button>
  254. </div>
  255. </el-dialog>
  256. </div>
  257. </template>
  258. <script>
  259. import { listMedicatedFood, getMedicatedFood, delMedicatedFood, addMedicatedFood,importTemplate, updateMedicatedFood, exportMedicatedFood } from "@/api/his/medicatedFood";
  260. import medicatedFoodDetails from '../../components/his/medicatedFoodDetails.vue';
  261. import Editor from '@/components/Editor/wang';
  262. import { getToken } from "@/utils/auth";
  263. export default {
  264. name: "MedicatedFood",
  265. components: { Editor ,medicatedFoodDetails},
  266. data() {
  267. return {
  268. show:{
  269. open:false,
  270. },
  271. upload: {
  272. // 是否显示弹出层
  273. open: false,
  274. // 弹出层标题
  275. title: "",
  276. // 是否禁用上传
  277. isUploading: false,
  278. // 是否更新已经存在的用户数据
  279. updateSupport: 0,
  280. // 设置上传的请求头部
  281. headers: { Authorization: "Bearer " + getToken() },
  282. // 上传的地址
  283. url: process.env.VUE_APP_BASE_API + "/his/medicatedFood/importData"
  284. },
  285. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
  286. baseUrl: process.env.VUE_APP_BASE_API,
  287. // 遮罩层
  288. loading: true,
  289. // 导出遮罩层
  290. exportLoading: false,
  291. // 选中数组
  292. ids: [],
  293. // 非单个禁用
  294. single: true,
  295. // 非多个禁用
  296. multiple: true,
  297. // 显示搜索条件
  298. showSearch: true,
  299. // 总条数
  300. total: 0,
  301. // 药膳食疗表格数据
  302. medicatedFoodList: [],
  303. // 弹出层标题
  304. title: "",
  305. // 是否显示弹出层
  306. open: false,
  307. // 状态字典
  308. statusOptions: [],
  309. // 查询参数
  310. queryParams: {
  311. pageNum: 1,
  312. pageSize: 10,
  313. foodName: null,
  314. imgUrl: null,
  315. sort: null,
  316. action: null,
  317. food: null,
  318. indications: null,
  319. descs: null,
  320. createTime: null,
  321. status: null
  322. },
  323. // 表单参数
  324. form: {},
  325. // 表单校验
  326. rules: {
  327. foodName: [
  328. { required: true, message: '请输入药膳名称', trigger: 'blur' },
  329. ],
  330. pinyin: [
  331. { required: true, message: '请输入拼音', trigger: 'blur' },
  332. ],
  333. imgUrl: [
  334. { required: true, message: '请上传图片', trigger: 'change' },
  335. ],
  336. sort: [
  337. { required: true, type: 'number', message: '请输入排序', trigger: 'blur' },
  338. ],
  339. // action: [
  340. // { required: true, message: '请输入功效', trigger: 'blur' },
  341. // ],
  342. // food: [
  343. // { required: true, message: '请输入食材', trigger: 'blur' },
  344. // ],
  345. // indications: [
  346. // { required: true, message: '请输入疾病', trigger: 'blur' },
  347. // ],
  348. status: [
  349. { required: true, message: '请选择状态', trigger: 'change' },
  350. ],
  351. },
  352. foodOptions:null,
  353. actionOptions:null,
  354. indicationOptions:null,
  355. };
  356. },
  357. created() {
  358. this.getList();
  359. this.getDicts("sys_company_status").then(response => {
  360. this.statusOptions = response.data;
  361. });
  362. this.getDicts("sys_medicated_food").then(response => {
  363. this.foodOptions = response.data;
  364. });
  365. this.getDicts("sys_medicated_food_action").then(response => {
  366. this.actionOptions = response.data;
  367. });
  368. this.getDicts("sys_indication").then(response => {
  369. this.indicationOptions = response.data;
  370. });
  371. },
  372. methods: {
  373. handledetails(row){
  374. this.show.open=true;
  375. setTimeout(() => {
  376. this.$refs.Details.getDetails(row.id);
  377. }, 1);
  378. },
  379. handleAvatarSuccess(res, file) {
  380. if(res.code==200){
  381. this.form.imgUrl=res.url;
  382. self.$forceUpdate()
  383. }
  384. else{
  385. this.msgError(res.msg);
  386. }
  387. },
  388. updateText(text){
  389. this.form.descs=text
  390. },
  391. beforeAvatarUpload(file) {
  392. const isLt1M = file.size / 1024 / 1024 < 1;
  393. if (!isLt1M) {
  394. this.$message.error('上传图片大小不能超过 1MB!');
  395. }
  396. return isLt1M;
  397. },
  398. /** 查询药膳食疗列表 */
  399. getList() {
  400. this.loading = true;
  401. listMedicatedFood(this.queryParams).then(response => {
  402. this.medicatedFoodList = response.rows;
  403. this.total = response.total;
  404. this.loading = false;
  405. });
  406. },
  407. // 取消按钮
  408. cancel() {
  409. this.open = false;
  410. this.reset();
  411. },
  412. // 表单重置
  413. reset() {
  414. this.form = {
  415. id: null,
  416. foodName: null,
  417. imgUrl: null,
  418. sort: null,
  419. action: null,
  420. food: null,
  421. indications: null,
  422. descs: null,
  423. createTime: null,
  424. status: 0
  425. };
  426. this.resetForm("form");
  427. },
  428. /** 搜索按钮操作 */
  429. handleQuery() {
  430. this.queryParams.pageNum = 1;
  431. this.getList();
  432. },
  433. /** 重置按钮操作 */
  434. resetQuery() {
  435. this.resetForm("queryForm");
  436. this.handleQuery();
  437. },
  438. // 多选框选中数据
  439. handleSelectionChange(selection) {
  440. this.ids = selection.map(item => item.id)
  441. this.single = selection.length!==1
  442. this.multiple = !selection.length
  443. },
  444. /** 新增按钮操作 */
  445. handleAdd() {
  446. this.reset();
  447. this.open = true;
  448. setTimeout(() => {
  449. this.$refs.myeditor.setText("");
  450. }, 500);
  451. this.title = "添加药膳食疗";
  452. },
  453. /** 修改按钮操作 */
  454. handleUpdate(row) {
  455. this.reset();
  456. const id = row.id || this.ids
  457. getMedicatedFood(id).then(response => {
  458. this.form = response.data;
  459. this.open = true;
  460. setTimeout(() => {
  461. if(this.form.descs==null){
  462. this.$refs.myeditor.setText("");
  463. }
  464. else{
  465. this.$refs.myeditor.setText(this.form.descs);
  466. }
  467. }, 1);
  468. this.title = "修改药膳食疗";
  469. });
  470. },
  471. /** 导入按钮操作 */
  472. handleImport() {
  473. this.upload.title = "导入";
  474. this.upload.open = true;
  475. },
  476. /** 下载模板操作 */
  477. importTemplate() {
  478. importTemplate().then(response => {
  479. this.download(response.msg);
  480. });
  481. },
  482. // 文件上传中处理
  483. handleFileUploadProgress(event, file, fileList) {
  484. this.upload.isUploading = true;
  485. },
  486. // 文件上传成功处理
  487. handleFileSuccess(response, file, fileList) {
  488. this.upload.open = false;
  489. this.upload.isUploading = false;
  490. this.$refs.upload.clearFiles();
  491. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  492. this.getList();
  493. },
  494. // 提交上传文件
  495. submitFileForm() {
  496. this.$refs.upload.submit();
  497. },
  498. /** 提交按钮 */
  499. submitForm() {
  500. this.$refs["form"].validate(valid => {
  501. if (valid) {
  502. if (this.form.id != null) {
  503. updateMedicatedFood(this.form).then(response => {
  504. this.msgSuccess("修改成功");
  505. this.open = false;
  506. this.getList();
  507. });
  508. } else {
  509. addMedicatedFood(this.form).then(response => {
  510. this.msgSuccess("新增成功");
  511. this.open = false;
  512. this.getList();
  513. });
  514. }
  515. }
  516. });
  517. },
  518. /** 删除按钮操作 */
  519. handleDelete(row) {
  520. const ids = row.id || this.ids;
  521. this.$confirm('是否确认删除药膳食疗编号为"' + ids + '"的数据项?', "警告", {
  522. confirmButtonText: "确定",
  523. cancelButtonText: "取消",
  524. type: "warning"
  525. }).then(function() {
  526. return delMedicatedFood(ids);
  527. }).then(() => {
  528. this.getList();
  529. this.msgSuccess("删除成功");
  530. }).catch(() => {});
  531. },
  532. /** 导出按钮操作 */
  533. handleExport() {
  534. const queryParams = this.queryParams;
  535. this.$confirm('是否确认导出所有药膳食疗数据项?', "警告", {
  536. confirmButtonText: "确定",
  537. cancelButtonText: "取消",
  538. type: "warning"
  539. }).then(() => {
  540. this.exportLoading = true;
  541. return exportMedicatedFood(queryParams);
  542. }).then(response => {
  543. this.download(response.msg);
  544. this.exportLoading = false;
  545. }).catch(() => {});
  546. }
  547. }
  548. };
  549. </script>
  550. <style>
  551. .avatar-uploader .el-upload {
  552. border: 1px dashed #d9d9d9;
  553. border-radius: 6px;
  554. cursor: pointer;
  555. position: relative;
  556. overflow: hidden;
  557. }
  558. .avatar-uploader .el-upload:hover {
  559. border-color: #409EFF;
  560. }
  561. .avatar-uploader-icon {
  562. font-size: 28px;
  563. color: #8c939d;
  564. width: 150px;
  565. height: 150px;
  566. line-height: 150px;
  567. text-align: center;
  568. }
  569. </style>