index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <div>
  3. <Toptitle>
  4. <template #left>
  5. <Button type="primary" @click="is_open = !is_open">{{
  6. is_open ? "收缩" : "展开"
  7. }}</Button>
  8. </template>
  9. <template #right>
  10. <Dropdown style="margin-left: 20px" @on-click="handleClick">
  11. <Button type="primary">
  12. 操作
  13. <Icon type="ios-arrow-down"></Icon>
  14. </Button>
  15. <DropdownMenu slot="list">
  16. <DropdownItem :name="1">新增</DropdownItem>
  17. <DropdownItem :name="2">批量删除</DropdownItem>
  18. <DropdownItem :name="3">导出</DropdownItem>
  19. </DropdownMenu>
  20. </Dropdown>
  21. </template>
  22. </Toptitle>
  23. <div
  24. :style="
  25. is_open
  26. ? 'max-height:200px;transition: all .5s;'
  27. : 'max-height:0px;overflow: hidden;transition: all .5s;'
  28. "
  29. >
  30. <Form :label-width="120" style="display: flex; flex-wrap: wrap">
  31. <FormItem label="管理员">
  32. <Select
  33. v-model="searchData.employee_id"
  34. filterable
  35. clearable
  36. transfer
  37. style="width: 200px"
  38. >
  39. <Option
  40. v-for="item in employeeList"
  41. :key="item.id"
  42. :value="item.id"
  43. :label="item.emp_name"
  44. />
  45. </Select>
  46. </FormItem>
  47. <FormItem label="仓库名称">
  48. <Input
  49. v-model="searchData.title"
  50. clearable
  51. style="width: 200px"
  52. placeholder="请输入"
  53. />
  54. </FormItem>
  55. <FormItem :label-width="30">
  56. <Button type="primary" @click="handleSearch">查询</Button>
  57. </FormItem>
  58. </Form>
  59. </div>
  60. <div style="max-height: calc(100% - 150px); border: 1px solid #fff">
  61. <vxe-grid
  62. v-bind="gridOptions"
  63. @checkbox-change="handleSelect"
  64. @checkbox-all="handleSelectAll"
  65. >
  66. <template #set="{ row }">
  67. <a style="margin-right: 10px" @click="handleEdit(row)">编辑</a>
  68. <a @click="handleDel(row)">删除</a>
  69. </template>
  70. </vxe-grid>
  71. </div>
  72. <div style="text-align: center; margin-top: 10px">
  73. <Page
  74. show-elevator
  75. :page-size-opts="[10, 20, 30, 40, 100, 1000]"
  76. @on-page-size-change="changeSize"
  77. @on-change="changePage"
  78. :current="pageIndex"
  79. show-total
  80. :total="total"
  81. show-sizer
  82. :page-size="pageSize"
  83. />
  84. </div>
  85. <Modal
  86. draggable
  87. title="新增"
  88. width="80"
  89. :closable="false"
  90. :mask-closable="false"
  91. v-model="is_show"
  92. >
  93. <div style="max-height: 450px; overflow: auto">
  94. <Form
  95. :label-width="100"
  96. v-for="(item, index) in modalData"
  97. :key="index"
  98. style="display: flex"
  99. >
  100. <FormItem label="管理员" style="width: 30%">
  101. <Select v-model="item.employee_id" filterable clearable transfer>
  102. <Option
  103. v-for="_item in employeeList"
  104. :key="_item.id"
  105. :value="_item.id"
  106. :label="_item.emp_name"
  107. />
  108. </Select>
  109. </FormItem>
  110. <FormItem label="仓库名称" style="width: 30%">
  111. <Input clearable placeholder="请输入" v-model="item.title" />
  112. </FormItem>
  113. <FormItem label="关联集团">
  114. <Select v-model="item.company" filterable clearable transfer>
  115. <Option
  116. v-for="_item in companyList"
  117. :key="_item.id"
  118. :value="_item.id"
  119. :label="_item.title"
  120. />
  121. </Select>
  122. </FormItem>
  123. <FormItem :label-width="40" style="width: 20%">
  124. <div class="icon">
  125. <Icon
  126. :size="20"
  127. type="ios-add-circle-outline"
  128. style="margin-right: 10px; cursor: pointer"
  129. @click="handleModalAdd(index)"
  130. />
  131. <Icon
  132. :size="20"
  133. type="ios-remove-circle-outline"
  134. style="cursor: pointer"
  135. @click="handleModalRemove(index)"
  136. />
  137. </div>
  138. </FormItem>
  139. </Form>
  140. </div>
  141. <div slot="footer">
  142. <Button style="margin-right: 10px" @click="is_show = false"
  143. >取消</Button
  144. >
  145. <Button type="primary" @click="handleSure">确认</Button>
  146. </div>
  147. </Modal>
  148. <Modal
  149. draggable
  150. title="编辑"
  151. width="40"
  152. :closable="false"
  153. :mask-closable="false"
  154. v-model="is_edit"
  155. >
  156. <Form :label-width="100">
  157. <FormItem label="管理员">
  158. <Select v-model="editData.employee_id" filterable clearable transfer>
  159. <Option
  160. v-for="_item in employeeList"
  161. :key="_item.id"
  162. :value="_item.id"
  163. :label="_item.emp_name"
  164. />
  165. </Select>
  166. </FormItem>
  167. <FormItem label="仓库名称">
  168. <Input clearable placeholder="请输入" v-model="editData.title" />
  169. </FormItem>
  170. <FormItem label="关联集团">
  171. <Select v-model="editData.company" filterable clearable transfer>
  172. <Option
  173. v-for="_item in companyList"
  174. :key="_item.id"
  175. :value="_item.id"
  176. :label="_item.title"
  177. />
  178. </Select>
  179. </FormItem>
  180. </Form>
  181. <div slot="footer">
  182. <Button style="margin-right: 10px" @click="is_edit = false"
  183. >取消</Button
  184. >
  185. <Button type="primary" @click="handleSureEdit">确认</Button>
  186. </div>
  187. </Modal>
  188. </div>
  189. </template>
  190. <script>
  191. export default {
  192. data() {
  193. return {
  194. pageSize: 10,
  195. pageIndex: 1,
  196. total: 0,
  197. searchData: {
  198. employee_id: '',
  199. title: ""
  200. },
  201. is_edit: false,
  202. is_open: false,
  203. editData: {},
  204. proxyData: {},
  205. modalData: [],
  206. companyList:[],
  207. is_show: false,
  208. selectData: [],
  209. gridOptions: {
  210. maxHeight: 'auto',
  211. border: true,
  212. showOverflow: true,
  213. rowId: 'id',
  214. rowConfig: {
  215. isHover: true
  216. },
  217. columnConfig: {
  218. resizable: true
  219. },
  220. data: [],
  221. columns: [
  222. { type: 'checkbox', width: 80 },
  223. { title: '操作', slots: { default: 'set' }, width: 150, align: 'center' },
  224. { field: 'emp_name', title: '管理员', width: 220 },
  225. { field: 'title', title: '仓库名称' },
  226. { field: 'company_name', title: '关联集团' },
  227. ]
  228. },
  229. employeeList: [],
  230. }
  231. },
  232. created() {
  233. //获取人员列表
  234. this.axios.post('/api/employeeList').then(res => {
  235. this.employeeList = res.data.data;
  236. })
  237. //获取集团列表
  238. this.axios.post('/api/companyList').then(res=>{
  239. this.companyList = res.data.data;
  240. })
  241. },
  242. mounted() {
  243. this.initData();
  244. },
  245. methods: {
  246. changeSize(e) {
  247. this.pageSize = e;
  248. this.pageIndex = 1;
  249. this.initData(this.proxyData)
  250. },
  251. changePage(e) {
  252. this.pageIndex = e;
  253. this.initData(this.proxyData);
  254. },
  255. async handleClick(name) {
  256. if (name == 1) {
  257. this.handleAdd();
  258. } else if(name == 2){
  259. this.handleDel();
  260. }else {
  261. if(this.selectData.length==0){
  262. return this.$Message.warning('请选择需要导出的数据!')
  263. }
  264. let id = this.selectData.map(v=>v.id);
  265. const res = await this.axios.post('/api/exportFile',{type:18,id})
  266. if(res.code === 200){
  267. let url = `${this.$store.state.ip}/api/getExport/${res.data.file}`
  268. location.href = url
  269. }
  270. }
  271. },
  272. handleSearch() {
  273. this.proxyData = JSON.parse(JSON.stringify(this.searchData));
  274. this.pageIndex = 1;
  275. this.initData(this.proxyData);
  276. },
  277. handleModalAdd(index) {
  278. this.modalData.splice(index + 1, 0, { employee_id: '', title: "" })
  279. },
  280. handleModalRemove(index) {
  281. this.modalData.splice(index, 1)
  282. },
  283. handleSure() {
  284. let data = JSON.parse(JSON.stringify(this.modalData))
  285. data.forEach(v=>{
  286. v.company = [v.company]
  287. })
  288. this.axios.post('/api/storehouseAdd', { data }).then(res => {
  289. if (res.code == 200) {
  290. this.$Message.success(res.msg);
  291. this.initData(this.proxyData);
  292. this.is_show = false;
  293. }
  294. })
  295. },
  296. handleSureEdit() {
  297. let id = this.editData.id;
  298. let data = [{ employee_id: this.editData.employee_id, title: this.editData.title ,company:[this.editData.company]}]
  299. this.axios.post('/api/storehouseEdit', { id, data }).then(res => {
  300. if (res.code == 200) {
  301. this.$Message.success(res.msg);
  302. this.initData(this.proxyData);
  303. this.is_edit = false;
  304. }
  305. })
  306. },
  307. handleSelectAll(e) {
  308. this.selectData = e.records;
  309. },
  310. handleSelect(e) {
  311. this.selectData = e.records;
  312. },
  313. initData(row) {
  314. this.axios.post('/api/storehouseList', { ...row, page_index: this.pageIndex, page_size: this.pageSize }).then(res => {
  315. this.gridOptions.data = res.data.data;
  316. this.total = res.data.total;
  317. })
  318. },
  319. handleEdit(row) {
  320. this.is_edit = true;
  321. this.editData = JSON.parse(JSON.stringify(row));
  322. this.editData.company = this.editData.company_id.length==1?this.editData.company_id[0]:'';
  323. },
  324. handleAdd() {
  325. // if (type == 1) {//新增
  326. this.modalData = [
  327. {
  328. employee_id: '',
  329. title: ''
  330. }
  331. ]
  332. this.is_show = true;
  333. // }
  334. // else {//编辑
  335. // if (this.getBol(this.selectData)) {
  336. // this.is_show = true;
  337. // } else {
  338. // return this.$Message.warning('请选择一个子集团!')
  339. // }
  340. // let data = this.getData(this.selectData);
  341. // this.modalData = { id: data.id, employee_id: data.employee_id, title: data.title }
  342. // }
  343. },
  344. // getData(arr) {
  345. // let obj = {};
  346. // arr.forEach(v => {
  347. // if (v.children.length == 0) {
  348. // obj = v;
  349. // } else {
  350. // obj = this.getData(v.children);
  351. // }
  352. // })
  353. // return obj;
  354. // },
  355. // getBol(arr) {
  356. // let bol = true;
  357. // let ids = arr.map(v => v.id);
  358. // let fid = [this.selectData[0].id, ...this.getChildren(this.selectData[0].children)];
  359. // let length = arr.map(v => v.employee_id.length);
  360. // let setLength = Array.from(new Set(length));
  361. // if (length.length == setLength.length) {
  362. // ids.forEach(v => {
  363. // if (fid.indexOf(v) == -1) {
  364. // return bol = false
  365. // }
  366. // })
  367. // } else {
  368. // bol = false;
  369. // }
  370. // return bol
  371. // },
  372. // getChildren(arr) {
  373. // let id = [];
  374. // arr.forEach(v => {
  375. // id.push(v.id);
  376. // if (v.children.length != 0) {
  377. // id = [id, ...this.getChildren(v.children)];
  378. // }
  379. // })
  380. // return id;
  381. // },
  382. handleDel(row) {
  383. let id = [];
  384. if (row) {
  385. id = [row.id];
  386. } else {
  387. if (this.selectData.length == 0) {
  388. return this.$Message.warning('请选择数据!');
  389. }
  390. id = this.selectData.map(v => (v.id));
  391. }
  392. this.$Modal.confirm({
  393. title: '删除',
  394. content: '确认删除嘛?',
  395. onOk: () => {
  396. this.axios.post('/api/storehouseDel', {id}).then(res => {
  397. if (res.code == 200) {
  398. this.$Message.success(res.msg);
  399. if (this.pageIndex != 1 && !(this.gridOptions.data.length - id.length)) {
  400. this.pageIndex--;
  401. }
  402. this.selectData = [];
  403. this.initData(this.proxyData)
  404. }
  405. })
  406. }
  407. })
  408. },
  409. }
  410. }
  411. </script>
  412. <style lang="scss" scoped>
  413. .icon {
  414. display: flex;
  415. width: 80px;
  416. justify-content: space-between;
  417. align-items: center;
  418. height: 44px;
  419. }
  420. </style>