index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div class="search">
  3. <Row>
  4. <Col>
  5. <Card>
  6. <Row @keydown.enter.native="handleSearch"> </Row>
  7. <Row class="operation">
  8. <Button @click="add" type="primary" >添加</Button>
  9. <Button @click="delAll">批量删除</Button>
  10. </Row>
  11. <Row>
  12. <Table
  13. :loading="loading"
  14. border
  15. :columns="columns"
  16. :data="data"
  17. ref="table"
  18. sortable="custom"
  19. @on-sort-change="changeSort"
  20. @on-selection-change="changeSelect"
  21. ></Table>
  22. </Row>
  23. <Row type="flex" justify="end" class="page">
  24. <Page
  25. :current="searchForm.pageNumber"
  26. :total="total"
  27. :page-size="searchForm.pageSize"
  28. @on-change="changePage"
  29. @on-page-size-change="changePageSize"
  30. :page-size-opts="[10, 20, 50]"
  31. size="small"
  32. show-total
  33. show-elevator
  34. show-sizer
  35. ></Page>
  36. </Row>
  37. </Card>
  38. </Col>
  39. </Row>
  40. <Modal
  41. :title="modalTitle"
  42. v-model="modalVisible"
  43. :mask-closable="false"
  44. :width="500"
  45. >
  46. <Form ref="form" :model="form" :label-width="100" :rules="formValidate">
  47. <FormItem label="计量单位" prop="name">
  48. <Input v-model="form.name" clearable style="width: 100%" />
  49. </FormItem>
  50. </Form>
  51. <div slot="footer">
  52. <Button type="text" @click="modalVisible = false">取消</Button>
  53. <Button type="primary" :loading="submitLoading" @click="handleSubmit"
  54. >提交</Button
  55. >
  56. </div>
  57. </Modal>
  58. </div>
  59. </template>
  60. <script>
  61. import {
  62. addGoodsUnit,
  63. getGoodsUnitPage,
  64. updateGoodsUnit,
  65. delGoodsUnit, delSensitive,
  66. } from "@/api/index";
  67. export default {
  68. name: "bill",
  69. components: {},
  70. data() {
  71. return {
  72. loading: true, // 表单加载状态
  73. modalType: 0, // 添加或编辑标识
  74. modalVisible: false, // 添加或编辑显示
  75. modalTitle: "", // 添加或编辑标题
  76. searchForm: {
  77. // 搜索框初始化对象
  78. pageNumber: 1, // 当前页数
  79. pageSize: 10, // 页面大小
  80. sort: "createTime", // 默认排序字段
  81. order: "desc", // 默认排序方式
  82. name: "",
  83. },
  84. form: {
  85. // 添加或编辑表单对象初始化数据
  86. name: "",
  87. },
  88. // 表单验证规则
  89. formValidate: {
  90. name: [
  91. {
  92. required: true,
  93. message: "请输入计量单位",
  94. trigger: "blur",
  95. },
  96. ],
  97. },
  98. submitLoading: false, // 添加或编辑提交状态
  99. selectList: [], // 多选数据
  100. selectCount: 0, // 多选计数
  101. columns: [
  102. // 表头
  103. {
  104. type: "selection",
  105. width: 60,
  106. align: "center",
  107. },
  108. {
  109. title: "计量单位",
  110. key: "name",
  111. minWidth: 120
  112. },
  113. {
  114. title: "创建时间",
  115. key: "createTime",
  116. width: 180
  117. },
  118. {
  119. title: "更新时间",
  120. key: "updateTime",
  121. width: 180
  122. },
  123. {
  124. title: "操作人",
  125. key: "createBy",
  126. minWidth: 150
  127. },
  128. {
  129. title: "操作",
  130. key: "action",
  131. align: "center",
  132. width: 200,
  133. render: (h, params) => {
  134. return h("div", [
  135. h(
  136. "Button",
  137. {
  138. props: {
  139. type: "info",
  140. size: "small",
  141. },
  142. style: {
  143. marginRight: "5px",
  144. },
  145. on: {
  146. click: () => {
  147. this.detail(params.row);
  148. },
  149. },
  150. },
  151. "修改"
  152. ),
  153. h(
  154. "Button",
  155. {
  156. props: {
  157. type: "error",
  158. size: "small",
  159. },
  160. style: {
  161. marginRight: "5px",
  162. },
  163. on: {
  164. click: () => {
  165. this.remove(params.row);
  166. },
  167. },
  168. },
  169. "删除"
  170. ),
  171. ]);
  172. },
  173. },
  174. ],
  175. data: [], // 表单数据
  176. total: 0, // 表单数据总数
  177. };
  178. },
  179. methods: {
  180. init() {
  181. this.getDataList();
  182. },
  183. changePage(v) {
  184. this.searchForm.pageNumber = v;
  185. this.getDataList();
  186. this.clearSelectAll();
  187. },
  188. changePageSize(v) {
  189. this.searchForm.pageSize = v;
  190. this.getDataList();
  191. },
  192. handleSearch() {
  193. this.searchForm.pageNumber = 1;
  194. this.searchForm.pageSize = 10;
  195. this.getDataList();
  196. },
  197. handleReset() {
  198. this.$refs.searchForm.resetFields();
  199. this.searchForm.pageNumber = 1;
  200. this.searchForm.pageSize = 10;
  201. // 重新加载数据
  202. this.getDataList();
  203. },
  204. changeSort(e) {
  205. this.searchForm.sort = e.key;
  206. this.searchForm.order = e.order;
  207. if (e.order === "normal") {
  208. this.searchForm.order = "";
  209. }
  210. this.getDataList();
  211. },
  212. clearSelectAll() {
  213. this.$refs.table.selectAll(false);
  214. },
  215. changeSelect(e) {
  216. this.selectList = e;
  217. this.selectCount = e.length;
  218. },
  219. getDataList() {
  220. this.loading = true;
  221. getGoodsUnitPage(this.searchForm).then((res) => {
  222. this.loading = false;
  223. if (res.success) {
  224. this.data = res.result.records;
  225. this.total = res.result.total;
  226. }
  227. });
  228. this.total = this.data.length;
  229. this.loading = false;
  230. },
  231. handleSubmit() {
  232. this.$refs.form.validate((valid) => {
  233. if (valid) {
  234. this.submitLoading = true;
  235. if (this.modalType == 0) {
  236. // 添加 避免编辑后传入id等数据 记得删除
  237. delete this.form.id;
  238. addGoodsUnit(this.form).then((res) => {
  239. this.submitLoading = false;
  240. if (res.success) {
  241. this.$Message.success("操作成功");
  242. this.getDataList();
  243. this.modalVisible = false;
  244. }
  245. });
  246. } else {
  247. // 编辑
  248. updateGoodsUnit(this.id, this.form).then((res) => {
  249. this.submitLoading = false;
  250. if (res.success) {
  251. this.$Message.success("操作成功");
  252. this.getDataList();
  253. this.modalVisible = false;
  254. }
  255. });
  256. }
  257. }
  258. });
  259. },
  260. add() {
  261. this.modalType = 0;
  262. this.modalTitle = "添加";
  263. this.form = {};
  264. this.$refs.form.resetFields();
  265. this.modalVisible = true;
  266. },
  267. detail(v) {
  268. this.modalType = 1;
  269. this.id = v.id;
  270. this.modalTitle = "修改";
  271. this.modalVisible = true;
  272. this.form.name = v.name;
  273. },
  274. remove(v) {
  275. this.$Modal.confirm({
  276. title: "确认删除",
  277. // 记得确认修改此处
  278. content: "您确认要删除 " + v.name + " ?",
  279. loading: true,
  280. onOk: () => {
  281. // 删除
  282. delGoodsUnit(v.id).then((res) => {
  283. this.$Modal.remove();
  284. if (res.success) {
  285. this.$Message.success("操作成功");
  286. this.getDataList();
  287. }
  288. });
  289. },
  290. });
  291. },
  292. delAll() {
  293. if (this.selectCount <= 0) {
  294. this.$Message.warning("您还未选择要删除的数据");
  295. return;
  296. }
  297. this.$Modal.confirm({
  298. title: "确认删除",
  299. content: "您确认要删除所选的 " + this.selectCount + " 条数据?",
  300. loading: true,
  301. onOk: () => {
  302. let ids = "";
  303. this.selectList.forEach(function (e) {
  304. ids += e.id + ",";
  305. });
  306. ids = ids.substring(0, ids.length - 1);
  307. // 批量删除
  308. delGoodsUnit(ids).then((res) => {
  309. this.$Modal.remove();
  310. if (res.success) {
  311. this.$Message.success("操作成功");
  312. this.clearSelectAll();
  313. this.getDataList();
  314. }
  315. });
  316. },
  317. });
  318. },
  319. },
  320. mounted() {
  321. this.init();
  322. },
  323. };
  324. </script>
  325. <style lang="scss">
  326. // 建议引入通用样式 可删除下面样式代码
  327. @import "@/styles/table-common.scss";
  328. </style>