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
<template>
  <TableLayout v-permissions="['ext:materialdistributeext:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="120px" label-suffix=":" inline>
      <el-form-item label="物料编码" prop="mmodelCode">
        <el-input v-model="searchForm.mmodelCode" placeholder="请输入物料编码" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="物料名称" prop="mmodelUnionName">
        <el-input v-model="searchForm.mmodelUnionName" placeholder="请输入物料名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="物料分类组合" prop="cateUnionId">
        <el-select v-model="searchForm.cateUnionId" filterable clearable placeholder="请选择">
          <el-option
            v-for="(item, index) in types"
            :key="index"
            :label="item.combinationName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="形成方式" prop="formation">
        <el-select v-model="searchForm.formation" filterable clearable placeholder="请选择">
          <el-option
            v-for="(item, index) in accesses"
            :key="index"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="searchForm.status" filterable 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>
      <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" >
        <li><el-button type="primary" v-if="containPermissions(['ext:barcodeparamext:query'])" plain @click="printLabelWithArray">打印标签</el-button></li>
        <li><el-button type="danger" plain @click="unvalidWithArray">失效</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 label="物料编码" min-width="160px">
          <template slot-scope="{row}">
            <el-button type="text">
              {{ row.mmodelCode }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column prop="unionName" label="物料组合名称" show-overflow-tooltip min-width="140px">
          <template slot-scope="{row}">
            <span class="long-title-style" >{{ row.unionName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="umodelName" label="单位" min-width="60px"></el-table-column>
        <el-table-column prop="unionCategoryName" label="物料分类" show-overflow-tooltip min-width="140px">
          <template slot-scope="{row}">
            <span class="long-title-style" >{{ row.unionCategoryName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="形成方式"
          min-width="80px"
        >
          <template slot-scope="{row}">
            {{ row.formation == '0' ? '生产' : '采购' }}
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          min-width="80"
        >
          <template slot-scope="{row}">
            <el-tag v-if="row.status == 1" type="success">有效</el-tag>
            <el-tag v-if="row.status == 0" type="danger">失效</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="140px"></el-table-column>
        <el-table-column
          label="操作"
          min-width="120px"
          fixed="right"
        >
          <template slot-scope="{row}">
            <div v-if="row.status == '1'">
              <el-button type="text"  v-if="containPermissions(['ext:barcodeparamext:query'])" @click="printLabel(row)">打印标签</el-button>
              <span style="margin-left: 8px;" v-permissions="['ext:materialdistributeext:create']">
                <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>
    <!-- <OperaMaterialDetailWindow ref="operaMaterialDetailWindow"/> -->
    <QrCodeLabel ref="qrCodeLabel"></QrCodeLabel>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import QrCodeLabel from '@/components/common/QrCodeLabel'
// import OperaMaterialDetailWindow from '@/components/ext/OperaMaterialDetailWindow'
import { updateStatusById } from '@/api/ext/materialDistributeExt'
import { getCategoryUnionListByOrg } from '@/api/ext/materialExt'
import { fetchList as getPrefix } from '@/api/ext/barcodeParamExt'
export default {
  name: 'MaterialDistributeExt',
  extends: BaseTable,
  components: { TableLayout, Pagination, QrCodeLabel },
  data () {
    return {
      // 搜索
      searchForm: {
        mmodelCode: '',
        mmodelUnionName: '',
        cateUnionId: '',
        formation: '',
        status: ''
      },
      accesses: [
        // 形成方式 0生产、1.采购
        { name: '生产', id: '0' },
        { name: '采购', id: '1' }
      ],
      types: [
        { name: '1', id: '1' },
        { name: '2', id: '2' },
        { name: '3', id: '3' }
      ],
      status: [
        { name: '有效', id: '1' },
        { name: '失效', id: '0' }
      ],
      printList: [],
      prefix: ''
    }
  },
  created () {
    this.config({
      module: '子组织物料',
      api: '/ext/materialDistributeExt',
      'field.id': 'id',
      'field.main': 'name',
      sorts: [{ direction: 'DESC', property: 'CREATE_TIME' }]
    })
    this.search()
    getCategoryUnionListByOrg()
      .then(res => {
        this.types = res
        // console.log(this.types)
      })
      .catch(err => {
        console.log(err)
      })
    getPrefix({
      page: 1,
      capacity: 1,
      model: { type: 0, status: 1 }
    })
      .then(res => {
        this.prefix = res.records[0].prefix
      })
  },
  methods: {
    unvalid (row) {
      // console.log('失效', row)
      this.$confirm('是否将该条物料信息设置为失效?', '提示', {
        confirmButtonText: '失效',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const query = '?status=0&ids=' + row.id
        this.updateStatus(query)
      }).catch(() => {})
    },
    printLabel (row) {
      // console.log('打印标签', row)
      this.printList = [{
        code: row.mmodelCode,
        // title: row.mmodelCode,
        // content: row.unionName,
        title: row.unionName,
        content: row.mmodelCode,
        department: this.$store.state.userInfo.curComDepartment.name
      }]
      this.$refs.qrCodeLabel.open('打印标签', this.printList, this.prefix)
    },
    unvalidWithArray () {
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请至少选择一条数据')
        return
      }
      const ids = []
      for (const item of this.tableData.selectedRows) {
        if (item.status === 0) {
          this.$tip.error(`${item.name}已经失效!不可进行失效操作!`)
          return
        }
        ids.push(item.id)
      }
      this.$confirm(`是否将${this.tableData.selectedRows.length}条物料信息设置为失效?`, '提示', {
        confirmButtonText: '失效',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const query = '?status=0&ids=' + ids.join(',')
        this.updateStatus(query)
      }).catch(() => {})
      
    },
    printLabelWithArray () {
      // console.log('批量打印标签')
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请至少选择一条数据')
        return
      }
      // console.log(this.tableData.selectedRows)
      this.printList = this.tableData.selectedRows.map((item) => {
        return {
          code: item.mmodelCode,
          title: item.unionName,
          content: item.mmodelCode,
          department: this.$store.state.userInfo.curComDepartment.name,
        }
      })
      this.$refs.qrCodeLabel.open('打印标签', this.printList, this.prefix)
    },
    updateStatus (q) {
      updateStatusById(q)
        .then(res => {
          this.$message.success('成功')
          this.search()
        })
        .catch(err => {
          console.log(err)
          this.$message.error('失败')
        })
    }
    // showDetail (row) {
    //   console.log('详情')
    //   materialDistributeExt(row.id)
    //     .then(res => {
    //       console.log('res', res)
    //       this.$refs.operaMaterialDetailWindow.open('物料详细', res)
    //     })
    //     .catch(err => {
    //       console.log(err)
    //       this.$message.error('获取详情失败')
    //     })
    // }
  }
}
</script>