customer.vue 5.1 KB

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