list.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 { warehouseList, warehouseDel } from '@/api/warehouse'
  70. import { STable } from '@/components'
  71. import warehouseEditModal from './editModal.vue'
  72. export default {
  73. components: { STable, warehouseEditModal },
  74. data () {
  75. return {
  76. spinning: false,
  77. queryParam: { // 查询条件
  78. name: '' // 仓库名称
  79. },
  80. tableHeight: 0,
  81. disabled: false, // 查询、重置按钮是否可操作
  82. columns: [
  83. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  84. { title: '仓库名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  85. { title: '排序', dataIndex: 'sort', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  86. { title: '操作', scopedSlots: { customRender: 'action' }, align: 'center' }
  87. ],
  88. // 加载数据方法 必须为 Promise 对象
  89. loadData: parameter => {
  90. this.disabled = true
  91. this.spinning = true
  92. return warehouseList(Object.assign(parameter, this.queryParam)).then(res => {
  93. const data = res.data
  94. const no = (data.pageNo - 1) * data.pageSize
  95. for (var i = 0; i < data.list.length; i++) {
  96. data.list[i].no = no + i + 1
  97. }
  98. this.disabled = false
  99. this.spinning = false
  100. return data
  101. })
  102. },
  103. openModal: false, // 新增编辑 弹框
  104. itemId: '', // 当前id
  105. nowData: null // 当前记录数据
  106. }
  107. },
  108. methods: {
  109. // 重置
  110. resetSearchForm () {
  111. this.queryParam.name = ''
  112. this.$refs.table.refresh(true)
  113. },
  114. // 新增/编辑
  115. handleEdit (row) {
  116. this.itemId = row ? row.id : null
  117. this.nowData = row || null
  118. this.openModal = true
  119. },
  120. // 新增/编辑 成功
  121. handleOk () {
  122. this.$refs.table.refresh(true)
  123. },
  124. // 关闭弹框
  125. closeModal () {
  126. this.itemId = ''
  127. this.openModal = false
  128. },
  129. // 删除
  130. handleDel (row) {
  131. const _this = this
  132. this.$confirm({
  133. title: '提示',
  134. content: '删除后不可恢复,确定要进行删除吗?',
  135. centered: true,
  136. onOk () {
  137. _this.spinning = true
  138. warehouseDel({
  139. id: row.id
  140. }).then(res => {
  141. if (res.status == 200) {
  142. _this.$message.success(res.message)
  143. _this.$refs.table.refresh()
  144. _this.spinning = false
  145. } else {
  146. _this.spinning = false
  147. }
  148. })
  149. }
  150. })
  151. },
  152. // 查看仓位
  153. goStoringLocation (row) {
  154. this.$router.push({ path: `/inventoryManagement/storingLocation/${row.warehouseSn}`, query: { name: row.name } })
  155. },
  156. pageInit () {
  157. const _this = this
  158. this.$nextTick(() => { // 页面渲染完成后的回调
  159. _this.setTableH()
  160. })
  161. },
  162. setTableH () {
  163. const tableSearchH = this.$refs.tableSearch.offsetHeight
  164. this.tableHeight = window.innerHeight - tableSearchH - 235
  165. }
  166. },
  167. mounted () {
  168. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  169. this.pageInit()
  170. this.resetSearchForm()
  171. }
  172. },
  173. activated () {
  174. // 如果是新页签打开,则重置当前页面
  175. if (this.$store.state.app.isNewTab) {
  176. this.pageInit()
  177. this.resetSearchForm()
  178. }
  179. // 仅刷新列表,不重置页面
  180. if (this.$store.state.app.updateList) {
  181. this.pageInit()
  182. this.$refs.table.refresh()
  183. }
  184. },
  185. beforeRouteEnter (to, from, next) {
  186. next(vm => {})
  187. }
  188. }
  189. </script>