index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <div class="query-box">
  5. <div class="query-box__left">
  6. <el-form-item label="" prop="drugsName">
  7. <el-input v-model="queryParams.drugsName" placeholder="请输入药品名称" clearable size="small" @keyup.enter.native="handleQuery"/>
  8. </el-form-item>
  9. <el-form-item label="" prop="drugsType">
  10. <el-select v-model="queryParams.drugsType" placeholder="请选择药品分类" clearable size="small">
  11. <el-option v-for="item in drugsTypeArr" :key="item.dictValue" :value="item.dictValue" :label="item.dictLabel"></el-option>
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="" prop="drugsSpecsType">
  15. <el-select v-model="queryParams.drugsSpecsType" placeholder="请选择中药类型" clearable size="small">
  16. <el-option v-for="item in chinesMedicineTypeArr" :key="item.dictValue" :value="item.dictValue" :label="item.dictLabel"></el-option>
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  21. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </div>
  24. </div>
  25. </el-form>
  26. <el-table v-loading="loading" :data="inventoryList" @selection-change="handleSelectionChange" border :row-class-name="setBGClass" size="mini">
  27. <el-table-column type="index" width="55" align="center" label="序号"/>
  28. <el-table-column label="药品名称" align="center" prop="drugsName" />
  29. <el-table-column label="药品规格" align="center" prop="specsName" />
  30. <el-table-column label="药品产地" align="center" prop="priceName" />
  31. <el-table-column label="单位" align="center" prop="packingUnit">
  32. <template slot-scope="scope">
  33. <dict-tag :options="unitArr" :value="scope.row.packingUnit" />
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="中药类型" align="center" prop="drugsSpecsType">
  37. <template slot-scope="scope">
  38. <dict-tag :options="chinesMedicineTypeArr" :value="scope.row.drugsSpecsType"></dict-tag>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="库存上限" align="center" prop="stockMax">
  42. <template slot-scope="scope">{{parseInt(scope.row.stockMax)||'-'}}</template>
  43. </el-table-column>
  44. <el-table-column label="库存下限" align="center" prop="stockMin">
  45. <template slot-scope="scope">{{parseInt(scope.row.stockMin)||'-'}}</template>
  46. </el-table-column>
  47. <el-table-column label="修改人" align="center" prop="updateBy" />
  48. <el-table-column label="修改时间" align="center" prop="updateTime" width="148" />
  49. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
  50. <template slot-scope="scope">
  51. <el-button size="mini" type="primary" style="width: 40px" @click="handleUpdate(scope.row)" v-hasPermi="['inventory:inventory:edit']">设置</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
  56. <!-- 添加或修改药品库存对话框 -->
  57. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  58. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  59. <el-form-item label="库存上限" prop="stockMax">
  60. <el-input-number controls-position="right" size="mini" v-model="form.stockMax" placeholder="请输入库存上限" />
  61. </el-form-item>
  62. <el-form-item label="库存下限" prop="stockMin">
  63. <el-input-number controls-position="right" size="mini" v-model="form.stockMin" placeholder="请输入库存下限" />
  64. </el-form-item>
  65. </el-form>
  66. <div slot="footer" class="dialog-footer">
  67. <el-button type="primary" @click="submitForm">确 定</el-button>
  68. <el-button @click="cancel">取 消</el-button>
  69. </div>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. import {
  75. listInventory,
  76. getInventory,
  77. delInventory,
  78. addInventory,
  79. updateInventory,
  80. exportInventory,
  81. } from "@/api/inventory/inventory";
  82. export default {
  83. name: "Inventory",
  84. data() {
  85. return {
  86. drugsTypeArr: [],
  87. chinesMedicineTypeArr: [],
  88. unitArr: [],
  89. // 遮罩层
  90. loading: true,
  91. // 导出遮罩层
  92. exportLoading: false,
  93. // 选中数组
  94. ids: [],
  95. // 非单个禁用
  96. single: true,
  97. // 非多个禁用
  98. multiple: true,
  99. // 显示搜索条件
  100. showSearch: true,
  101. // 总条数
  102. total: 0,
  103. // 药品库存表格数据
  104. inventoryList: [],
  105. // 弹出层标题
  106. title: "",
  107. // 是否显示弹出层
  108. open: false,
  109. // 查询参数
  110. queryParams: {
  111. pageNum: 1,
  112. pageSize: 10,
  113. pharmacyId: window.localStorage.getItem("pharmacyId"),
  114. drugsType: null,
  115. drugsSpecsType: null,
  116. },
  117. // 表单参数
  118. form: {},
  119. // 表单校验
  120. rules: {
  121. pharmacyId: [
  122. { required: true, message: "药房id不能为空", trigger: "blur" },
  123. ],
  124. validTime: [
  125. { required: true, message: "有效时间不能为空", trigger: "blur" },
  126. ],
  127. },
  128. };
  129. },
  130. created() {
  131. this.getDicts("drugs_type").then((response) => {
  132. this.drugsTypeArr = response.data;
  133. });
  134. this.getDicts("chinese_medicine_type").then((response) => {
  135. this.chinesMedicineTypeArr = response.data;
  136. });
  137. this.getDicts("unit").then((response) => {
  138. this.unitArr = response.data;
  139. });
  140. this.getList();
  141. },
  142. methods: {
  143. setBGClass (r) {
  144. if (r.row.stockMin && (r.row.stock < r.row.stockMin)) {
  145. return 'redColumn'
  146. }
  147. if (r.row.stockMax && (r.row.stock > r.row.stockMax)) {
  148. return 'greenColumn'
  149. }
  150. },
  151. /** 查询药品库存列表 */
  152. getList() {
  153. this.loading = true;
  154. listInventory(this.queryParams).then((response) => {
  155. this.inventoryList = response.rows;
  156. this.total = response.total;
  157. this.loading = false;
  158. });
  159. },
  160. // 取消按钮
  161. cancel() {
  162. this.open = false;
  163. //this.reset();
  164. },
  165. // 表单重置
  166. reset() {
  167. this.form = {
  168. id: null,
  169. pharmacyId: window.localStorage.getItem("pharmacyId"),
  170. specsId: null,
  171. priceId: null,
  172. stock: null,
  173. purchasePrice: null,
  174. retailPrice: null,
  175. approvalCode: null,
  176. stockMax: null,
  177. stockMin: null,
  178. site: null,
  179. productionCode: null,
  180. validTime: null,
  181. del: null,
  182. state: null,
  183. createBy: null,
  184. updateBy: null,
  185. createTime: null,
  186. updateTime: null,
  187. };
  188. this.resetForm("form");
  189. },
  190. /** 搜索按钮操作 */
  191. handleQuery() {
  192. this.queryParams.pageNum = 1;
  193. this.getList();
  194. },
  195. /** 重置按钮操作 */
  196. resetQuery() {
  197. this.resetForm("queryForm");
  198. this.handleQuery();
  199. },
  200. // 多选框选中数据
  201. handleSelectionChange(selection) {
  202. this.ids = selection.map((item) => item.id);
  203. this.single = selection.length !== 1;
  204. this.multiple = !selection.length;
  205. },
  206. /** 新增按钮操作 */
  207. handleAdd() {
  208. this.reset();
  209. this.open = true;
  210. this.title = "添加药品库存";
  211. },
  212. /** 修改按钮操作 */
  213. handleUpdate(row) {
  214. this.reset();
  215. const id = row.id || this.ids;
  216. this.open = true;
  217. this.title = "修改药品库存";
  218. this.form = Object.assign({}, row);
  219. // getInventory({ id, pageNum: 1, pageSize: 10 }).then((response) => {
  220. // this.form = response.rows[0];
  221. // //console.log(response.rows);
  222. // });
  223. },
  224. /** 提交按钮 */
  225. submitForm() {
  226. this.$refs["form"].validate((valid) => {
  227. if (valid) {
  228. if (this.form.stockMax < this.form.stockMin) {
  229. return this.msgError('库存上限需大于库存下限')
  230. }
  231. if (this.form.id != null) {
  232. updateInventory({
  233. id: this.form.id,
  234. stockMax: this.form.stockMax,
  235. stockMin: this.form.stockMin
  236. }).then((response) => {
  237. this.msgSuccess("修改成功");
  238. this.open = false;
  239. this.getList();
  240. });
  241. } else {
  242. addInventory(this.form).then((response) => {
  243. this.msgSuccess("新增成功");
  244. this.open = false;
  245. this.getList();
  246. });
  247. }
  248. }
  249. });
  250. },
  251. /** 删除按钮操作 */
  252. handleDelete(row) {
  253. const ids = row.id || this.ids;
  254. this.$confirm(
  255. '确定需要删除选中数据吗?',
  256. "警告",
  257. {
  258. confirmButtonText: "确定",
  259. cancelButtonText: "取消",
  260. type: "warning",
  261. }
  262. )
  263. .then(function () {
  264. return delInventory(ids);
  265. })
  266. .then(() => {
  267. this.getList();
  268. this.msgSuccess("删除成功");
  269. })
  270. .catch(() => {});
  271. },
  272. /** 导出按钮操作 */
  273. async handleExport() {
  274. this.exportLoading = true;
  275. try {
  276. await this.$confirm("是否确认导出所有药品库存数据项?", "警告", {
  277. confirmButtonText: "确定",
  278. cancelButtonText: "取消",
  279. type: "warning",
  280. });
  281. const data = await exportInventory(this.queryParams)
  282. this.$message.success(`导出 ${data.name} 成功`);
  283. } catch (e) {}
  284. this.exportLoading = false;
  285. },
  286. },
  287. };
  288. </script>
  289. <style>
  290. .redColumn, .redColumn:hover, .el-table__body tr.redColumn.hover-row > td {
  291. background: #F56C6C!important;
  292. color: #fff!important;
  293. }
  294. .greenColumn, .greenColumn:hover, .el-table__body tr.greenColumn.hover-row > td {
  295. background: #67C23A!important;
  296. color: #fff!important;
  297. }
  298. </style>