| <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="salesorder"> | 
|         <el-input v-model="searchForm.salesorder" 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="190px"> | 
|           <template slot-scope="{row}"> | 
|             <el-button type="text" @click="$refs.plannedProgress.open('计划执行进度', row)"> | 
|               <span class="long-title-style">{{ row.planCode }}</span> | 
|             </el-button> | 
|             <el-tag type="danger" size="mini" v-if="row.hasExpire">延期</el-tag> | 
|           </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 }} {{ 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: '', | 
|         salesorder: '', | 
|         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> |