list.vue 7.4 KB

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