index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="page-container">
  3. <div class="content-container">
  4. <TreeChoice v-model="hasDeptIds" @click="getList" @getDeptInfo="getDeptInfo" />
  5. <div class="main">
  6. <div class="table-nav">
  7. <div class="tags">
  8. <div class="tag">库位信息</div>
  9. </div>
  10. <div class="actions">
  11. <el-button type="primary" icon="el-icon-plus" size="mini" v-hasPermi="['system:dataPermissions:addRole']" style="margin-right: 10px" @click="addStockShow" v-if="hasDeptIds.length">添加</el-button>
  12. <right-toolbar @queryTable="getList" :isShowSearch="false"></right-toolbar>
  13. </div>
  14. </div>
  15. <!-- 数据角色表格 -->
  16. <el-table v-loading="loading" :data="dataList" border highlight-current-row>
  17. <el-table-column label="库位" prop="locationName" width="200"></el-table-column>
  18. <el-table-column label="公司部门" prop="deptName" width="300"></el-table-column>
  19. <el-table-column label="保管员" prop="keeperName" width="200"></el-table-column>
  20. <el-table-column label="描述" prop="remark" />
  21. <el-table-column label="操作" class-name="small-padding fixed-width" width="300" align="center">
  22. <template slot-scope="scope">
  23. <el-button size="mini" type="text" icon="el-icon-edit" @click="choiceUser(scope.row)" v-hasPermi="['system:dataPermissions:updRole']">保管员</el-button>
  24. <el-button size="mini" type="text" icon="el-icon-edit" @click="updStock(scope.row)" v-hasPermi="['system:dataPermissions:updRole']">修改</el-button>
  25. <el-button size="mini" type="text" icon="el-icon-delete" @click="delStock(scope.row)" v-hasPermi="['system:dataPermissions:delRole']">删除</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. <!-- 编辑弹窗 -->
  30. <el-dialog :title="title" :visible.sync="stockShow" width="30%">
  31. <el-form ref="stockForm" :model="stockForm" :rules="stockRules" label-width="100px">
  32. <el-form-item label="名称" prop="locationName">
  33. <div style="width: 300px"><el-input v-model="stockForm.locationName" placeholder="请输入名称" /></div>
  34. </el-form-item>
  35. <el-form-item label="描述">
  36. <div style="width: 300px"><el-input maxlength="80" v-model="stockForm.remark" placeholder="请输入描述" /></div>
  37. </el-form-item>
  38. <el-form-item label="公司部门">
  39. <div style="width: 300px"><el-input maxlength="80" disabled v-model="stockForm.deptName" /></div>
  40. </el-form-item>
  41. </el-form>
  42. <div slot="footer" class="dialog-footer">
  43. <el-button size="small" @click="stockCancel">取 消</el-button>
  44. <el-button type="primary" size="small" @click="stockSub">保 存</el-button>
  45. </div>
  46. </el-dialog>
  47. <UserChoice ref="userChoice" @selectedPerson="selectedPerson" />
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { stockList, stockAdd, stockUpd, stockDel, updateKeeper } from '@/api/system/stockLocation.js'
  54. import { treeselect } from '@/api/system/dept'
  55. import TreeChoice from '@/components/deptTreeChoice/index.vue'
  56. import UserChoice from '@/components/userChoice/index.vue'
  57. export default {
  58. name: 'stockLocation',
  59. components: {
  60. TreeChoice,
  61. UserChoice
  62. },
  63. data() {
  64. return {
  65. loading: false,
  66. //拥有权限的部门id数组
  67. hasDeptIds: [],
  68. //数据
  69. dataList: [],
  70. //库位编辑弹窗显示
  71. stockShow: false,
  72. //库位编辑弹窗标题
  73. title: '',
  74. // 部门信息
  75. deptOptions: [],
  76. //库位表单
  77. stockForm: { deptId: '', locationName: '', remark: '', deptName: '' },
  78. //库位表单验证
  79. stockRules: { locationName: [{ required: true, message: '名称不能为空', trigger: 'blur' }] },
  80. locationId: '' // 库位id
  81. }
  82. },
  83. methods: {
  84. //获取数据
  85. getList() {
  86. if (!this.hasDeptIds.length) {
  87. this.dataList = []
  88. return
  89. }
  90. this.loading = true
  91. stockList({ deptIds: this.hasDeptIds }).then(res => {
  92. if (res.code === 200) {
  93. this.dataList = res.data
  94. this.loading = false
  95. }
  96. })
  97. },
  98. //获取部门信息
  99. getDeptInfo(d) {
  100. this.stockForm.deptId = d.deptId
  101. this.stockForm.deptName = d.deptName
  102. },
  103. //显示库位弹窗
  104. addStockShow() {
  105. this.title = '库位添加'
  106. this.stockShow = true
  107. },
  108. //表单重置
  109. resetForm() {
  110. this.stockForm = { deptId: '', locationName: '', remark: '', deptName: '' }
  111. },
  112. //检测重名
  113. checkName(data) {
  114. let o = this.dataList.find(item => item.locationName == data.locationName && item.locationId != data.locationId)
  115. if (o) {
  116. return '库位名称重复'
  117. }
  118. return false
  119. },
  120. //库位弹窗取消
  121. stockCancel() {
  122. this.resetForm()
  123. this.stockShow = false
  124. },
  125. //库位弹窗提交
  126. stockSub() {
  127. this.$refs.stockForm.validate(valid => {
  128. if (valid) {
  129. let checkFiled = this.checkName(this.stockForm)
  130. if (checkFiled) {
  131. this.$msg({ type: 'error', message: checkFiled })
  132. return
  133. }
  134. if (this.stockForm.locationId) {
  135. stockUpd(this.stockForm).then(res => {
  136. if (res.code === 200) {
  137. this.$msg({ message: '修改成功' })
  138. this.dataList = this.dataList.map(item => {
  139. if (item.locationId == this.stockForm.locationId) {
  140. return {
  141. ...item,
  142. ...this.stockForm
  143. }
  144. }
  145. return {
  146. ...item
  147. }
  148. })
  149. this.stockCancel()
  150. }
  151. })
  152. } else {
  153. stockAdd(this.stockForm).then(res => {
  154. if (res.code === 200) {
  155. this.$msg({ message: '添加成功' })
  156. this.getList()
  157. this.stockCancel()
  158. }
  159. })
  160. }
  161. }
  162. })
  163. },
  164. //选择人员
  165. choiceUser(row) {
  166. this.locationId = row.locationId
  167. treeselect().then(response => {
  168. this.deptOptions = response.data
  169. this.deptOptions.unshift({ id: '0', label: '全部部门' })
  170. this.$refs.userChoice.init(true, this.deptOptions)
  171. })
  172. },
  173. //人员回调
  174. selectedPerson(data) {
  175. updateKeeper({ keeper: data, locationId: this.locationId }).then(res => {
  176. this.getList()
  177. })
  178. },
  179. //修改
  180. updStock(row) {
  181. this.stockForm = {
  182. deptId: row.deptId,
  183. locationName: row.locationName,
  184. remark: row.remark,
  185. deptName: row.deptName,
  186. locationId: row.locationId
  187. }
  188. this.title = '库位修改'
  189. this.stockShow = true
  190. },
  191. //删除
  192. delStock(row) {
  193. this.$modal
  194. .confirm('确定要删除吗')
  195. .then(() => {
  196. stockDel(row.locationId).then(res => {
  197. if (res.code == 200) {
  198. this.$msg({ message: '删除成功' })
  199. this.dataList = this.dataList.filter(item => item.locationId != row.locationId)
  200. } else {
  201. this.$msg({ type: 'error', message: res.msg })
  202. }
  203. })
  204. })
  205. .catch(() => {})
  206. }
  207. }
  208. }
  209. </script>
  210. <style></style>