<template> 
 | 
  <GlobalWindow 
 | 
    :title="title" 
 | 
    :visible.sync="visible" 
 | 
    width="80%" 
 | 
    :confirm-working="isWorking" 
 | 
    @confirm="confirm" 
 | 
  > 
 | 
    <el-table 
 | 
      ref="orderTable" 
 | 
      :data="form.list" 
 | 
      stripe 
 | 
      border 
 | 
      @selection-change="handleSelectionChange" 
 | 
    > 
 | 
      <el-table-column type="selection" fixed="left" width="55"></el-table-column> 
 | 
      <el-table-column prop="code" label="工单编号" min-width="140px"></el-table-column> 
 | 
      <el-table-column prop="code" label="工单类型" min-width="80px"> 
 | 
         <template slot-scope="{row}"> 
 | 
          {{ typeToStr(row.type)}} 
 | 
        </template> 
 | 
      </el-table-column> 
 | 
      <el-table-column prop="mmodel.name" label="物料名称" min-width="100px"></el-table-column> 
 | 
      <el-table-column prop="mmodel.code" label="物料编码" min-width="160px"></el-table-column> 
 | 
      <el-table-column prop="procedureName" label="工序" show-overflow-tooltip min-width="100px"> 
 | 
        <template slot-scope="{row}"> 
 | 
          <span class="long-title-style">{{ row.procedureName }}</span> 
 | 
        </template> 
 | 
      </el-table-column> 
 | 
      <el-table-column prop="planNum" label="计划生产数量" min-width="80px"> 
 | 
        <template slot-scope="{row}"> 
 | 
          {{ row.planNum + row.umodel.name }} 
 | 
        </template> 
 | 
      </el-table-column> 
 | 
      <el-table-column prop="proUserName" label="生产人员" show-overflow-tooltip min-width="140px"> 
 | 
        <template slot-scope="{row}"> 
 | 
          <span class="long-title-style">{{ proUserName(row.proUserList) }}</span> 
 | 
        </template> 
 | 
      </el-table-column> 
 | 
      <el-table-column prop="pgmodel.name" label="生产设备" show-overflow-tooltip min-width="100px"> 
 | 
        <template slot-scope="{row}"> 
 | 
          <span class="long-title-style">{{ '【' + row.pgmodel.code + '】' + row.pgmodel.name }}</span> 
 | 
        </template> 
 | 
      </el-table-column> 
 | 
    </el-table> 
 | 
  </GlobalWindow> 
 | 
</template> 
 | 
  
 | 
<script> 
 | 
import BaseOpera from '@/components/base/BaseOpera' 
 | 
import GlobalWindow from '@/components/common/GlobalWindow' 
 | 
import { preparationWTransfer } from '@/api/ext/workorderExt' 
 | 
export default { 
 | 
  name: 'OperaWorkorderExtWindow', 
 | 
  extends: BaseOpera, 
 | 
  components: { GlobalWindow }, 
 | 
  data () { 
 | 
    return { 
 | 
      // 表单数据 
 | 
      form: { 
 | 
        list: [ 
 | 
        ] 
 | 
      }, 
 | 
      // 验证规则 
 | 
      rules: { 
 | 
      }, 
 | 
      selectedRows: [], 
 | 
      types: [ 
 | 
        // 0正常、1返工、2客户返修 
 | 
        { name: '正常', id: 0 }, 
 | 
        { name: '返工返修', id: 2 }, 
 | 
        // { name: '客户返修', id: 2 } 
 | 
      ], 
 | 
    } 
 | 
  }, 
 | 
  created () { 
 | 
    this.config({ 
 | 
      api: '/ext/workorderExt', 
 | 
      'field.id': 'id' 
 | 
    }) 
 | 
  }, 
 | 
  methods: { 
 | 
    open (title, target) { 
 | 
      this.title = title 
 | 
      this.visible = true 
 | 
      // 编辑 
 | 
      this.$nextTick(() => { 
 | 
        this.form.list = target 
 | 
      }) 
 | 
      setTimeout(()=>{ 
 | 
          this.form.list.forEach(item => { 
 | 
            this.$refs.orderTable.toggleRowSelection(item) 
 | 
          }) 
 | 
        },50) 
 | 
    }, 
 | 
    handleSelectionChange (selectedRows) { 
 | 
      this.selectedRows = selectedRows 
 | 
    }, 
 | 
    confirm () { 
 | 
      if (this.selectedRows.length === 0) { 
 | 
        this.$tip.warning('请至少选择一条数据') 
 | 
        return 
 | 
      } 
 | 
      const ids = this.selectedRows.map(element => { 
 | 
        return element.id 
 | 
      }).join(',') 
 | 
      this.isWorking = true 
 | 
      preparationWTransfer(ids) 
 | 
        .then(() => { 
 | 
          this.$tip.success('备料成功') 
 | 
          this.$emit('success') 
 | 
          this.visible = false 
 | 
        }) 
 | 
        .catch(err => { 
 | 
          this.$tip.error(err) 
 | 
        }) 
 | 
        .finally(() => { 
 | 
          this.isWorking = false 
 | 
        }) 
 | 
    }, 
 | 
    typeToStr (type) { 
 | 
      for (const item of this.types) { 
 | 
        if (item.id === type) { 
 | 
          return item.name 
 | 
        } 
 | 
      } 
 | 
    }, 
 | 
    proUserName (proUserList) { 
 | 
      return proUserList.map((item) => {return item.proUserDepartName}).join(',') 
 | 
    } 
 | 
  } 
 | 
} 
 | 
</script> 
 |