<template>
  <div class="mod-config">
    <printFlexo ref="printFlexo"></printFlexo>

    <el-form label-position="top" style="margin-top: 5px; margin-left: 0px;"    >
        <el-form-item >
          <el-button type="primary" @click="colorSearch(true)" >刷新</el-button>
          <el-button type="primary" @click="newColor()" v-if="!ifDisableFlag">新增</el-button>
          <el-button type="primary" @click="colorSaveBatch()" 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="80"
          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 label="印刷面" header-align="center">
          <el-table-column
            prop="printSide"
            header-align="center"
            align="left"
            min-width="100"
            label="Print Side">
          </el-table-column>
        </el-table-column>
        <el-table-column label="色序" header-align="center">
          <el-table-column
            prop="showOrder"
            header-align="center"
            align="left"
            min-width="100"
            label="Color sequence">
          </el-table-column>
        </el-table-column>
        <el-table-column label="颜色参考" header-align="center">
          <el-table-column
            prop="colorReference"
            header-align="center"
            align="left"
            min-width="105"
            label="Color Reference">
          </el-table-column>
        </el-table-column>
        <el-table-column label="油墨代号/颜色IFS No" header-align="center">
          <el-table-column
            prop="inkCode"
            header-align="center"
            align="left"
            min-width="140"
            label="InkCode/Color IFS No">
          </el-table-column>
        </el-table-column>
        <el-table-column label="油墨名称" header-align="center">
          <el-table-column
            prop="inkDesc"
            header-align="center"
            align="left"
            min-width="200"
            label="InkDesc">
          </el-table-column>
        </el-table-column>
        <el-table-column label="颜色匹配" header-align="center">
          <el-table-column
            prop="colorMatch"
            header-align="center"
            align="left"
            min-width="100"
            label="Color Match">
          </el-table-column>
        </el-table-column>
        <el-table-column label="网纹辊/Anilox Grade" header-align="center">
          <el-table-column
            prop="lpi"
            header-align="center"
            align="left"
            min-width="100"
            label="线数(LPI)">
          </el-table-column>
          <el-table-column
            prop="bcm"
            header-align="center"
            align="left"
            min-width="100"
            label="容积(BCM)">
          </el-table-column>
        </el-table-column>
        <el-table-column label="印刷速度" header-align="center">
          <el-table-column
            prop="speed"
            header-align="center"
            align="left"
            min-width="60"
            label="Speed">
          </el-table-column>
        </el-table-column>
        <el-table-column label="红外干燥/Infra-Red" header-align="center">
          <el-table-column
            prop="openFlag"
            header-align="center"
            align="left"
            min-width="100"
            label="(ON /OFF)">
          </el-table-column>
          <el-table-column
            prop="resourceNo"
            header-align="center"
            align="left"
            min-width="100"
            label="机台">
          </el-table-column>
<!--          <el-table-column-->
<!--            prop="gallus"-->
<!--            header-align="center"-->
<!--            align="left"-->
<!--            min-width="100"-->
<!--            label="Gallus(level%)">-->
<!--          </el-table-column>-->
<!--          <el-table-column-->
<!--            prop="markAndy"-->
<!--            header-align="center"-->
<!--            align="left"-->
<!--            min-width="100"-->
<!--            label="MarkAndy(level%)">-->
<!--          </el-table-column>-->
<!--          <el-table-column-->
<!--            prop="hexiang"-->
<!--            header-align="center"-->
<!--            align="left"-->
<!--            min-width="100"-->
<!--            label="Hexiang(L/H)">-->
<!--          </el-table-column>-->
        </el-table-column>
        <el-table-column label="热覆温度" header-align="center">
          <el-table-column
            prop="temperature"
            header-align="center"
            align="left"
            min-width="100"
            label="temperature">
          </el-table-column>
        </el-table-column>
        <el-table-column label="热覆压力" header-align="center">
          <el-table-column
            prop="pressure"
            header-align="center"
            align="left"
            min-width="100"
            label="Pressure">
          </el-table-column>
        </el-table-column>
        <el-table-column label="备注" header-align="center">
          <el-table-column
            prop="remark"
            header-align="center"
            align="left"
            min-width="200"
            label="Remark">
          </el-table-column>
        </el-table-column>
      </el-table>
      <div  class="rq-bmPic" >
        <img style="max-width:  100%;max-height: 100%;vertical-align:middle;" :src="picUrl">
      </div>
      </el-form>

    <el-dialog append-to-body title="颜色信息" :close-on-click-modal="false" v-drag :visible.sync="colorFlag" width="660px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'印刷面/Print Side'">
          <el-select v-model="colorData.printSide" style="width: 145px">
            <el-option label="Front" value="Front"></el-option>
            <el-option label="Back" value="Back"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'色序/Color sequence'">
<!--          <el-input v-model="colorData.showOrder" type="number" style="width: 145px"  onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" ></el-input>-->
          <el-input v-model="colorData.showOrder" type="text" style="width: 145px" ></el-input>
        </el-form-item>
        <el-form-item :label="'颜色参考/Color Reference'">
          <el-input v-model="colorData.colorReference" style="width: 145px"></el-input>
        </el-form-item>
        <el-form-item >
          <span slot="label" @click="getBaseList(133,1)" ><a herf="#">油墨代号/颜色IFS No</a></span>
          <el-input v-model="colorData.inkCode" style="width: 145px"></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="'颜色匹配/Color Match'">
          <el-input v-model="colorData.colorMatch"  style="width: 145px" ></el-input>
        </el-form-item>
        <el-form-item :label="'线数/LPI'">
          <el-input v-model="colorData.lpi" style="width: 145px" ></el-input>
        </el-form-item>
        <el-form-item :label="'容积/BCM'">
          <el-input v-model="colorData.bcm"  style="width: 145px" ></el-input>
        </el-form-item>
        <el-form-item :label="'印刷速度/Speed'">
          <el-input v-model="colorData.speed" style="width: 145px" ></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="'Gallus(level%)'">-->
