main.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <!-- 中文下拉 -->
  3. <div>
  4. <div style="display: flex;">
  5. <el-select v-model="value" @input="$emit('selectedValue', value)" :placeholder="'请输入 ' + placeholder"
  6. @change="selectChange" @clear="clear" :clearable="clearable" :multiple="multiple" :filterable="filterable"
  7. :remote="remote" :remote-method="remoteMethod" :loading="loading" :size="size" :disabled="disabled">
  8. <el-option v-for="item in options" :key="item[key]" :label="item[label]"
  9. :value="item[keyValue ? keyValue : label]">
  10. </el-option>
  11. </el-select>
  12. <el-button v-if="searchShow" icon="el-icon-search" size="small" :disabled="disabled" @click="open()" />
  13. </div>
  14. <el-dialog title="客户" :visible.sync="dialogVisible" width="70%" :before-close="false" @closed="closed"
  15. append-to-body>
  16. <span>
  17. <el-row v-if="treeShow">
  18. <el-col :span="4">
  19. <el-card class="box-card">
  20. <avue-tree ref="tree" :option="treeOption" :data="treeData" @node-click="nodeClick">
  21. </avue-tree>
  22. </el-card>
  23. </el-col>
  24. <el-col :span="20">
  25. <avue-crud :option="option" :table-loading="loading" :data="dataList" :page.sync="page"
  26. :search.sync="query" v-model="form" id="out-table" ref="crud" @row-del="rowDel"
  27. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  28. @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad">
  29. </avue-crud>
  30. </el-col>
  31. </el-row>
  32. <avue-crud v-else :option="option" :table-loading="loading" :data="dataList" :page.sync="page"
  33. :search.sync="query" v-model="form" id="out-table" ref="crud" @row-del="rowDel"
  34. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  35. @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad">
  36. </avue-crud>
  37. </span>
  38. <span slot="footer" class="dialog-footer">
  39. <el-button size="small" @click="dialogVisible = false">取 消</el-button>
  40. <el-button size="small" type="primary" :disabled="this.selectionList.length != 1" @click="importData">确
  41. 定</el-button>
  42. </span>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. import { getDicinit } from "@/api/dicSelect/index";
  48. import { bcorpstypedefineList } from "@/api/iosBasicData/bcorpstypedefine"
  49. export default {
  50. data() {
  51. return {
  52. dialogVisible: false,
  53. options: [],
  54. loading: false,
  55. data: {},
  56. form: {},
  57. query: {},
  58. page: {
  59. pageSize: 10,
  60. currentPage: 1,
  61. total: 0
  62. },
  63. dataList: [],
  64. selectionList: [],
  65. option: {
  66. height: 400,
  67. calcHeight: 30,
  68. tip: false,
  69. searchIcon: true,
  70. searchIndex: 3,
  71. searchShow: true,
  72. searchMenuSpan: 6,
  73. border: true,
  74. index: true,
  75. selection: true,
  76. header: false,
  77. menu: false,
  78. column: [
  79. {
  80. label: "编码",
  81. prop: "code",
  82. search: true,
  83. rules: [{
  84. required: true,
  85. message: "请输入单位编码",
  86. trigger: "blur"
  87. }],
  88. overHidden: true,
  89. },
  90. {
  91. label: "中文名称",
  92. prop: "cnName",
  93. search: true,
  94. rules: [{
  95. required: true,
  96. message: "请输入中文名称",
  97. trigger: "blur"
  98. }],
  99. overHidden: true,
  100. },
  101. {
  102. label: "英文名称",
  103. prop: "enName",
  104. search: true,
  105. rules: [{
  106. required: true,
  107. message: "请输入英文名称",
  108. trigger: "blur"
  109. }],
  110. overHidden: true,
  111. },
  112. {
  113. label: "状态",
  114. prop: "status",
  115. type: 'select',
  116. search: true,
  117. dicData: [{
  118. label: '启用',
  119. value: 0
  120. }, {
  121. label: '停用',
  122. value: 1
  123. }],
  124. rules: [{
  125. required: true,
  126. message: "请输入状态",
  127. trigger: "blur"
  128. }],
  129. overHidden: true,
  130. },
  131. {
  132. label: "备注",
  133. prop: "remarks",
  134. span: 24,
  135. type: 'textarea',
  136. width: "180",
  137. slot: true,
  138. minRows: 3,
  139. overHidden: true,
  140. },
  141. ],
  142. designer: null,
  143. },
  144. treeOption: {
  145. nodeKey: "id",
  146. lazy: true,
  147. treeLoad: function (node, resolve) {
  148. const parentId = node.level === 0 ? 0 : node.data.id;
  149. },
  150. addBtn: false,
  151. menu: false,
  152. size: "small",
  153. props: {
  154. labelText: "标题",
  155. label: "cnName",
  156. value: "id",
  157. children: "children"
  158. }
  159. },
  160. treeData: []
  161. }
  162. },
  163. props: {
  164. activateCreated: {
  165. type: Boolean,
  166. default: true
  167. },
  168. key: {
  169. type: [String, Number],
  170. default: null
  171. },
  172. label: {
  173. type: String,
  174. default: ''
  175. },
  176. keyValue: {
  177. type: [String, Number],
  178. default: null
  179. },
  180. res: {
  181. type: String,
  182. default: ''
  183. },
  184. placeholder: {
  185. type: String,
  186. default: '请输入'
  187. },
  188. clearable: {
  189. type: Boolean,
  190. default: true
  191. },
  192. value: {
  193. type: [String, Number],
  194. default: ''
  195. },
  196. method: {
  197. type: String,
  198. default: 'GET'
  199. },
  200. url: {
  201. type: String,
  202. default: ''
  203. },
  204. dataName: {
  205. type: String,
  206. default: ''
  207. },
  208. multiple: {
  209. type: Boolean,
  210. default: false
  211. },
  212. filterable: {
  213. type: Boolean,
  214. default: false
  215. },
  216. remote: {
  217. type: Boolean,
  218. default: false
  219. },
  220. size: {
  221. type: String,
  222. default: 'small'
  223. },
  224. disabled: {
  225. type: Boolean,
  226. default: false
  227. },
  228. searchShow: {
  229. type: Boolean,
  230. default: false
  231. },
  232. treeShow: {
  233. type: Boolean,
  234. default: false
  235. },
  236. mockData: {
  237. type: Array,
  238. default: function () {
  239. return [];
  240. }
  241. }
  242. },
  243. model: {
  244. prop: "value",
  245. event: "selectedValue"
  246. },
  247. created() {
  248. if (this.activateCreated) {
  249. this.getDicData()
  250. } else {
  251. this.options = this.mockData
  252. }
  253. },
  254. methods: {
  255. open() {
  256. this.dialogVisible = true
  257. this.getTree()
  258. },
  259. // 获取客户类别
  260. getTree() {
  261. bcorpstypedefineList(1, 50).then(res => {
  262. this.treeData = res.data.data.records
  263. })
  264. },
  265. nodeClick(data) {
  266. this.query.corpTypeName = data.cnName
  267. this.onLoad(this.page, this.query);
  268. },
  269. closed() {
  270. this.query = {}
  271. this.selectionList = []
  272. },
  273. remoteMethod(query) {
  274. if (query !== '') {
  275. setTimeout(() => {
  276. this.data[this.dataName] = query
  277. this.getDicData()
  278. }, 200);
  279. } else {
  280. setTimeout(() => {
  281. this.data = this.$options.data().data
  282. this.getDicData()
  283. }, 200);
  284. }
  285. },
  286. getDicData() {
  287. this.loading = true
  288. getDicinit(this.method, this.url, this.data).then(res => {
  289. if (this.res) {
  290. this.options = res.data.data[this.res]
  291. } else {
  292. this.options = res.data.data
  293. }
  294. }).finally(() => {
  295. this.loading = false;
  296. })
  297. },
  298. IdGetDicData(data) {
  299. this.loading = true
  300. getDicinit(this.method, this.url, data).then(res => {
  301. if (this.res) {
  302. this.options = res.data.data[this.res]
  303. } else {
  304. this.options = res.data.data
  305. }
  306. }).finally(() => {
  307. this.loading = false;
  308. })
  309. },
  310. selectChange(row) {
  311. this.options.forEach(e => {
  312. if (row == e[this.label]) {
  313. this.$emit('selectChange', e)
  314. }
  315. })
  316. },
  317. clear() {
  318. if (this.remote) {
  319. this.data = this.$options.data().data
  320. this.getDicData()
  321. }
  322. this.$emit('selectChange', null)
  323. },
  324. importData() {
  325. this.dialogVisible = false
  326. this.$emit('selectChange', this.selectionList[0])
  327. },
  328. searchChange(params, done) {
  329. this.page.currentPage = 1;
  330. this.onLoad(this.page, this.query);
  331. done();
  332. },
  333. selectionChange(list) {
  334. this.selectionList = list;
  335. },
  336. currentChange(currentPage) {
  337. this.page.currentPage = currentPage;
  338. },
  339. sizeChange(pageSize) {
  340. this.page.pageSize = pageSize;
  341. },
  342. refreshChange() {
  343. this.onLoad(this.page, this.query);
  344. },
  345. onLoad(page, params = {}) {
  346. let obj = {}
  347. obj = {
  348. current: page.currentPage,
  349. size: page.pageSize,
  350. ...Object.assign(params, this.query),
  351. }
  352. this.loading = true
  353. getDicinit(this.method, this.url, obj).then(res => {
  354. this.dataList = res.data.data.records
  355. this.page.total = res.data.data.total;
  356. }).finally(() => {
  357. this.loading = false;
  358. })
  359. },
  360. }
  361. }
  362. </script>
  363. <style lang="scss" scoped>
  364. /deep/ .el-col-md-8 {
  365. width: 24.33333%;
  366. }
  367. </style>