allocation.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!-- 货位 -->
  2. <script>
  3. import { list, refer } from "./api/index";
  4. import { initParams } from "@/utils/init-something";
  5. export default {
  6. name: "AllocationInputDialog",
  7. props: ["title", "value"],
  8. components: {},
  9. data() {
  10. // tree
  11. const columns = [
  12. // {
  13. // key: "deptId",
  14. // title: "仓库编码",
  15. // type: "Input",
  16. // search: true,
  17. // },
  18. // {
  19. // key: "deptName",
  20. // title: "仓库名称",
  21. // type: "Input",
  22. // search: true,
  23. // },
  24. ];
  25. const initTableColumns = () => columns.filter((column) => column.key);
  26. const initSearchColumns = () => columns.filter((column) => column.search);
  27. return {
  28. // global
  29. size: "mini",
  30. width: "50%",
  31. page: { pageNum: 1, pageSize: 25, total: 0 },
  32. pageSizes: [25, 50],
  33. layout: "prev, pager, next, jumper",
  34. api: "puOrg",
  35. showKey: "deptName",
  36. // dialog
  37. visible: false,
  38. loading: false,
  39. // search
  40. searchColumns: initSearchColumns(),
  41. params: initParams(initSearchColumns()),
  42. // table
  43. tableColumns: initTableColumns(),
  44. data: [],
  45. currentData: null,
  46. };
  47. },
  48. computed: {},
  49. watch: {},
  50. methods: {
  51. // set dialog visible
  52. setVisible(prop) {
  53. this.visible = prop;
  54. },
  55. // do something before dialog open
  56. beforeOpen() {
  57. const { value } = this.$props;
  58. this.params[this.showKey] = value;
  59. this.fetchList(this.params, this.page);
  60. },
  61. // fetch table data
  62. async fetchList(prop, page) {
  63. try {
  64. this.loading = true;
  65. const { pageNum, pageSize } = page;
  66. const { code, msg, rows, total } = await refer({
  67. pageNum,
  68. pageSize,
  69. isPage: true,
  70. type: "ALLOCATION_PARAM",
  71. });
  72. // const { code, msg, rows, total } = await list(this.api, {
  73. // ...prop,
  74. // pageNum,
  75. // pageSize,
  76. // });
  77. if (code === 200) {
  78. this.data = rows;
  79. this.page.total = total;
  80. this.$notify.success({ title: msg });
  81. } else {
  82. this.$notify.warning({ title: msg });
  83. }
  84. } catch (err) {
  85. this.$notify.error({ title: "error", message: err });
  86. } finally {
  87. this.loading = false;
  88. this.setCurrentData(
  89. this.data.find(
  90. (column) => column[this.showKey] === this.currentData[this.showKey]
  91. )
  92. );
  93. }
  94. },
  95. // setting up to fetch table data
  96. queryList() {
  97. this.fetchList(this.params, this.page);
  98. },
  99. // reset to fetch table data
  100. resetList() {
  101. this.page.pageNum = 1;
  102. this.params = initParams(this.searchColumns);
  103. this.fetchList(this.params, this.page);
  104. },
  105. // size change to fetch table data
  106. pageSizeChange(prop) {
  107. this.page.pageSize = prop;
  108. this.fetchList(this.params, this.page);
  109. },
  110. // number change to fetch table data
  111. pageNumberChange(prop) {
  112. this.page.pageNum = prop;
  113. this.fetchList(this.params, this.page);
  114. },
  115. // select row data
  116. selectCurrentData(row) {
  117. this.currentData = row;
  118. },
  119. // set row data highlight
  120. setCurrentData(row) {
  121. this.$refs.singleTable.setCurrentRow(row);
  122. },
  123. //
  124. confirm() {
  125. if (this.currentData) {
  126. this.$emit("confirm", this.currentData);
  127. }
  128. this.setVisible(false);
  129. },
  130. },
  131. created() { },
  132. mounted() { },
  133. destroyed() { },
  134. };
  135. </script>
  136. <template>
  137. <el-dialog :title="title" :visible.sync="visible" :width="width" append-to-body @open="beforeOpen">
  138. <el-form :size="size" :inline="true" :model="params">
  139. <el-form-item v-for="(column, index) in searchColumns" :key="index" :label="column.title">
  140. <el-input v-model="params[column.key]" @change="queryList"> </el-input>
  141. </el-form-item>
  142. <el-form-item>
  143. <el-button icon="el-icon-refresh" @click="resetList"></el-button>
  144. </el-form-item>
  145. </el-form>
  146. <el-table v-loading="loading" :data="data" :size="size" ref="singleTable" height="45vh" highlight-current-row
  147. style="width: 100%; margin-bottom: 20px" @row-click="selectCurrentData">
  148. <el-table-column v-for="(column, index) in tableColumns" :key="index" :prop="column.key" :label="column.title"
  149. :width="column.width" show-overflow-tooltip>
  150. </el-table-column>
  151. </el-table>
  152. <div style="display: flex; justify-content: space-between; align-items: center">
  153. <p>
  154. <span style="font-size: 12px">已选择 :</span>
  155. <el-tag v-if="currentData" :size="size">{{
  156. currentData[showKey]
  157. }}</el-tag>
  158. <span v-else>无</span>
  159. </p>
  160. <el-pagination :layout="layout" :total="page.total" :page-sizes="pageSizes" :page-size="page.pageSize"
  161. :current-page="page.pageNum" :small="size === 'mini'" background @size-change="pageSizeChange"
  162. @current-change="pageNumberChange">
  163. </el-pagination>
  164. </div>
  165. <div style="margin-top: 20px; text-align: right">
  166. <el-button :size="size" @click="visible = false">取 消</el-button>
  167. <el-button :size="size" type="primary" @click="confirm">确 定</el-button>
  168. </div>
  169. </el-dialog>
  170. </template>
  171. <style scoped></style>