王震
2023-08-18 5cafe90e9e91127889a948ecb44dec61d6185bd4
src/components/view/rawInsDetail.vue
@@ -32,6 +32,9 @@
  .raw-detail-info .el-input{
        width: auto;
  }
  .raw-detail-info.raw-detail-info-edit >>>.el-input__inner{
    background:#fff;
  }
  .raw-detail-info >>>.el-input__inner{
    width: 224px;
    height: 32px;
@@ -42,6 +45,12 @@
  }
  .raw-detail-info .el-form-item{
    margin-bottom: 24px;
  }
  .raw-detail-info .el-form-item .el-button {
    height: 32px;
    border: 1px solid rgba(190, 190, 190, 0.44);
    box-shadow: 0px 2px 4px rgba(220, 220, 220, 0.41);
    padding: 0 12px;
  }
  /* 检验项目 */
@@ -70,56 +79,149 @@
        </el-col>
      </el-row>
    </div>
    <div class="raw-detail-info">
        <el-form v-model="detail" label-position="right" label-width="120px" >
    <div class="raw-detail-info" :class="detailId===null?'raw-detail-info-edit':''">
        <el-form v-model="detailInfo" label-position="right" label-width="120px" >
            <el-row>
                <el-col :span="7">
                    <el-form-item label="来料日期:">
                        <el-input></el-input>
                  <el-form-item label="原材料名称:">
                        <el-input v-if="detailId!==null" :disabled="detailId!==null" v-model="detailInfo.name"></el-input>
                        <el-select @change="checkRawName" v-else  placeholder="请选择项目名称" v-model="detailInfo.name">
                          <el-option v-for="item in materialOptions" :key="item.id" :label="item.name" :value="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="规格型号:">
                        <el-input></el-input>
                        <el-input v-if="detailId!==null" :disabled="detailId!==null" v-model="detailInfo.specifications"></el-input>
                         <el-cascader
                          placeholder="请选择规格型号"
                          v-else
                          :disabled="specificationOptions.length===0"
                          :props="{label:'name',value:'name'}"
                          v-model="detailInfo.specificationsArr"
                          :options="specificationOptions"
                          ></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="原材料编码:">
                        <el-input></el-input>
                        <el-input disabled v-model="detailInfo.code"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="7">
                    <el-form-item label="原材料名称:">
                        <el-input></el-input>
                    <el-form-item label="来料日期:">
                        <el-input v-if="detailId!==null" :disabled="detailId!==null" v-model="detailInfo.formTime"></el-input>
                        <el-date-picker
                          v-else
                          type="date"
                          value-format="yyyy-MM-dd"
                          v-model="detailInfo.formTime"
                          placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="报检日期:">
                        <el-input></el-input>
                    <el-form-item label="数量:">
                        <el-input placeholder="请输入检验数量" :disabled="detailId!==null" v-model="detailInfo.number"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="单位:">
                        <el-input></el-input>
                        <el-input placeholder="请输入检验单位" :disabled="detailId!==null" v-model="detailInfo.unit"></el-input>
                    </el-form-item>
                </el-col>
                <el-col  :span="3">
                    <el-form-item v-show="detailId===null" label="" label-width="50px">
                        <el-button  @click="addNewRawInspect">保存提交</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="7">
                    <el-form-item v-show="detailId!==null" label="报检日期:">
                        <el-input :disabled="detailId!==null" v-model="detailInfo.createTime"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="14">
                    <el-form-item v-show="detailId!==null" label="报检人:">
                        <el-input :disabled="detailId!==null" v-model="detailInfo.userName"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <!-- <el-form v-show="detailId ===null" v-model="rawInsParams" label-position="right" label-width="120px" >
            <el-row>
                <el-col :span="7">
                    <el-form-item label="订单号:">
                        <el-input placeholder="请输入订单号" v-model="rawInsParams.orderNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="客户名称:">
                        <el-input placeholder="请输入客户名称" v-model="rawInsParams.customerName"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="工程名称:">
                        <el-input placeholder="请输入工程名称"  v-model="rawInsParams.projectName"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="7">
                    <el-form-item label="数量:">
                        <el-input></el-input>
                    <el-form-item label="质量追溯号:">
                        <el-input  placeholder="请输入质量追溯号"  v-model="rawInsParams.qualityTraceability"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="报检人:">
                        <el-input></el-input>
                    <el-form-item label="项目名称:">
                        <el-select placeholder="请输入项目名称" v-model="rawInsParams.material">
                          <el-option v-for="item in materialOptions" :key="item.id" :label="item.name" :value="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="产品编码:">
                        <el-input placeholder="产品编码" disabled  v-model="code"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
             <el-row>
                <el-col :span="7">
                    <el-form-item label="规格型号:">
                        <el-input  v-model="detailInfo.specificationsModel"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="单位:">
                        <el-input placeholder="请输入单位"  v-model="rawInsParams.unit"></el-input>
                    </el-form-item>
                </el-col>
                <el-col  :span="7">
                    <el-form-item label="数量">
                      <el-input  placeholder="请输入产品编码"  v-model="rawInsParams.qualityTraceability"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row>
                <el-col :span="21">
                    <el-form-item label="主机工:">
                        <el-input placeholder="请输入主机工"  v-model="rawInsParams.userId"></el-input>
                    </el-form-item>
                </el-col>
                <el-col  :span="3">
                    <el-form-item label="" label-width="100px">
                        <el-button  @click="addNewRawInspect">保存提交</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form> -->
    </div>
    <div class="title">
      <el-row>
