Mr.Zhang
2023-08-14 287934f48daa9889f824e12d1af687bc5aa3bbe2
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<template>
  <TableLayout :permissions="['ext:workplans:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" label-suffix=":" :model="searchForm" label-width="90px" inline>
      <el-form-item label="物料名称" prop="materialName">
        <el-input v-model="searchForm.materialName" placeholder="请输入" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="物料编码" prop="materialCode">
        <el-input v-model="searchForm.materialCode" placeholder="请输入" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="成品计划" prop="planCode">
        <el-input v-model="searchForm.planCode" placeholder="请输入成品计划编码" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="计划状态" prop="planStatus">
        <el-select v-model="searchForm.planStatus" placeholder="请选择" clearable @change="search">
          <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工厂" prop="factoryId">
        <el-select v-model="searchForm.factoryId" placeholder="请选择" clearable @change="search">
          <el-option v-for="item in factoryList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="批次号" prop="batch">
        <el-input v-model="searchForm.batch" placeholder="请输入" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="计划日期" prop="planDate">
        <el-date-picker style="width: 300px;" @change="changeDate" v-model="searchForm.planDate" type="datetimerange"
          value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <!-- <el-button type="primary" :loading="isWorking.export" v-permissions="['ext:workplans:exportExcel']" @click="exportExcel">导出</el-button> -->
        <el-button @click="resets">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar" v-permissions="['ext:workplans:create', 'ext:workplans:delete']">
        <li><el-button type="primary" @click="$refs.operaWorkPlansWindow.open('新建成品计划')"  v-permissions="['ext:workplans:create']">新建</el-button></li>
        <li>
          <ImportButton
            text="导入"
            template-name="workplans_import_template.xlsx"
            template-path="template/workplans_import_template.xlsx"
            action="/business/workPlans/importBatch"
            @success="search"
          />
        </li>
        <li><el-button type="primary" @click="exportExcel">导出</el-button></li>
        <li><el-button type="primary" @click="batchPublishing">批量发布</el-button></li>
        <!-- deleteByIdInBatch -->
        <li><el-button type="danger" @click="deleteByIds" icon="el-icon-delete" v-permissions="['ext:workplans:delete']">批量删除</el-button></li>
      </ul>
      <el-table v-loading="isWorking.search" :data="tableData.list" border stripe @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="planCode" label="成品计划编码" min-width="150px">
          <template slot-scope="{row}">
            <el-button type="text" @click="$refs.plannedProgress.open('计划执行进度', row)">
              <span class="long-title-style">{{ row.planCode }}</span>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column prop="materialName" label="物料名称" min-width="100px"></el-table-column>
        <el-table-column prop="materialCode" label="物料编码" min-width="100px"></el-table-column>
        <el-table-column prop="startDate" label="计划开始日期" min-width="100px"></el-table-column>
        <el-table-column prop="planDate" label="计划完成日期" min-width="100px"></el-table-column>
        <el-table-column prop="factoryName" label="工厂" min-width="100px"></el-table-column>
        <el-table-column prop="batch" label="生产批次号" min-width="100px"></el-table-column>
        <el-table-column prop="num" label="计划数量" min-width="100px"></el-table-column>
        <el-table-column label="状态" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.status == 0">已生成</span>
            <span v-else-if="row.status == 1">执行中</span>
            <!-- <span v-else-if="row.status == 2">已撤回</span>
                <span v-else-if="row.status == 3">已取消</span>
                <span v-else-if="row.status == 4">已分配</span>
                <span v-else-if="row.status == 5">已暂停</span> -->
            <span v-else-if="row.status == 6">已完工</span>
            <!-- <span v-else-if="row.status == 7">已入库</span> -->
            <span v-else-if="row.status == 8">已关闭</span>
          </template>
        </el-table-column>
        <el-table-column label="完工数" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.finishNum">{{ row.finishNum }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="完工合格数" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.finishQualifiedNum">{{ row.finishQualifiedNum }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="完工不良数" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.finishUnQualifiedNum">{{ row.finishUnQualifiedNum }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
 
        <el-table-column label="销售订单" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.salesorder">{{ row.salesorder }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column prop="urgent" label="优先级" min-width="80px">
          <!-- <template slot-scope="{row}">
            <span v-if="row.urgent">{{ row.urgent }}</span>
            <span v-else>-</span>
          </template> -->
        </el-table-column>
        <el-table-column label="暂停" min-width="80px">
          <template slot-scope="{row}">
            {{ row.paused==0?'否':'是' }}
          </template>
        </el-table-column>
 
        <el-table-column label="发布日期" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.publishDate">{{ row.publishDate }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="计划员" min-width="160px">
          <template slot-scope="{row}">
            <span>{{ row.userName }}&nbsp;{{ row.userMobile }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="containPermissions(['ext:workplans:update', 'ext:workplans:delete'])" label="操作"
          min-width="160" fixed="right">
          <template slot-scope="{row}">
            <div v-if="row.status != 8">
              <el-button type="text" v-if="row.status == 0" @click="sendRelease(row.id)">发布</el-button>
              <el-button type="text" v-if="row.status == 1" @click="PAUSERESUME(row.id, row.paused)">{{ row.paused == 1 ?
                '恢复' : '暂停' }}</el-button>
              <el-button type="text" v-if="row.status == 1" @click="closePlain(row.id)">关闭</el-button>
              <el-button type="text" v-if="row.status == 0" @click="$refs.operaWorkPlansWindow.open('编辑成品计划', row)"
                v-permissions="['ext:workplans:update']">编辑</el-button>
              <span v-if="row.status == 0" v-permissions="['ext:workplans:delete']" style="margin-left: 10px;">
                <el-button type="text" @click="deleteById(row)">删除</el-button>
              </span>
            </div>
            <span v-else>-</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination @size-change="handleSizeChange" @current-change="handlePageChange" :pagination="tableData.pagination">
      </pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaWorkPlansWindow ref="operaWorkPlansWindow" @success="handlePageChange" />
    <!-- 详情 -->
    <plannedProgress ref="plannedProgress" />
  </TableLayout>
</template>
  
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import ImportButton from '@/components/common/ImportButton'
import OperaWorkPlansWindow from '@/components/business/OperaWorkPlansWindow'
import plannedProgress from '@/components/business/plannedProgress'
import { getDepartmentListByConditon } from '@/api/ext/departmentExt'
import { release, paused, regain, close, releaseBatch, deleteBatch } from '@/api/business/workPlans'
export default {
  name: 'WorkPlans',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaWorkPlansWindow, ImportButton, plannedProgress },
  data() {
    return {
      // 搜索
      searchForm: {
        materialName: '',
        materialCode: '',
        planDateStart: '',
        planDateEnd: '',
        factoryId: '',
        materialId: '',
        batch: '',
        planStatus: '',
        planCode: ''
      },
      ids: [],
      statusList: [
        { label: '已生成', value: 0 },
        { label: '执行中', value: 1 },
        // { label: '已撤回', value: 2 },
        // { label: '已取消', value: 3 },
        // { label: '已分配', value: 4 },
        // { label: '已暂停', value: 5 },
        { label: '已完工', value: 6 },
        // { label: '已入库', value: 7 },
        { label: '已关闭', value: 8 }
      ],
      factoryList: []
    }
  },
  provide() {
    return {
      factories: () => this.factoryList
    }
  },
  created() {
    this.config({
      module: '成品计划',
      api: '/business/workPlans',
      'field.id': 'id',
      'field.main': 'planCode'
    })
    this.search()
  },
  activated() {
    getDepartmentListByConditon({
      type: 1
    }).then(res => {
      this.factoryList = res
    }).catch(err => {
      console.log(err)
    })
  },
  methods: {
    // 计划批量删除
    deleteByIds() {
      if (this.ids.length === 0) {
        this.$tip.warning('至少选择一项内容')
        return
      }
      for (let i = 0; i < this.tableData.list.length; i++) {
        for (let s = 0; s < this.ids.length; s++) {
          if (this.tableData.list[i].id === this.ids[s].id) {
            if (this.tableData.list[i].status != 0) {
              this.$tip.warning('只有已生成状态可以删除')
              return
            }
          }
        }
      }
      this.$confirm(`确认删除已选中的${this.ids.length}条成品计划吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteBatch(this.ids).then(res => {
          this.$tip.success('删除成功')
          this.ids = []
          this.search()
        })
      })
    },
    // 批量发布计划
    batchPublishing() {
      if (this.ids.length === 0) {
        this.$tip.warning('至少选择一项内容')
        return
      }
      this.$confirm('确认发布选中计划?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        releaseBatch(this.ids).then(res => {
          this.$tip.success('发布成功')
          this.ids = []
          this.search()
        })
      })
    },
    // 关闭计划
    closePlain(id) {
      close({ id })
        .then(res => {
          this.$tip.success('关闭成功')
          this.search()
        })
    },
    // 暂停恢复
    PAUSERESUME(id, type) {
      if (type === 1) {
        regain({ id })
          .then(res => {
            this.$tip.success('恢复成功')
            this.search()
          })
      } else {
        paused({ id })
          .then(res => {
            this.$tip.success('暂停成功')
            this.search()
          })
      }
    },
    // 发布计划
    sendRelease(id) {
      this.$confirm('确认发布当前的计划?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        release({ id })
          .then(res => {
            console.log(res)
            this.$tip.success('发布成功')
            this.search()
          })
      })
      // this.$dialog.exportConfirm('确认发布当前的计划?')
      //   .then(() => {
      //     release({ id })
      //       .then(res => {
      //         console.log(res)
      //         this.$tip.success('发布成功')
      //         this.search()
      //       })
      //   })
      //   .catch(() => {
      //     console.log('发布报错');
      //   })
    },
    handleSelectionChange(e) {
      this.ids = e.map(item => {
        return {
          id: item.id
        }
      })
    },
    changeDate(e) {
      if (e) {
        this.searchForm.planDateStart = e[0]
        this.searchForm.planDateEnd = e[1]
      } else {
        this.searchForm.planDateStart = ''
        this.searchForm.planDateEnd = ''
      }
      this.search()
    },
    resets() {
      this.searchForm.planDateStart = ''
      this.searchForm.planDateEnd = ''
      this.reset()
    }
  }
}
</script>