index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. plain
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['zdsz:unit:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="success"
  31. plain
  32. icon="el-icon-edit"
  33. size="mini"
  34. :disabled="single"
  35. @click="handleUpdate"
  36. v-hasPermi="['zdsz:unit:edit']"
  37. >修改</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="danger"
  42. plain
  43. icon="el-icon-delete"
  44. size="mini"
  45. :disabled="multiple"
  46. @click="handleDelete"
  47. v-hasPermi="['zdsz:unit:remove']"
  48. >删除</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="warning"
  53. plain
  54. icon="el-icon-download"
  55. size="mini"
  56. @click="handleExport"
  57. v-hasPermi="['zdsz:unit:export']"
  58. >导出</el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="unitList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center" />
  64. <el-table-column label="" align="center" prop="id" v-if="true"/>
  65. <el-table-column label="" align="center" prop="areaId" />
  66. <el-table-column label="" align="center" prop="buildingId" />
  67. <el-table-column label="" align="center" prop="name" />
  68. <el-table-column label="备注" align="center" prop="remark" />
  69. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  70. <template slot-scope="scope">
  71. <el-button
  72. size="mini"
  73. type="text"
  74. icon="el-icon-edit"
  75. @click="handleUpdate(scope.row)"
  76. v-hasPermi="['zdsz:unit:edit']"
  77. >修改</el-button>
  78. <el-button
  79. size="mini"
  80. type="text"
  81. icon="el-icon-delete"
  82. @click="handleDelete(scope.row)"
  83. v-hasPermi="['zdsz:unit:remove']"
  84. >删除</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <pagination
  89. v-show="total>0"
  90. :total="total"
  91. :page.sync="queryParams.pageNum"
  92. :limit.sync="queryParams.pageSize"
  93. @pagination="getList"
  94. />
  95. <!-- 添加或修改单元管理对话框 -->
  96. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  97. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  98. <el-form-item label="" prop="name">
  99. <el-input v-model="form.name" placeholder="请输入" />
  100. </el-form-item>
  101. <el-form-item label="备注" prop="remark">
  102. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  103. </el-form-item>
  104. </el-form>
  105. <div slot="footer" class="dialog-footer">
  106. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  107. <el-button @click="cancel">取 消</el-button>
  108. </div>
  109. </el-dialog>
  110. </div>
  111. </template>
  112. <script>
  113. import { listUnit, getUnit, delUnit, addUnit, updateUnit } from "@/api/zdsz/unit";
  114. export default {
  115. name: "Unit",
  116. data() {
  117. return {
  118. // 按钮loading
  119. buttonLoading: false,
  120. // 遮罩层
  121. loading: true,
  122. // 选中数组
  123. ids: [],
  124. // 非单个禁用
  125. single: true,
  126. // 非多个禁用
  127. multiple: true,
  128. // 显示搜索条件
  129. showSearch: true,
  130. // 总条数
  131. total: 0,
  132. // 单元管理表格数据
  133. unitList: [],
  134. // 弹出层标题
  135. title: "",
  136. // 是否显示弹出层
  137. open: false,
  138. // 查询参数
  139. queryParams: {
  140. pageNum: 1,
  141. pageSize: 10,
  142. areaId: undefined,
  143. buildingId: undefined,
  144. name: undefined,
  145. },
  146. // 表单参数
  147. form: {},
  148. // 表单校验
  149. rules: {
  150. id: [
  151. { required: true, message: "不能为空", trigger: "blur" }
  152. ],
  153. areaId: [
  154. { required: true, message: "不能为空", trigger: "change" }
  155. ],
  156. buildingId: [
  157. { required: true, message: "不能为空", trigger: "change" }
  158. ],
  159. name: [
  160. { required: true, message: "不能为空", trigger: "blur" }
  161. ],
  162. remark: [
  163. { required: true, message: "备注不能为空", trigger: "blur" }
  164. ],
  165. }
  166. };
  167. },
  168. created() {
  169. this.getList();
  170. },
  171. methods: {
  172. /** 查询单元管理列表 */
  173. getList() {
  174. this.loading = true;
  175. listUnit(this.queryParams).then(response => {
  176. this.unitList = response.rows;
  177. this.total = response.total;
  178. this.loading = false;
  179. });
  180. },
  181. // 取消按钮
  182. cancel() {
  183. this.open = false;
  184. this.reset();
  185. },
  186. // 表单重置
  187. reset() {
  188. this.form = {
  189. id: undefined,
  190. areaId: undefined,
  191. buildingId: undefined,
  192. name: undefined,
  193. remark: undefined,
  194. delFlag: undefined,
  195. createBy: undefined,
  196. createTime: undefined,
  197. updateBy: undefined,
  198. updateTime: undefined
  199. };
  200. this.resetForm("form");
  201. },
  202. /** 搜索按钮操作 */
  203. handleQuery() {
  204. this.queryParams.pageNum = 1;
  205. this.getList();
  206. },
  207. /** 重置按钮操作 */
  208. resetQuery() {
  209. this.resetForm("queryForm");
  210. this.handleQuery();
  211. },
  212. // 多选框选中数据
  213. handleSelectionChange(selection) {
  214. this.ids = selection.map(item => item.id)
  215. this.single = selection.length!==1
  216. this.multiple = !selection.length
  217. },
  218. /** 新增按钮操作 */
  219. handleAdd() {
  220. this.reset();
  221. this.open = true;
  222. this.title = "添加单元管理";
  223. },
  224. /** 修改按钮操作 */
  225. handleUpdate(row) {
  226. this.loading = true;
  227. this.reset();
  228. const id = row.id || this.ids
  229. getUnit(id).then(response => {
  230. this.loading = false;
  231. this.form = response.data;
  232. this.open = true;
  233. this.title = "修改单元管理";
  234. });
  235. },
  236. /** 提交按钮 */
  237. submitForm() {
  238. this.$refs["form"].validate(valid => {
  239. if (valid) {
  240. this.buttonLoading = true;
  241. if (this.form.id != null) {
  242. updateUnit(this.form).then(response => {
  243. this.$modal.msgSuccess("修改成功");
  244. this.open = false;
  245. this.getList();
  246. }).finally(() => {
  247. this.buttonLoading = false;
  248. });
  249. } else {
  250. addUnit(this.form).then(response => {
  251. this.$modal.msgSuccess("新增成功");
  252. this.open = false;
  253. this.getList();
  254. }).finally(() => {
  255. this.buttonLoading = false;
  256. });
  257. }
  258. }
  259. });
  260. },
  261. /** 删除按钮操作 */
  262. handleDelete(row) {
  263. const ids = row.id || this.ids;
  264. this.$modal.confirm('是否确认删除单元管理编号为"' + ids + '"的数据项?').then(() => {
  265. this.loading = true;
  266. return delUnit(ids);
  267. }).then(() => {
  268. this.loading = false;
  269. this.getList();
  270. this.$modal.msgSuccess("删除成功");
  271. }).catch(() => {
  272. }).finally(() => {
  273. this.loading = false;
  274. });
  275. },
  276. /** 导出按钮操作 */
  277. handleExport() {
  278. this.download('zdsz/unit/export', {
  279. ...this.queryParams
  280. }, `unit_${new Date().getTime()}.xlsx`)
  281. }
  282. }
  283. };
  284. </script>