@@ -144,36 +246,43 @@
                width="212">
            </el-table-column>
            <el-table-column
                prop="address"
                prop="unit"
                label="单位"
                width="148">
            </el-table-column>
            <el-table-column
                prop="address"
                prop="required"
                label="标准"
                width="254">
            </el-table-column>
            <el-table-column
                prop="address"
                prop="internal"
                label="内控值"
                width="291">
            </el-table-column>
            <el-table-column
                prop="address"
                prop="testValue"
                label="检查值"
                width="371">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.testValue" @blur="changeState(scope.row)"></el-input>
                </template>
            </el-table-column>
            <el-table-column
                prop="address"
                prop="deviceName"
                label="试验设备"
                width="248"
                >
            </el-table-column>
            <el-table-column
                prop="address"
                prop="testState"
                label="结论"
                 width="98"
                >
                <template slot-scope="scope">
                  <span v-show="scope.row.testState!=null" :style="{color: scope.row.testState===1?'#67C23A':'#F56C6C'}">{{scope.row.testState===1?'合格':'不合格'}}</span>
                  <span v-show="scope.row.testState==null">暂未结论</span>
                </template>
            </el-table-column>
    </el-table>
    </div>
@@ -185,31 +294,37 @@
    <div class="raw-conclusion-table">
        <el-table :data="conclusionTable">
            <el-table-column
                prop="number"
                prop="code"
                label="物料编号"
                width="353">
            </el-table-column>
            <el-table-column
                prop="number"
                prop="name"
                label="物料名称"
                width="353">
            </el-table-column>
            <el-table-column
                prop="number"
                prop="names"
                label="检验员"
                width="542">
                <template slot-scope="scope">
                  <span v-for="item in scope.row.names" :key="item&&item.userName" :style="{marginRight:'8px'}">{{item}}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="number"
                prop="testState"
                label="检验结论"
                width="362">
                 <template slot-scope="scope">
                  <span v-show="scope.row.testState!=null" :style="{color: scope.row.testState===1?'#67C23A':'#F56C6C'}">{{scope.row.testState===1?'合格':'不合格'}}</span>
                  <span v-show="scope.row.testState==null">暂未结论</span>
                </template>
            </el-table-column>
             <el-table-column
                fixed="right"
                label="操作"
                width="120">
                <template slot-scope="scope">
                    <el-button type="text" size="small">上报</el-button>
                <template>
                    <el-button type="text" size="small" @click.once="submitSave">上报</el-button>
                </template>
            </el-table-column>
        </el-table>
