StoreManagement.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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>
  25. </template>
  26. <script>
  27. import {
  28. getSysUserBind
  29. } from '@/api/user'
  30. import {
  31. getWarehouse,
  32. getWarehouseDetails,
  33. addWarehouse,
  34. putWarehouse,
  35. delWarehouse
  36. } from '@/api/warehouse'
  37. import actionBar from '@/components/actionBar'
  38. import tables from '@/components/tables'
  39. import pagination from '@/components/pagination'
  40. import forms from '@/components/forms'
  41. import {
  42. formRules,
  43. employee
  44. } from "./warehouse.js";
  45. export default {
  46. name: 'StoreManagement',
  47. components: {
  48. actionBar,
  49. tables,
  50. pagination,
  51. forms
  52. },
  53. data() {
  54. return {
  55. operateList: [{
  56. type: 'add',
  57. title: '添加仓库',
  58. icon: 'el-icon-plus',
  59. }],
  60. formList: [{
  61. type: 'input',
  62. label: '名称/管理员名称',
  63. field: 'name',
  64. placeholder: '仓库名称/管理员名称',
  65. }, {
  66. type: 'input',
  67. label: 'SN',
  68. field: 'sn',
  69. placeholder: 'SN',
  70. }],
  71. searchRuleForm: {
  72. name: '',
  73. sn: '',
  74. },
  75. searchValue: {},
  76. Pagination: {
  77. PageIndex: 1,
  78. PageSize: 10,
  79. },
  80. Total: 0,
  81. tableData: [],
  82. operationType: '',
  83. tableList: employee(),
  84. tableData: [],
  85. staffTitle: '添加',
  86. staffDialogVisible: false,
  87. formRuleList: [],
  88. ruleForm: {
  89. name: '',
  90. sn: '',
  91. address: '',
  92. status: '',
  93. userId: '',
  94. },
  95. confirmLoading: false,
  96. selectingData: {},
  97. }
  98. },
  99. mounted() {
  100. this.getDriver()
  101. const dataList = formRules();
  102. this.formRuleList = dataList;
  103. this.getList()
  104. },
  105. methods: {
  106. // 搜索
  107. searchProtocol(value) {
  108. this.searchValue = value
  109. this.getList()
  110. },
  111. // 获取订单列表
  112. getList() {
  113. var params = {
  114. page: this.Pagination.PageIndex,
  115. pageSize: this.Pagination.PageSize,
  116. ...this.searchValue
  117. }
  118. getWarehouse(params).then(res => {
  119. if (res.code == 200) {
  120. this.tableData = res.data.list
  121. this.Total = res.data.count
  122. }
  123. })
  124. },
  125. // 获取仓库管理员列表
  126. getDriver() {
  127. getSysUserBind({
  128. type: 2,
  129. }).then(res => {
  130. if (res.code == 200) {
  131. const arrList = []
  132. const arr = res.data.list
  133. arr.forEach((item, index) => {
  134. const commodity = {
  135. label: item.nickName,
  136. value: item.id,
  137. IsBind: item.IsBind,
  138. }
  139. arrList.push(commodity)
  140. })
  141. this.optionMatching(arrList, 'userId')
  142. }
  143. })
  144. },
  145. // 选项赋值
  146. optionMatching(value, field) {
  147. this.formRuleList.forEach((item, index) => {
  148. if (item.field == field) {
  149. item.options = value
  150. }
  151. })
  152. },
  153. // 弹窗表单添加
  154. handleAdd() {
  155. let flag = this.$refs['childRules'].validateForm();
  156. if (flag) {
  157. if (this.operationType == 'add') {
  158. this.confirmLoading = true
  159. var params = {
  160. ...this.ruleForm
  161. }
  162. params.userId = Number(params.userId)
  163. addWarehouse(params).then(res => {
  164. if (res.code == 200) {
  165. this.$message({
  166. message: '操作成功',
  167. type: 'success'
  168. });
  169. this.getList()
  170. }
  171. this.staffDialogVisible = false
  172. this.confirmLoading = false
  173. }).catch(() => {
  174. this.confirmLoading = false
  175. })
  176. } else if (this.operationType == 'edit') {
  177. this.confirmLoading = true
  178. var params = {
  179. id: this.selectingData.id,
  180. address: this.ruleForm.address,
  181. name: this.ruleForm.name,
  182. sn: this.ruleForm.sn,
  183. status: this.ruleForm.status,
  184. userId: this.ruleForm.userId,
  185. }
  186. params.userId = Number(params.userId)
  187. putWarehouse(params).then(res => {
  188. if (res.code == 200) {
  189. this.$message({
  190. message: '操作成功',
  191. type: 'success'
  192. });
  193. this.getList()
  194. }
  195. this.staffDialogVisible = false
  196. this.confirmLoading = false
  197. }).catch(() => {
  198. this.confirmLoading = false
  199. })
  200. }
  201. } else {
  202. this.$message.error('表单信息不完整,请继续填写完整');
  203. }
  204. },
  205. buttonData(row, type) {
  206. this.selectingData = row
  207. this.operationType = type
  208. if (type == 'edit') {
  209. this.staffTitle = '编辑'
  210. this.staffDialogVisible = true
  211. setTimeout(() => {
  212. this.$nextTick(() => {
  213. this.ruleForm = JSON.parse(JSON.stringify(row))
  214. this.ruleForm.userId = String(row.userId)
  215. })
  216. })
  217. } else if (type == 'del') {
  218. this.deleteUser(row.id)
  219. } else if (type == 'logs') {
  220. this.staffTitle = '详情'
  221. this.staffDialogVisible = true
  222. this.formRuleList.forEach((item, index) => {
  223. item.disabled = true
  224. })
  225. this.ruleForm = JSON.parse(JSON.stringify(row))
  226. this.ruleForm.userId = row.user.nickName
  227. }
  228. },
  229. openModel(type) {
  230. this.getDriver()
  231. this.staffTitle = '添加'
  232. this.staffDialogVisible = true
  233. this.operationType = type
  234. },
  235. // 删除仓库
  236. deleteUser(id) {
  237. this.$confirm('此操作将永久删除该仓库, 是否继续?', '提示', {
  238. confirmButtonText: '确定',
  239. cancelButtonText: '取消',
  240. type: 'warning'
  241. }).then(() => {
  242. delWarehouse({
  243. id: id,
  244. }).then(res => {
  245. if (res.code == 200) {
  246. this.$message({
  247. message: '操作成功',
  248. type: 'success'
  249. });
  250. this.getList()
  251. }
  252. })
  253. }).catch(() => {});
  254. },
  255. changeSize(val) {
  256. this.Pagination.PageSize = val
  257. this.getList()
  258. },
  259. changeCurrent(val) {
  260. this.Pagination.PageIndex = val
  261. this.getList()
  262. },
  263. // 清空表单
  264. closeDialog() {
  265. this.formRuleList.forEach((item, index) => {
  266. item.disabled = false
  267. })
  268. this.ruleForm = {}
  269. this.$refs.childRules.resetCheck();
  270. }
  271. }
  272. }
  273. </script>