Mr.Shi
2023-08-11 5a7fb4358eb902ce139096f20ef3c0625adcd7f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<template>
  <TableLayout v-permissions="['ext:warehouseext:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" label-suffix=":" inline>
      <el-form-item label="仓库名称" prop="name">
        <el-input v-model="searchForm.name" placeholder="请输入仓库名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="仓库归属" prop="ascription">
        <el-select v-model="searchForm.ascription" clearable filterable placeholder="请选择">
          <el-option
            v-for="(item, index) in ascriptions"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="仓库类型" prop="type">
        <el-select v-model="searchForm.type" clearable filterable placeholder="请选择">
          <el-option
            v-for="(item, index) in types"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="仓库属性" prop="systemDicDataId">
        <el-select v-model="searchForm.systemDicDataId" clearable placeholder="请选择">
          <el-option
            v-for="(item, index) in properties"
            :key="index"
            :label="item.code"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="仓库状态" prop="status">
        <el-select v-model="searchForm.status" clearable placeholder="请选择">
          <el-option
            v-for="(item, index) in status"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="启用货位" prop="useLocation">
        <el-select v-model="searchForm.useLocation" placeholder="请选择">
          <el-option
            v-for="(item, index) in useLocation"
            :key="index"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <!-- <ul class="toolbar" v-permissions="['ext:warehouseext:create', 'ext:warehouseext:delete']">
        <li><el-button type="primary" @click="$refs.operaWarehouseExtWindow.open('新建仓库信息')" icon="el-icon-plus" v-permissions="['ext:warehouseext:create']">新建</el-button></li>
        <li><el-button @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['ext:warehouseext:delete']">删除</el-button></li>
      </ul> -->
      <ul class="toolbar">
        <li><el-button v-permissions="['ext:warehouseext:create']" type="primary" @click="$refs.operaWarehouseExtWindow.open('新建仓库')">新建</el-button></li>
        <!-- <li><el-button type="primary" plain  @click="unvalid(row)" class="unvalid-style">打印标签</el-button></li> -->
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" fixed="left" width="55"></el-table-column>
        <el-table-column prop="name" fixed="left" label="仓库名称" show-overflow-tooltip="" min-width="140px">
          <template slot-scope="{row}">
            <span class="long-title-style">{{ row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="code" label="仓库编码" min-width="100px"></el-table-column>
        <el-table-column label="仓库归属" min-width="100px">
          <template slot-scope="{row}">
            {{ ascriptionToStr(row.ascription) }}
          </template>
        </el-table-column>
        <el-table-column prop="type" label="仓库类型" min-width="100px">
          <template slot-scope="{row}">
            {{ typeToStr(row.type) }}
          </template>
        </el-table-column>
        <el-table-column prop="useLocation" label="启用货位" min-width="100px">
          <template slot-scope="{row}">
            <el-switch
              :disabled="!containPermissions(['ext:warehouseext:update'])"
              v-model="row.useLocation"
              :inactive-value="0"
              :active-value="1"
              @change="changeStatus(row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="tmodel.code" label="仓库属性" min-width="100px"></el-table-column>
        <!-- <el-table-column prop="dmodelName" label="所属组织" min-width="100px"></el-table-column> -->
        <el-table-column prop="mmodel.realname" label="管理员" min-width="100px"></el-table-column>
        <el-table-column prop="status" label="可销售" min-width="60px">
          <template slot-scope="{row}">
            <span v-if="row.isSales == 0" class="valid-style">是</span>
            <span v-if="row.isSales == 1" class="unvalid-style">否</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="仓库状态" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.status == '1'" class="valid-style">有效</span>
            <span v-if="row.status == '0'" class="unvalid-style">失效</span>
          </template>
        </el-table-column>
        <el-table-column prop="addr" label="仓库地址" show-overflow-tooltip="" min-width="180px">
          <template slot-scope="{row}">
            <span class="long-title-style" :title="row.addr">{{ row.addr }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="140px"></el-table-column>
        <!-- <el-table-column
          v-if="containPermissions(['ext:warehouseext:update', 'ext:warehouseext:delete'])"
          label="操作"
          min-width="120"
          fixed="right"
        > -->
        <el-table-column
          label="操作"
          min-width="160px"
          fixed="right"
        >
          <template slot-scope="{row}">
            <div v-if="row.status == '1'">
              <el-button type="text" @click="editWhouse(row)" v-permissions="['ext:warehouseext:update']">编辑</el-button>
              <!-- <el-button type="text"  @click="printLabel(row)" class="unvalid-style">打印标签</el-button> -->
              <span style="margin: 8px;" v-permissions="['ext:warehouseext:delete']">
                <el-button type="text" @click="unvalid(row)">失效</el-button>
              </span>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      >
      </pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaWarehouseExtWindow ref="operaWarehouseExtWindow" @success="handlePageChange"/>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
// import SearchFormCollapse from '@/components/common/SearchFormCollapse'
import Pagination from '@/components/common/Pagination'
import { updateMateriaStatus, updateHWStatus, warehouseExt } from '@/api/ext/warehouseExt'
import { queryListByCode } from '@/api/system/dictData'
import OperaWarehouseExtWindow from '@/components/ext/OperaWarehouseExtWindow'
export default {
  name: 'WarehouseExt',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaWarehouseExtWindow },
  data () {
    return {
      status: [
        { name: '失效', id: '0' },
        { name: '有效', id: '1' }
      ],
      useLocation: [
        { name: '禁用', id: '0' },
        { name: '启用', id: '1' }
      ],
      ascriptions: [
        //  0公司库 1车间库 2外协库
        { name: '公司库', id: 0 },
        { name: '车间库', id: 1 },
        { name: '外协库', id: 2 },
      ],
      types: [
        // 0原材料库 1半成品库 2成品库 3不良品库 4线边库
        { name: '原材料库', id: 0 },
        { name: '半成品库', id: 1 },
        { name: '成品库', id: 2 },
        { name: '不良品库', id: 3 },
        { name: '线边库', id: 4 },
        // 客退库、客返库、让步库、非品库
        { name: '客退库', id: 5 },
        { name: '客返库', id: 6 },
        { name: '让步库', id: 7 },
        { name: '废品库', id: 8 },
      ],
      // 搜索
      searchForm: {
        ascription: null,
        systemDicDataId: null,
        useLocation: null,
        name: null,
        cell: null,
        area: null,
        type: null,
        code: null,
        shelf: null
      },
      properties: []
    }
  },
  provide() {
    return {
      properties: () => this.properties
    }
  },
  created () {
    this.config({
      module: '仓库信息',
      api: '/ext/warehouseExt',
      'field.id': 'id',
      'field.main': 'name',
      sorts: [{ direction: 'DESC', property: 'CREATE_TIME' }]
    })
    queryListByCode('?dicCode=SYSTEM_APPLIANCE_TYPE')
      .then(res => {
        // console.log(res)
        this.properties = res
      })
      .catch(err => {
        console.log(err)
      })
    this.search()
  },
  methods: {
    typeToStr (type) {
      for (const item of this.types) {
        if (item.id === type) return item.name
      }
    },
    unvalidWithArray (row) {
      console.log('失效', row)
    },
    ascriptionToStr(ascription) {
      for (const item of this.ascriptions) {
        if (item.id === ascription) return item.name
      }
    },
    editWhouse (row) {
      warehouseExt(row.id)
        .then(res => {
          res.systemDicDataId = parseInt(res.systemDicDataId)
          this.$refs.operaWarehouseExtWindow.open('编辑仓库信息', res)
        })
        .catch(err => {
          this.$tip.error(err)
        })
      // console.log('失效', row)
    },
    unvalid (row) {
      this.$confirm('此操作将会让此仓库失效,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateMateriaStatus(row.id, '0')
          .then(res => {
            this.handlePageChange()
          })
          .catch(err => {
            this.$tip.error(err)
          })
      }).catch(() => {
 
      })
    },
    printLabel (row) {
      console.log('打印标签', row)
    },
    // 修改货位启用禁用
    changeStatus (row) {
      // console.log(row)
      updateHWStatus(row.id, row.useLocation)
        .then(res => {
          // this.search()
        })
        .catch(err => {
          this.$tip.error(err)
        })
        .finally(() => {
          this.handlePageChange()
        })
    }
  }
}
 
 
</script>