StoreManagement.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <!-- 仓库管理 -->
  3. <div class="home">
  4. <actionBar :operateList="operateList" :formList="formList" :ruleForm="searchRuleForm" @openModel="openModel"
  5. @searchProtocol="searchProtocol"></actionBar>
  6. <div class="card_content">
  7. <!-- 表单 -->
  8. <tables :suspension="true" :tableList="tableList" :tableData="tableData" @buttonData="buttonData"></tables>
  9. <!-- 分页 -->
  10. <div v-if="Total">
  11. <pagination :total="Total" :currentPage="Pagination.PageIndex" @changeSize="changeSize"
  12. @changeCurrent="changeCurrent">
  13. </pagination>
  14. </div>
  15. </div>
  16. <el-dialog :title="staffTitle" :visible.sync="staffDialogVisible" width="600px" :close-on-click-modal="false"
  17. @close="closeDialog">
  18. <forms ref="childRules" :formNewList="formRuleList" :ruleForm="ruleForm" labelWidth="100px"></forms>
  19. <span slot="footer" class="dialog-footer" v-if="operationType != 'logs'">
  20. <el-button plain @click="staffDialogVisible = false">取 消</el-button>
  21. <el-button type="primary" :loading="confirmLoading" @click="handleAdd">确 定</el-button>
  22. </span>
  23. </el-dialog>
  24. <div class="management_card">
  25. <el-dialog :visible.sync="importDialogVisible" width="500px" :close-on-click-modal="false" @close="closeDialogil">
  26. <div class="card_import">
  27. <div class="card_incubat">
  28. <forms ref="incubatorRules" labelPosition="left" :formNewList="stateRuleList" :ruleForm="stateRuleForm"
  29. labelWidth="100px"></forms>
  30. </div>
  31. <div class="card_search_input">
  32. <el-input v-model="nameTitle" placeholder="设备名称" @input="incubatorInput"></el-input>
  33. </div>
  34. <!-- 表单 -->
  35. <tables ref="refIncubator" :tableList="incubatorList" :tableData="incubatorData"></tables>
  36. <!-- 分页 -->
  37. <div v-if="Total1">
  38. <pagination :total="Total1" :currentPage="Paginationil.PageIndex" :pager-countnum="5"
  39. layout="sizes, prev, pager, next" @changeSize="changeSizeil" @changeCurrent="changeCurrentil">
  40. </pagination>
  41. </div>
  42. </div>
  43. <span slot="footer" class="dialog-footer">
  44. <el-button plain @click="importDialogVisible = false">取 消</el-button>
  45. <el-button type="primary" :loading="incubatorLoading" @click="incubatorAdd">导 入</el-button>
  46. </span>
  47. </el-dialog>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import {
  53. getSysUserBind
  54. } from '@/api/user'
  55. import {
  56. getWarehouse,
  57. getWarehouseDetails,
  58. addWarehouse,
  59. putWarehouse,
  60. delWarehouse,
  61. importWarehouse
  62. } from '@/api/warehouse'
  63. import {
  64. getDevice
  65. } from '@/api/incubator'
  66. import actionBar from '@/components/actionBar'
  67. import tables from '@/components/tables'
  68. import pagination from '@/components/pagination'
  69. import forms from '@/components/forms'
  70. import {
  71. formRules,
  72. employee,
  73. incubator
  74. } from "./warehouse.js";
  75. import {
  76. startStatus,
  77. } from '@/assets/js/blockSort'
  78. export default {
  79. name: 'StoreManagement',
  80. components: {
  81. actionBar,
  82. tables,
  83. pagination,
  84. forms
  85. },
  86. data() {
  87. return {
  88. operateList: [{
  89. type: 'add',
  90. title: '添加仓库',
  91. icon: 'el-icon-plus',
  92. }, {
  93. type: 'import',
  94. title: '冷链平台导入',
  95. icon: 'el-icon-upload',
  96. }],
  97. formList: [{
  98. type: 'input',
  99. label: '名称/管理员名称',
  100. field: 'name',
  101. placeholder: '仓库名称/管理员名称',
  102. }, {
  103. type: 'input',
  104. label: 'SN',
  105. field: 'sn',
  106. placeholder: 'SN',
  107. }],
  108. searchRuleForm: {
  109. name: '',
  110. sn: '',
  111. },
  112. Pagination: {
  113. PageIndex: 1,
  114. PageSize: 10,
  115. },
  116. Total: 0,
  117. tableData: [],
  118. operationType: '',
  119. tableList: employee(),
  120. tableData: [],
  121. staffTitle: '添加',
  122. staffDialogVisible: false,
  123. formRuleList: [],
  124. ruleForm: {
  125. name: '',
  126. sn: '',
  127. address: '',
  128. status: '',
  129. userId: '',
  130. },
  131. confirmLoading: false,
  132. selectingData: {},
  133. importDialogVisible: false,
  134. incubatorList: incubator(),
  135. incubatorData: [],
  136. Total1: 0,
  137. Paginationil: {
  138. PageIndex: 1,
  139. PageSize: 10,
  140. },
  141. stateRuleList: [{
  142. field: 'status',
  143. label: '启用状态:',
  144. placeholder: '启用状态:',
  145. type: 'radio',
  146. colWidth: 24,
  147. rules: [{
  148. required: true,
  149. message: '选择启用状态:',
  150. trigger: 'change'
  151. }],
  152. options: startStatus()
  153. }],
  154. stateRuleForm: {
  155. status: '2',
  156. },
  157. nameTitle: '',
  158. incubatorLoading: false,
  159. }
  160. },
  161. mounted() {
  162. this.getDriver()
  163. const dataList = formRules();
  164. this.formRuleList = dataList;
  165. this.getList()
  166. },
  167. methods: {
  168. // 搜索
  169. searchProtocol(value) {
  170. this.searchValue = value
  171. this.getList()
  172. },
  173. // 获取订单列表
  174. getList() {
  175. var params = {
  176. page: this.Pagination.PageIndex,
  177. pageSize: this.Pagination.PageSize,
  178. ...this.searchValue
  179. }
  180. getWarehouse(params).then(res => {
  181. if (res.code == 200) {
  182. this.tableData = res.data.list
  183. this.Total = res.data.count
  184. }
  185. })
  186. },
  187. // 获取仓库管理员列表
  188. getDriver() {
  189. getSysUserBind({
  190. type: 2,
  191. }).then(res => {
  192. if (res.code == 200) {
  193. const arrList = []
  194. const arr = res.data.list
  195. arr.forEach((item, index) => {
  196. const commodity = {
  197. label: item.nickName,
  198. value: item.id,
  199. IsBind: item.IsBind,
  200. }
  201. arrList.push(commodity)
  202. })
  203. this.optionMatching(arrList, 'userId')
  204. }
  205. })
  206. },
  207. // 选项赋值
  208. optionMatching(value, field) {
  209. this.formRuleList.forEach((item, index) => {
  210. if (item.field == field) {
  211. item.options = value
  212. }
  213. })
  214. },
  215. // 弹窗表单添加
  216. handleAdd() {
  217. let flag = this.$refs['childRules'].validateForm();
  218. if (flag) {
  219. if (this.operationType == 'add') {
  220. this.confirmLoading = true
  221. var params = {
  222. ...this.ruleForm
  223. }
  224. params.userId = Number(params.userId)
  225. addWarehouse(params).then(res => {
  226. if (res.code == 200) {
  227. this.$message({
  228. message: '操作成功',
  229. type: 'success'
  230. });
  231. this.getList()
  232. }
  233. this.staffDialogVisible = false
  234. this.confirmLoading = false
  235. }).catch(() => {
  236. this.confirmLoading = false
  237. })
  238. } else if (this.operationType == 'edit') {
  239. this.confirmLoading = true
  240. var params = {
  241. id: this.selectingData.id,
  242. address: this.ruleForm.address,
  243. name: this.ruleForm.name,
  244. sn: this.ruleForm.sn,
  245. status: this.ruleForm.status,
  246. userId: this.ruleForm.userId,
  247. }
  248. params.userId = Number(params.userId)
  249. putWarehouse(params).then(res => {
  250. if (res.code == 200) {
  251. this.$message({
  252. message: '操作成功',
  253. type: 'success'
  254. });
  255. this.getList()
  256. }
  257. this.staffDialogVisible = false
  258. this.confirmLoading = false
  259. }).catch(() => {
  260. this.confirmLoading = false
  261. })
  262. }
  263. } else {
  264. this.$message.error('表单信息不完整,请继续填写完整');
  265. }
  266. },
  267. buttonData(row, type) {
  268. this.selectingData = row
  269. this.operationType = type
  270. if (type == 'edit') {
  271. this.staffTitle = '编辑'
  272. this.staffDialogVisible = true
  273. setTimeout(() => {
  274. this.$nextTick(() => {
  275. this.ruleForm = JSON.parse(JSON.stringify(row))
  276. this.ruleForm.userId = String(row.userId)
  277. })
  278. })
  279. } else if (type == 'del') {
  280. this.deleteUser(row.id)
  281. } else if (type == 'logs') {
  282. this.staffTitle = '详情'
  283. this.staffDialogVisible = true
  284. this.formRuleList.forEach((item, index) => {
  285. item.disabled = true
  286. })
  287. this.ruleForm = JSON.parse(JSON.stringify(row))
  288. this.ruleForm.userId = row.user.nickName
  289. }
  290. },
  291. openModel(type) {
  292. if (type == 'add') {
  293. this.getDriver()
  294. this.staffTitle = '添加'
  295. this.staffDialogVisible = true
  296. this.operationType = type
  297. } else if (type == 'import') {
  298. this.importDialogVisible = true
  299. this.getDeviceList()
  300. }
  301. },
  302. // 获取设备列表
  303. getDeviceList() {
  304. var params = {
  305. page: this.Paginationil.PageIndex,
  306. pageSize: this.Paginationil.PageSize,
  307. name: this.nameTitle,
  308. }
  309. getDevice(params).then(res => {
  310. if (res.code == 200) {
  311. this.incubatorData = res.data.list
  312. this.Total1 = res.data.count
  313. }
  314. })
  315. },
  316. // 搜索保温箱
  317. incubatorInput(value) {
  318. this.nameTitle = value
  319. this.getDeviceList()
  320. },
  321. // 批量导入保温箱
  322. incubatorAdd() {
  323. const arrID = this.$refs.refIncubator.waybillIds
  324. let arr1 = []
  325. arrID.forEach(item => {
  326. let arr2 = {
  327. sn: item.T_sn,
  328. name: item.T_devName,
  329. }
  330. arr1.push(arr2)
  331. })
  332. let flag = this.$refs['incubatorRules'].validateForm();
  333. if (flag) {
  334. if (arr1.length > 0) {
  335. this.incubatorLoading = true
  336. let params = {
  337. list: arr1,
  338. ...this.stateRuleForm,
  339. }
  340. importWarehouse(params).then(res => {
  341. if (res.code == 200) {
  342. this.$message({
  343. message: '操作成功',
  344. type: 'success'
  345. });
  346. this.getList()
  347. this.importDialogVisible = false
  348. }
  349. this.incubatorLoading = false
  350. })
  351. } else {
  352. this.$message.warning('请选择需要导入的保温箱');
  353. }
  354. } else {
  355. this.$message.error('表单信息不完整,请继续填写完整');
  356. }
  357. },
  358. // 删除仓库
  359. deleteUser(id) {
  360. this.$confirm('此操作将永久删除该仓库, 是否继续?', '提示', {
  361. confirmButtonText: '确定',
  362. cancelButtonText: '取消',
  363. type: 'warning'
  364. }).then(() => {
  365. delWarehouse({
  366. id: id,
  367. }).then(res => {
  368. if (res.code == 200) {
  369. this.$message({
  370. message: '操作成功',
  371. type: 'success'
  372. });
  373. this.getList()
  374. }
  375. })
  376. }).catch(() => {});
  377. },
  378. changeSize(val) {
  379. this.Pagination.PageSize = val
  380. this.getList()
  381. },
  382. changeCurrent(val) {
  383. this.Pagination.PageIndex = val
  384. this.getList()
  385. },
  386. changeSizeil(val) {
  387. this.Paginationil.PageSize = val
  388. this.getDeviceList()
  389. },
  390. changeCurrentil(val) {
  391. this.Paginationil.PageIndex = val
  392. this.getDeviceList()
  393. },
  394. // 清空表单
  395. closeDialog() {
  396. this.formRuleList.forEach((item, index) => {
  397. item.disabled = false
  398. })
  399. this.ruleForm = {}
  400. this.$refs.childRules.resetCheck();
  401. },
  402. closeDialogil() {
  403. this.$refs.incubatorRules.resetCheck();
  404. this.$refs.refIncubator.clearSelected();
  405. }
  406. }
  407. }
  408. </script>