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

    <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="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 label="油墨类型" header-align="center">
          <el-table-column
            prop="inkType"
            header-align="center"
            align="left"
            min-width="60"
            label="Ink Type">
          </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="60"
            label="Color Reference">
          </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="60"
            label="Color Match">
          </el-table-column>
        </el-table-column>
        <el-table-column label="容积" header-align="center">
          <el-table-column
            prop="bcm"
            header-align="center"
            align="left"
            min-width="60"
            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="外干燥" header-align="center">
          <el-table-column
            prop="dry"
            header-align="center"
            align="left"
            min-width="60"
            label="Dry">
          </el-table-column>
        </el-table-column>
        <el-table-column label="UV固化/UV Curing" header-align="center">
          <el-table-column
            prop="gallus"
            header-align="center"
            align="left"
            min-width="60"
            label="Gallus(level%)">
          </el-table-column>
          <el-table-column
            prop="markAndy"
            header-align="center"
            align="left"
            min-width="60"
            label="MarkAndy(level%)">
          </el-table-column>
          <el-table-column
            prop="lp"
            header-align="center"
            align="left"
            min-width="60"
            label="LP(L/M/H)">
          </el-table-column>
          <el-table-column
            prop="hexiang"
            header-align="center"
            align="left"
            min-width="60"
            label="Hexiang(L/H)">
          </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="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.inkType" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(133,1)" ><a herf="#">颜色参考</a></span>
          <el-input v-model="colorData.colorReference" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'颜色匹配'">
          <el-input v-model="colorData.colorMatch"  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.bcm"  style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'印刷速度'">
          <el-input v-model="colorData.speed" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'外干燥'">
          <el-input v-model="colorData.dry" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'Gallus(level%)'">
          <el-input v-model="colorData.gallus" 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="'MarkAndy(level%)'">
          <el-input v-model="colorData.markAndy" style="width: 130px" ></el-input>
        </el-form-item>
        <el-form-item :label="'LP(L/M/H)'">
          <el-input v-model="colorData.lp" 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>
      <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 printing from "./com_bm_demoSlot";/*组件*/
  import {
    searchBMPrintingDetail,
    updateBMPrintingDetail,
    searchBMPrintingColor,
    saveBMPrintingColor,
    deleteBMPrintingColor,
    saveBMPrintingColorBatch, // 一键导入
  } from "@/api/sampleManagement/technicalSpecificationList.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    components: {
      Chooselist,printing
    },
    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:'',
          order:'',
          inkType:'',
          colorReference:'',
          colorMatch:'',
          bcm:'',
          speed:'',
          dry:'',
          gallus:'',
          markAndy:'',
          lp:'',
          hexiang:'',
          updateBy:'',
          updateDate:'',
        },
        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.colorReference
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 133) {
          if(this.tagNo1==1) {
            this.colorData.colorReference = 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='printing'
        this.$refs.printing.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].order) {
            number = Number(this.colorTable[i].order) + 1
          }
        }
        this.colorData = {
          id: 0,
          site: this.searchData.site,
          codeNo: this.searchData.codeNo,
          order: number,
          inkType: '',
          colorReference: '',
          colorMatch: '',
          bcm: '',
          speed: '',
          dry: '',
          gallus: '',
          markAndy: '',
          lp: '',
          hexiang: '',
          updateBy: '',
          updateDate: '',
        }
        this.colorFlag = true
      },

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

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

      colorSave () {
        this.$confirm("是否保存信息？", '保存提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          saveBMPrintingColor(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,
          }
          saveBMPrintingColorBatch(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(() => {
          deleteBMPrintingColor(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>
