mainProduct.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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: "goodsName",
  94. search: true,
  95. overHidden: true,
  96. },
  97. {
  98. label: "创建人",
  99. prop: "createUserName",
  100. overHidden: true,
  101. },
  102. {
  103. label: '创建时间',
  104. prop: "createTime",
  105. search: true,
  106. overHidden: true,
  107. },
  108. {
  109. label: '修改人',
  110. prop: "updateUserName",
  111. overHidden: true,
  112. },
  113. {
  114. label: '更新时间',
  115. prop: "updateTime",
  116. overHidden: true,
  117. },
  118. {
  119. label: '备注',
  120. prop: "remarks",
  121. overHidden: true,
  122. },
  123. ],
  124. designer: null,
  125. },
  126. treeOption: {
  127. nodeKey: "id",
  128. lazy: true,
  129. treeLoad: function (node, resolve) {
  130. const parentId = node.level === 0 ? 0 : node.data.id;
  131. },
  132. addBtn: false,
  133. menu: false,
  134. size: "small",
  135. props: {
  136. labelText: "标题",
  137. label: "cnName",
  138. value: "id",
  139. children: "children"
  140. }
  141. },
  142. treeData: [],
  143. selectWidth: 0
  144. }
  145. },
  146. props: {
  147. activateCreated: {
  148. type: Boolean,
  149. default: true
  150. },
  151. slotRight: {
  152. type: Boolean,
  153. default: false
  154. },
  155. diySlot: {
  156. type: Boolean,
  157. default: false
  158. },
  159. key: {
  160. type: [String, Number],
  161. default: null
  162. },
  163. label: {
  164. type: String,
  165. default: ''
  166. },
  167. rightLabel: {
  168. type: String,
  169. default: ''
  170. },
  171. keyValue: {
  172. type: [String, Number],
  173. default: null
  174. },
  175. res: {
  176. type: String,
  177. default: ''
  178. },
  179. placeholder: {
  180. type: String,
  181. default: '请输入'
  182. },
  183. clearable: {
  184. type: Boolean,
  185. default: true
  186. },
  187. value: {
  188. type: [String, Number],
  189. default: ''
  190. },
  191. method: {
  192. type: String,
  193. default: 'GET'
  194. },
  195. url: {
  196. type: String,
  197. default: ''
  198. },
  199. dataName: {
  200. type: String,
  201. default: ''
  202. },
  203. multiple: {
  204. type: Boolean,
  205. default: false
  206. },
  207. filterable: {
  208. type: Boolean,
  209. default: false
  210. },
  211. remote: {
  212. type: Boolean,
  213. default: false
  214. },
  215. size: {
  216. type: String,
  217. default: 'small'
  218. },
  219. disabled: {
  220. type: Boolean,
  221. default: false
  222. },
  223. searchShow: {
  224. type: Boolean,
  225. default: false
  226. },
  227. treeShow: {
  228. type: Boolean,
  229. default: false
  230. },
  231. mockData: {
  232. type: Array,
  233. default: function () {
  234. return [];
  235. }
  236. },
  237. collapseTags: {
  238. type: Boolean,
  239. default: false
  240. },
  241. },
  242. model: {
  243. prop: "value",
  244. event: "selectedValue"
  245. },
  246. created() {
  247. if (this.activateCreated) {
  248. this.getDicData()
  249. } else {
  250. this.options = this.mockData
  251. }
  252. },
  253. mounted() {
  254. if (this.diySlot) {
  255. this.$nextTick(() => {
  256. this.selectWidth = this.$refs.mySelect.$el.offsetWidth;
  257. this.$refs.mySelect.$el.querySelector('.el-select-dropdown').style.width = `${this.selectWidth}px`;
  258. });
  259. }
  260. },
  261. methods: {
  262. open() {
  263. this.dialogVisible = true
  264. this.getTree()
  265. },
  266. // 获取客户类别
  267. getTree() {
  268. bcorpstypedefineList(1, 50).then(res => {
  269. this.treeData = res.data.data.records
  270. })
  271. },
  272. nodeClick(data) {
  273. this.query.corpTypeName = data.cnName
  274. this.onLoad(this.page, this.query);
  275. },
  276. closed() {
  277. this.query = {}
  278. this.selectionList = []
  279. },
  280. remoteMethod(query) {
  281. if (query !== '') {
  282. setTimeout(() => {
  283. this.data[this.dataName] = query
  284. this.getDicData()
  285. }, 200);
  286. } else {
  287. setTimeout(() => {
  288. this.data = this.$options.data().data
  289. this.getDicData()
  290. }, 200);
  291. }
  292. },
  293. getDicData() {
  294. if (this.url) {
  295. this.loading = true
  296. getDicinit(this.method, this.url, this.data).then(res => {
  297. if (this.res) {
  298. this.options = res.data.data[this.res]
  299. } else {
  300. this.options = res.data.data
  301. }
  302. }).finally(() => {
  303. this.loading = false;
  304. })
  305. } else {
  306. this.options = this.mockData
  307. }
  308. },
  309. IdGetDicData(data) {
  310. this.loading = true
  311. getDicinit(this.method, this.url, data).then(res => {
  312. if (this.res) {
  313. this.options = res.data.data[this.res]
  314. } else {
  315. this.options = res.data.data
  316. }
  317. }).finally(() => {
  318. this.loading = false;
  319. })
  320. },
  321. selectChange(row) {
  322. this.options.forEach(e => {
  323. if (this.keyValue) {
  324. if (row == e[this.keyValue]) {
  325. this.$emit('selectChange', e)
  326. }
  327. }
  328. if (this.label) {
  329. if (row == e[this.label]) {
  330. this.$emit('selectChange', e)
  331. }
  332. }
  333. })
  334. },
  335. clear() {
  336. this.data = this.$options.data().data
  337. this.getDicData()
  338. this.$emit('selectChange', null)
  339. },
  340. importData() {
  341. this.dialogVisible = false
  342. this.$emit('selectChange', this.selectionList[0])
  343. },
  344. searchChange(params, done) {
  345. this.page.currentPage = 1;
  346. this.onLoad(this.page, this.query);
  347. done();
  348. },
  349. selectionChange(list) {
  350. this.selectionList = list;
  351. },
  352. currentChange(currentPage) {
  353. this.page.currentPage = currentPage;
  354. },
  355. sizeChange(pageSize) {
  356. this.page.pageSize = pageSize;
  357. },
  358. refreshChange() {
  359. this.onLoad(this.page, this.query);
  360. },
  361. onLoad(page, params = {}) {
  362. let obj = {}
  363. obj = {
  364. current: page.currentPage,
  365. size: page.pageSize,
  366. ...Object.assign(params, this.query),
  367. }
  368. this.loading = true
  369. getDicinit(this.method, this.url, obj).then(res => {
  370. this.dataList = res.data.data.records
  371. this.page.total = res.data.data.total;
  372. }).finally(() => {
  373. this.loading = false;
  374. })
  375. },
  376. }
  377. }
  378. </script>
  379. <style lang="scss" scoped>
  380. /deep/ .el-col-md-8 {
  381. width: 24.33333%;
  382. }
  383. </style>