list.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <a-card size="small" :bordered="false" class="warehouseList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="仓库名称">
  10. <a-input id="warehouseList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入仓库名称"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="warehouseList-refresh">查询</a-button>
  15. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="warehouseList-reset">重置</a-button>
  16. </a-col>
  17. </a-row>
  18. </a-form>
  19. </div>
  20. <!-- 操作按钮 -->
  21. <div class="table-operator">
  22. <a-button v-if="$hasPermissions('B_inventory_warehouse_add')" id="warehouseList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  23. </div>
  24. <!-- 列表 -->
  25. <s-table
  26. class="sTable fixPagination"
  27. ref="table"
  28. :style="{ height: tableHeight+84.5+'px' }"
  29. size="small"
  30. :rowKey="(record) => record.id"
  31. :columns="columns"
  32. :data="loadData"
  33. :scroll="{ y: tableHeight }"
  34. :defaultLoadData="false"
  35. bordered>
  36. <!-- 操作 -->
  37. <template slot="action" slot-scope="text, record">
  38. <!-- record.sysFlag表示该仓库是否默认,为默认仓库时则不可删除不可编辑 -->
  39. <a-button
  40. size="small"
  41. v-if="$hasPermissions('M_inventoryWarehouseStoringLocationList')"
  42. type="link"
  43. class="button-warning"
  44. @click="goStoringLocation(record)"
  45. id="warehouseList-storingLocation-btn">仓位管理</a-button>
  46. <a-button
  47. size="small"
  48. v-if="$hasPermissions('B_inventory_warehouse_edit') && record.sysFlag==0"
  49. type="link"
  50. class="button-info"
  51. @click="handleEdit(record)"
  52. id="warehouseList-edit-btn">编辑</a-button>
  53. <a-button
  54. size="small"
  55. v-if="$hasPermissions('B_inventory_warehouse_del') && record.sysFlag==0"
  56. type="link"
  57. class="button-error"
  58. @click="handleDel(record)"
  59. id="warehouseList-del-btn">删除</a-button>
  60. <span v-if="!$hasPermissions('M_inventoryWarehouseStoringLocationList') && !$hasPermissions('B_inventory_warehouse_edit') && !$hasPermissions('B_inventory_warehouse_del')">--</span>
  61. </template>
  62. </s-table>
  63. </a-spin>
  64. <!-- 新增/编辑仓库 -->
  65. <warehouse-edit-modal :openModal="openModal" :nowData="nowData" :itemId="itemId" @ok="handleOk" @close="closeModal" />
  66. </a-card>
  67. </template>
  68. <script>
  69. import { commonMixin } from '@/utils/mixin'
  70. import { warehouseList, warehouseDel } from '@/api/warehouse'
  71. import { STable } from '@/components'
  72. import warehouseEditModal from './editModal.vue'
  73. export default {
  74. name: 'WarehouseList',
  75. components: { STable, warehouseEditModal },
  76. mixins: [commonMixin],
  77. data () {
  78. return {
  79. spinning: false,
  80. queryParam: { // 查询条件
  81. name: '' // 仓库名称
  82. },
  83. tableHeight: 0,
  84. disabled: false, // 查询、重置按钮是否可操作
  85. columns: [
  86. { title: '序号', dataIndex: 'no', width: '14%', align: 'center' },
  87. { title: '仓库名称', dataIndex: 'name', width: '40%', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  88. { title: '排序', dataIndex: 'sort', width: '16%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  89. { title: '操作', scopedSlots: { customRender: 'action' }, width: '30%', align: 'center' }
  90. ],
  91. // 加载数据方法 必须为 Promise 对象
  92. loadData: parameter => {
  93. this.disabled = true
  94. this.spinning = true
  95. return warehouseList(Object.assign(parameter, this.queryParam)).then(res => {
  96. let data
  97. if (res.status == 200) {
  98. data = res.data
  99. const no = (data.pageNo - 1) * data.pageSize
  100. for (var i = 0; i < data.list.length; i++) {
  101. data.list[i].no = no + i + 1
  102. }
  103. this.disabled = false
  104. }
  105. this.spinning = false
  106. return data
  107. })
  108. },
  109. openModal: false, // 新增编辑 弹框
  110. itemId: '', // 当前id
  111. nowData: null // 当前记录数据
  112. }
  113. },
  114. methods: {
  115. // 重置
  116. resetSearchForm () {
  117. this.queryParam.name = ''
  118. this.$refs.table.refresh(true)
  119. },
  120. // 新增/编辑
  121. handleEdit (row) {
  122. this.itemId = row ? row.id : null
  123. this.nowData = row || null
  124. this.openModal = true
  125. },
  126. // 新增/编辑 成功
  127. handleOk () {
  128. this.$refs.table.refresh(true)
  129. },
  130. // 关闭弹框
  131. closeModal () {
  132. this.itemId = ''
  133. this.openModal = false
  134. },
  135. // 删除
  136. handleDel (row) {
  137. const _this = this
  138. this.$confirm({
  139. title: '提示',
  140. content: '删除后不可恢复,确定要进行删除吗?',
  141. centered: true,
  142. onOk () {
  143. _this.spinning = true
  144. warehouseDel({
  145. id: row.id
  146. }).then(res => {
  147. if (res.status == 200) {
  148. _this.$message.success(res.message)
  149. _this.$refs.table.refresh()
  150. _this.spinning = false
  151. } else {
  152. _this.spinning = false
  153. }
  154. })
  155. }
  156. })
  157. },
  158. // 查看仓位
  159. goStoringLocation (row) {
  160. this.$router.push({ path: `/inventoryManagement/storingLocation/${row.warehouseSn}`, query: { name: row.name } })
  161. },
  162. pageInit () {
  163. const _this = this
  164. this.$nextTick(() => { // 页面渲染完成后的回调
  165. _this.setTableH()
  166. })
  167. },
  168. setTableH () {
  169. const tableSearchH = this.$refs.tableSearch.offsetHeight
  170. this.tableHeight = window.innerHeight - tableSearchH - 235
  171. }
  172. },
  173. watch: {
  174. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  175. this.setTableH()
  176. }
  177. },
  178. mounted () {
  179. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  180. this.pageInit()
  181. this.resetSearchForm()
  182. }
  183. },
  184. activated () {
  185. // 如果是新页签打开,则重置当前页面
  186. if (this.$store.state.app.isNewTab) {
  187. this.pageInit()
  188. this.resetSearchForm()
  189. }
  190. // 仅刷新列表,不重置页面
  191. if (this.$store.state.app.updateList) {
  192. this.pageInit()
  193. this.$refs.table.refresh()
  194. }
  195. },
  196. beforeRouteEnter (to, from, next) {
  197. next(vm => {})
  198. }
  199. }
  200. </script>