list.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_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. <a-button
  39. size="small"
  40. type="link"
  41. class="button-warning"
  42. @click="goStoringLocation(record)"
  43. v-if="$hasPermissions('B_warehouse_ckSet')"
  44. id="warehouseList-storingLocation-btn">仓位管理</a-button>
  45. <a-button
  46. size="small"
  47. type="link"
  48. class="button-info"
  49. v-if="record.defaultFlag!='1' &&$hasPermissions('B_warehouse_edit') "
  50. @click="handleEdit(record)"
  51. id="warehouseList-edit-btn">编辑</a-button>
  52. <a-button
  53. size="small"
  54. type="link"
  55. class="button-error"
  56. v-if="record.defaultFlag!='1' &&$hasPermissions('B_warehouse_del')"
  57. @click="handleDel(record)"
  58. id="warehouseList-del-btn">删除</a-button>
  59. <span v-if="record.defaultFlag=='0' && !$hasPermissions('B_warehouse_edit') && !$hasPermissions('B_warehouse_del')">--</span>
  60. </template>
  61. </s-table>
  62. </a-spin>
  63. <!-- 新增/编辑仓库 -->
  64. <warehouse-edit-modal :openModal="openModal" :nowData="nowData" :itemSn="itemSn" @ok="handleOk" @close="closeModal" />
  65. </a-card>
  66. </template>
  67. <script>
  68. import { warehouseList, warehouseDel } from '@/api/warehouse'
  69. import { STable } from '@/components'
  70. import warehouseEditModal from './editModal.vue'
  71. export default {
  72. components: { STable, warehouseEditModal },
  73. data () {
  74. return {
  75. spinning: false,
  76. queryParam: { // 查询条件
  77. name: '' // 仓库名称
  78. },
  79. tableHeight: 0,
  80. disabled: false, // 查询、重置按钮是否可操作
  81. columns: [
  82. { title: '序号', dataIndex: 'no', width: '10%', align: 'center' },
  83. { title: '仓库名称', dataIndex: 'name', align: 'center', width: '45%', ellipsis: true, customRender: function (text) { return text || '--' } },
  84. { title: '操作', scopedSlots: { customRender: 'action' }, align: 'center', width: '45%' }
  85. ],
  86. // 加载数据方法 必须为 Promise 对象
  87. loadData: parameter => {
  88. this.disabled = true
  89. this.spinning = true
  90. return warehouseList(Object.assign(parameter, this.queryParam)).then(res => {
  91. const data = res.data
  92. const no = (data.pageNo - 1) * data.pageSize
  93. for (var i = 0; i < data.list.length; i++) {
  94. data.list[i].no = no + i + 1
  95. }
  96. this.disabled = false
  97. this.spinning = false
  98. return data
  99. })
  100. },
  101. openModal: false, // 新增编辑 弹框
  102. itemSn: '', // 当前sn
  103. nowData: null // 当前记录数据
  104. }
  105. },
  106. methods: {
  107. // 重置
  108. resetSearchForm () {
  109. this.queryParam.name = ''
  110. this.$refs.table.refresh(true)
  111. },
  112. // 新增/编辑
  113. handleEdit (row) {
  114. this.itemSn = row ? row.warehouseSn : null
  115. this.nowData = row || null
  116. this.openModal = true
  117. },
  118. // 新增/编辑 成功
  119. handleOk () {
  120. this.$refs.table.refresh(true)
  121. },
  122. // 关闭弹框
  123. closeModal () {
  124. this.itemSn = ''
  125. this.openModal = false
  126. },
  127. // 删除
  128. handleDel (row) {
  129. const _this = this
  130. this.$confirm({
  131. title: '提示',
  132. content: '删除后不可恢复,确定要进行删除吗?',
  133. centered: true,
  134. onOk () {
  135. _this.spinning = true
  136. warehouseDel({
  137. sn: row.warehouseSn
  138. }).then(res => {
  139. if (res.status == 200) {
  140. _this.$message.success(res.message)
  141. _this.$refs.table.refresh()
  142. _this.spinning = false
  143. } else {
  144. _this.spinning = false
  145. }
  146. })
  147. }
  148. })
  149. },
  150. // 查看仓位
  151. goStoringLocation (row) {
  152. this.$router.push({ path: `/basicData/storingLocation/${row.warehouseSn}`, query: { name: row.name } })
  153. },
  154. pageInit () {
  155. const _this = this
  156. this.$nextTick(() => { // 页面渲染完成后的回调
  157. _this.setTableH()
  158. })
  159. },
  160. setTableH () {
  161. const tableSearchH = this.$refs.tableSearch.offsetHeight
  162. this.tableHeight = window.innerHeight - tableSearchH - 235
  163. }
  164. },
  165. watch: {
  166. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  167. this.setTableH()
  168. }
  169. },
  170. mounted () {
  171. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  172. this.pageInit()
  173. this.resetSearchForm()
  174. }
  175. },
  176. activated () {
  177. // 如果是新页签打开,则重置当前页面
  178. if (this.$store.state.app.isNewTab) {
  179. this.pageInit()
  180. this.resetSearchForm()
  181. }
  182. // 仅刷新列表,不重置页面
  183. if (this.$store.state.app.updateList) {
  184. this.$refs.table.refresh()
  185. this.pageInit()
  186. }
  187. },
  188. beforeRouteEnter (to, from, next) {
  189. next(vm => {})
  190. }
  191. }
  192. </script>