@@ -221,51 +336,110 @@
import RawIns from './raw-ins.vue'
export default {
    components:{RawIns},
    props:['goBack','detail'],
    props:['goBack','detailId'],
    created(){
        console.log(this.detail)
      // 清空
      this.detailInfo = {}
      if(this.detailId){
        console.log(this.detailId)
        this.getDetailInfo()
      }else{
        this.getOptions()
      }
    },
    mounted(){
    },
    computed:{
      conclusionTable(){
        // console.log(this.projectTable)
        // console.log(this.projectTable.map(item=>item.userName))
        const conclusion = {}
        conclusion.name = this.detailInfo.name
        conclusion.code = this.detailInfo.code
        conclusion.names= [...new Set(this.projectTable.map(item=>item.userName))]
        console.log(conclusion,this.projectTable)
        console.log(this.projectTable.filter(item=>item.testState===null).length)
        if(this.projectTable.filter(item=>item.testState===null).length===this.projectTable.length){
          conclusion.testState = null
          return [conclusion]
        }
        if(this.projectTable.filter(item=>item.testState===0).length>0){
          conclusion.testState= 0
        }else{
          conclusion.testState= 1
        }
        return [conclusion]
      },
      // 产品编码
      // code(){
      //   const material= this.materialOptions.filter(item=>item.name===this.rawInsParams.material)[0]
      //   return  material && material.code
      // }
    },
    data() {
        return {
            conclusionTable:[
                {number:'物料名称'}
            ],
            projectTable:[
                {
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市'
          }
            ]
          // 详情页就是详情信息
          detailInfo:{},
          projectTable:[],
          // 新建检验单参数对象
          rawInsParams:{},
          // 项目名称options
          materialOptions:[],
          specificationOptions:[]
        }
    },
    methods:{
      // 获取报检单详情信息
      async getDetailInfo() {
        const {data} = await this.$axios.get(this.$api.url.selectRawInspectsListById+`${this.detailId}`,{params:{id:this.detailId}})
        this.detailInfo  = data
        this.projectTable = data.rawInsProducts
        console.log(data)
      },
      // 新增检验单
      async addNewRawInspect() {
        this.detailInfo.specifications = this.detailInfo.specificationsArr.join("-")
        // const time = this.detailInfo.formTime
        // this.detailInfo.formTime = `${time.getFullYear()}-${time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1}-${time.getDate() < 10 ? '0' + time.getDate() : time.getDate()}`
        const res = await this.$axios.post(this.$api.url.addRawInspects,{...this.detailInfo},{headers:{'Content-Type':'application/json'}})
        console.log(res)
        this.detailId = res.data
        this.getDetailInfo()
        this.$message.success('提交成功')
      },
      // 修改项目的检测值改变结论
      async changeState(row){
        // console.log(row)
        const res = await this.$axios.post(this.$api.url.updaterawInsProduct,{...row},{headers:{'Content-Type':'application/json'}})
        this.$message.success('提交成功')
        this.getDetailInfo()//重新刷新信息数据
      },
      async submitSave() {
        const res = await this.$axios.post(this.$api.url.updateRawInspectsById+`${this.detailId}`)
        this.$message.success('提交成功')
        this.getDetailInfo()
      },
      async getOptions() {
        // const {data} = await this.$axios.get(this.$api.url.listMaterial)
        // this.materialOptions = data
        const {data} = await this.$axios.get(this.$api.url.selectRawMaterial)
        this.materialOptions = data
        console.log(this.materialOptions)
      },
      checkRawName(data) {
        console.log('选择原材料名称',data)
        this.materialOptions.forEach(item=>{
          if(item.name===data){
            console.log(item.id)
            this.detailInfo.code = item.code
            this.$axios.get(this.$api.url.selectSpBySt,{params:{id:item.id}}).then(res=>{
              this.specificationOptions= res.data
            })
          }
        })
      }
     }
}
</script>