<template>
  <div class="mod-config">
    <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;" v-if="searchData.buNo==='Flexo'">
      <el-row :gutter="20">
        <el-col :span="6"><div class="grid-content bg-purple">
          <el-form-item :label="'印版编号/PlateNo'">
            <el-input v-model="dataForm.plateNo" :disabled="ifDisableFlag"  ></el-input>
          </el-form-item>
        </div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">
          <el-form-item :label="'刀模编号/CutterNumber'">
            <el-input v-model="dataForm.cutterNumber" :disabled="ifDisableFlag"  ></el-input>
          </el-form-item>
        </div></el-col>
        <el-col :span="6"><div class="grid-content bg-purple">
          <el-form-item :label="'刀模排位/CutterLayout'" >
            <el-input v-model="dataForm.cutterLayout" :disabled="ifDisableFlag" type="number"  onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"></el-input>
          </el-form-item>
        </div></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24"><div class="grid-content bg-purple">
          <el-form-item :label="'材料准备阶段/Action'">
            <el-input
              type="textarea"
              v-model="dataForm.action "
              :rows="3"
              resize='none'
              maxlength="120"
              show-word-limit
              :disabled="ifDisableFlag"
              style="height: 60px" >
            </el-input>
          </el-form-item>
        </div></el-col>
      </el-row>
    </el-form>

      <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;"   v-if="searchData.buNo!=='Flexo'">
        <el-form-item >
          <el-button type="primary" @click="colorSearch()" >刷新</el-button>
          <el-button type="primary" @click="newColor()" v-if="!ifDisableFlag">新增</el-button>
        </el-form-item>
      <el-table
        height="400"
        :data="colorTable"
        border
        style="width: 100%">
        <el-table-column
          prop=""
          header-align="center"
          align="center"
          min-width="30"
          v-if="!ifDisableFlag"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" @click="updateColor(scope.row)">编辑</a>
            <a type="text" size="small" @click="deleteColor(scope.row)">删除</a>
          </template>
        </el-table-column>
        <el-table-column
          prop="order"
          header-align="center"
          align="left"
          min-width="40"
          label="色序">
        </el-table-column>
        <el-table-column
          prop="color"
          header-align="center"
          align="left"
          min-width="60"
          label="颜色">
        </el-table-column>
        <el-table-column
          prop="meshModel"
          header-align="center"
          align="left"
          min-width="60"
          label="类型">
        </el-table-column>
        <el-table-column
          prop="meshSize"
          header-align="center"
          align="right"
          min-width="60"
          label="目数">
        </el-table-column>
        <el-table-column
          prop="angle"
          header-align="center"
          align="right"
          min-width="60"
          label="角度">
        </el-table-column>
        <el-table-column
          prop="coatingType"
          header-align="center"
          align="left"
          min-width="60"
          label="涂膜种类">
        </el-table-column>
        <el-table-column
          prop="filmNo"
          header-align="center"
          align="left"
          min-width="60"
          label="菲林编号">
        </el-table-column>
        <el-table-column
          prop="stencilNo"
          header-align="center"
          align="left"
          min-width="60"
          label="网版编号">
        </el-table-column>
      </el-table>
        <el-row :gutter="20">
          <el-col :span="24"><div class="grid-content bg-purple">
            <el-form-item :label="'备注/Remarks'">
              <el-input
                type="textarea"
                v-model="dataForm.remark "
                :rows="3"
                resize='none'
                maxlength="120"
                show-word-limit
                :disabled="ifDisableFlag"
                style="height: 60px" >
              </el-input>
            </el-form-item>
          </div></el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 60px">
          <el-col :span="24"><div class="grid-content bg-purple">
            <el-form-item :label="'问题反馈'">
              <el-input
                type="textarea"
                v-model="dataForm.feedback "
                :rows="3"
                resize='none'
                maxlength="120"
                show-word-limit
                :disabled="ifDisableFlag"
                style="height: 60px" >
              </el-input>
            </el-form-item>
          </div></el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 60px">
          <el-col :span="24"><div class="grid-content bg-purple">
            <el-form-item :label="'Action'">
              <el-input
                type="textarea"
                v-model="dataForm.action "
                :rows="3"
                resize='none'
                maxlength="120"
                show-word-limit
                :disabled="ifDisableFlag"
                style="height: 60px" >
              </el-input>
            </el-form-item>
          </div></el-col>
        </el-row>
      </el-form>

    <el-form label-position="top" style="margin-top:60px; margin-left: 0px;text-align:center" v-if="!ifDisableFlag">
      <el-button type="primary" @click="saveData()"  >保存</el-button>
    </el-form>


    <el-dialog append-to-body title="颜色信息" :close-on-click-modal="false" v-drag :visible.sync="colorFlag" width="600px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'色序'">
          <el-input v-model="colorData.order" type="number" style="width: 130px"  onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" ></el-input>
        </el-form-item>
        <el-form-item :label="'颜色'">
          <el-input v-model="colorData.color" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'类型'">
          <el-input v-model="colorData.meshModel" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'目数'">
          <el-input v-model="colorData.meshSize" type="number" style="width: 130px" ></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'颜色匹配'">
          <el-input v-model="colorData.angle" type="number" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'涂膜种类'">
          <el-input v-model="colorData.coatingType" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'菲林编号'">
          <el-input v-model="colorData.filmNo" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'网版编号'">
          <el-input v-model="colorData.stencilNo" style="width: 130px" ></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="colorSave()">保存</el-button>
        <el-button type="primary" @click="colorFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    searchBMPrepressDetail,
    updateBMPrepressDetail,
    searchBMPrepressColor,
    saveBMPrepressColor,
    deleteBMPrepressColor,
  } from "@/api/sampleManagement/technicalSpecificationList.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    components: {
      Chooselist
    },
    data() {
      return {
        searchData: {
          site: '',
          username: this.$store.state.user.name,
          codeNo: '',
          buNo:'',
          ifDisableFlag:'',
        },
        ifDisableFlag:false,
        dataForm:{
          site: '',
          codeNo:'',
          plateNo:'',
          cutterNumber:'',
          cutterLayout:'',
          action:'',
          feedback:'',
          remark:'',

        },
        colorTable:[],
        colorData:{
          id:'',
          site: '',
          codeNo:'',
          order:'',
          color:'',
          meshModel:'',
          meshSize:'',
          angle:'',
          coatingType:'',
          filmNo:'',
          stencilNo:'',
          updateBy:'',
          updateDate:'',
        },
        colorFlag:false,
      }
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          if (val === 1013) {
            if(type==1) {
              strVal = this.dataForm.partType
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1013) {
          if(this.tagNo1==1) {
            this.dataForm.partType = val.Base_id
            this.dataForm.partTypeDesc = val.Base_desc
          }
        }
      },
      //初始化组件的参数
      init(inData) {
        if(this.dataForm.codeNo!=null&&this.dataForm.codeNo!=''){
          return false;
        }
        //初始化参数
        this.searchData = JSON.parse(JSON.stringify(inData));
        if(this.searchData.ifDisableFlag){
          this.ifDisableFlag=true
        }
        //刷新表格
        this.searchTable();
        this.colorSearch();

      },
      searchTable(){
        searchBMPrepressDetail(this.searchData).then(({data}) => {
          if(data.rows.length>0){
            this.dataForm = data.rows[0];
          }else {
            this.dataForm.site=this.searchData.site
            this.dataForm.codeNo=this.searchData.codeNo
          }
        });
      },
      saveData(){
        this.$confirm("是否保存信息？", '保存提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          updateBMPrepressDetail(this.dataForm).then(({data}) => {
            if (data && data.code === 0) {
              this.$message.success( '操作成功')
              this.$emit("closeModel")
            } else {
              this.$message.error(data.msg)
            }
          })
        }).catch(() => {
          return
        })
      },

      newColor(){
        if(this.searchData.codeNo==''){
          this.$message.success('数据错误，请关闭页面重试！')
          return false;
        }
        let number=1;
        for (let i = 0; i <this.colorTable.length ; i++) {
          if(number<=this.colorTable[i].order){
            number=Number(this.colorTable[i].order)+1
          }
        }
        this.colorData={
          id:0,
          site: this.searchData.site,
          codeNo:this.searchData.codeNo,
          order:number,
          color:'',
          meshModel:'',
          meshSize:'',
          angle:'',
          coatingType:'',
          filmNo:'',
          stencilNo:'',
          updateBy:'',
          updateDate:'',
        }
        this.colorFlag=true;
      },
      updateColor(row){
        this.colorData=JSON.parse(JSON.stringify(row))
        this.colorFlag=true;
      },

      colorSearch(){
        searchBMPrepressColor(this.searchData).then(({data}) => {
          this.colorTable = data.rows
        });
      },
      colorSave(){
        this.$confirm("是否保存信息？", '保存提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          saveBMPrepressColor(this.colorData).then(({data}) => {
            if (data && data.code === 0) {
              this.colorSearch();
              this.$message.success( '操作成功')
            } else {
              this.$message.error(data.msg)
            }
          })
        }).catch(() => {

        })
      },
      deleteColor(row){
        this.$confirm(`是否删除这条信息?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteBMPrepressColor(row).then(({data}) => {
            if (data && data.code === 0) {
              this.colorSearch();
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },


    },
  }
</script>

<style scoped>

</style>