<!--          <el-input v-model="colorData.gallus" style="width: 130px" ></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item :label="'MarkAndy(level%)'">-->
<!--          <el-input v-model="colorData.markAndy" style="width: 130px" ></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item :label="'Hexiang(L/H)'">-->
<!--          <el-input v-model="colorData.hexiang" style="width: 130px" ></el-input>-->
<!--        </el-form-item>-->
        <el-form-item :label="'机台/Machine No.'">
          <dict-data-select :site="colorData.site" v-if="colorData.site" v-model="colorData.resourceNo" style="width: 145px" dict-type="bm_printingFlexo_resource"></dict-data-select>
        </el-form-item>
        <el-form-item :label="'热覆温度/Temperature'">
          <el-input v-model="colorData.temperature" style="width: 145px" ></el-input>
        </el-form-item>
        <el-form-item :label="'红外干燥/Infra-Red(ON /OFF)'">
          <el-select v-model="colorData.openFlag" style="width: 145px">
            <el-option label="ON" value="ON"></el-option>
            <el-option label="OFF" value="OFF"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'热覆压力/Pressure'">
          <el-input v-model="colorData.pressure" style="width: 145px"></el-input>
        </el-form-item>
        <el-form-item :label="'备注/Remark'">
          <el-input v-model="colorData.remark" style="width: 463px"></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 printFlexo from "./com_bm_demoSlot";/*组件*/
  import {
    searchBMprintFlexoColor,
    saveBMprintFlexoColor,
    deleteBMprintFlexoColor,
    saveBMPrintFlexoColorBatch, // 一键导入
  } from "@/api/sampleManagement/technicalSpecificationList.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  import DictDataSelect from "../../sys/dict-data-select-highlight.vue";
  export default {
    components: {
      DictDataSelect,
      Chooselist,printFlexo
    },
    data() {
      return {
        searchData: {
          site: '',
          username: this.$store.state.user.name,
          codeNo: '',
          buNo:'',
          type:'',
        },
        picUrl:this.$store.state.user.bmPicUrl+'defaultPaperOrientation.png',
        ifDisableFlag:false,

        colorTable:[],
        colorData:{
          id:'',
          site: '',
          codeNo:'',
          printSide:'',
          order:'',
          colorReference:'',
          inkCode:'',
          colorMatch:'',
          lpi:'',
          bcm:'',
          openFlag:'',
          gallus:'',
          markAndy:'',
          hexiang:'',
          temperature:'',
          pressure:'',
          remark:'',
          updateBy:'',
          updateDate:'',
          resourceNo: '',
          speed: '',
          showOrder: null
        },
        colorFlag:false,
      }
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          if (val === 133) {
            if(type==1) {
              strVal = this.colorData.inkCode
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 133) {
          if(this.tagNo1==1) {
            this.colorData.inkCode = val.part_no
          }
        }
      },

      //初始化组件的参数
      init (inData) {
        if (this.searchData.codeNo != null && this.searchData.codeNo !== '') {
          return false;
        }
        //初始化参数
        this.searchData = JSON.parse(JSON.stringify(inData))
        // if (this.searchData.ifDisableFlag) {
        //   this.ifDisableFlag = true
        // }
        //刷新表格
        this.searchTable()
        this.colorSearch()
        //刷新表格
        this.searchData.type = 'printFlexo'
        this.$refs.printFlexo.init(JSON.parse(JSON.stringify(this.searchData)))
      },

      searchTable () {

      },

      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].showOrder) {
            number = Number(this.colorTable[i].showOrder) + 1
          }
        }
        this.colorData = {
          id: 0,
          site: this.searchData.site,
          codeNo: this.searchData.codeNo,
          order: number,
          printSide: 'front',
          colorReference: '',
          inkCode: '',
          colorMatch: '',
          lpi: '',
          bcm: '',
          openFlag: '',
          gallus: '',
          markAndy: '',
          hexiang: '',
          temperature: '',
          pressure: '',
          remark: '',
          updateBy: '',
          updateDate: '',
          resourceNo: '',
          speed: '',
          showOrder: null
        }
        this.colorFlag = true
      },

      updateColor (row) {
        this.colorData = JSON.parse(JSON.stringify(row))
        this.colorFlag = true
      },

      colorSearch (type) {
        searchBMprintFlexoColor(this.searchData).then(({data}) => {
          this.colorTable = data.rows
          if (type) {
            this.$message.success( '操作成功')
          }
        })
      },

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

      // 一键导入
      colorSaveBatch () {
        this.$confirm("此操作将清空已填写的数据，是否继续？", '保存提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          let tempData = {
            site: this.searchData.site,
            codeNo: this.searchData.codeNo,
            printSide: 'front',
          }
          saveBMPrintFlexoColorBatch(tempData).then(({data}) => {
            if (data && data.code === 0) {
              this.colorSearch()
              this.$message.success( '操作成功')
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },

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

    },
  }
</script>

<style scoped>

</style>
