main.vue 14 KB

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