<script>
import {
  searchCodeItemDefs,
  removeBatchCodeItemDef,
  saveBatchCodeItemDef,
  editBatchCodeItemDef, searchCodeItemDefsSeq, searchCodeSeqGenerate, saveCodeSeqGenerate
} from "../../../api/code/codeItemDef"
import ItemValue from "./item/itemValue.vue";

const columnList = [
  {
    functionId: 9009004,
    serialNumber: '9009004Table1ItemNo',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'itemNo',
    headerAlign: 'center',
    align: 'right',
    columnLabel: '序号',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 60
  },
  {
    functionId: 9009004,
    serialNumber: '9009004Table1ItemDesc',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'itemDesc',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '描述',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1SeqNo',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'seqNo',
    headerAlign: 'center',
    align: 'right',
    columnLabel: '排列次序号',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1Postfix',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'postfix',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '前面是否增加分割号',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1Bits',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'bits',
    headerAlign: 'center',
    align: 'right',
    columnLabel: '编码位数',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1ItemByCondition',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'itemByCondition',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '可选值随元素变化而变化',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 180
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1ItemType',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'itemType',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '元素输入类型',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1SeqNoBits',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'seqNoBits',
    headerAlign: 'center',
    align: 'right',
    columnLabel: '流水号位数',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1SeqNoType',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'seqNoType',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '流水号产生规则',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1VirtualItem',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'virtualItem',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '不参与编码',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },
  // {
  //   functionId: 9009004,
  //   serialNumber: '9009004Table1ValueSeqNo',
  //   tableId: '9009004Table1',
  //   tableName: '编码组成元素',
  //   columnProp: 'valueSeqNo',
  //   headerAlign: 'center',
  //   align: 'right',
  //   columnLabel: '值顺序号',
  //   columnHidden: false,
  //   columnImage: false,
  //   columnSortable: false,
  //   sortLv: 0,
  //   status: true,
  //   fixed: '',
  //   columnWidth: 120
  // },{
  //   functionId: 9009004,
  //   serialNumber: '9009004Table1FixedValueFlag',
  //   tableId: '9009004Table1',
  //   tableName: '编码组成元素',
  //   columnProp: 'fixedValueFlag',
  //   headerAlign: 'center',
  //   align: 'right',
  //   columnLabel: '固定值',
  //   columnHidden: false,
  //   columnImage: false,
  //   columnSortable: false,
  //   sortLv: 0,
  //   status: true,
  //   fixed: '',
  //   columnWidth: 120
  // },
];
const descColumnList = [
  {
    functionId: 9009004,
    serialNumber: '9009004Table1ItemNo',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'itemNo',
    headerAlign: 'center',
    align: 'right',
    columnLabel: '序号',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 60
  },
  {
    functionId: 9009004,
    serialNumber: '9009004Table1ItemDesc',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'itemDesc',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '描述',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1SeqNo',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'seqNo',
    headerAlign: 'center',
    align: 'right',
    columnLabel: '排列次序号',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 80
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1ShowInDesc',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'showInDesc',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '在描述中显示',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 120
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1ShowItemDescInDesc',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'showItemDescInDesc',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '在描述显示元素名称',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 140
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1ShowInRemark',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'showInRemark',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '在备注中显示',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 100
  },{
    functionId: 9009004,
    serialNumber: '9009004Table1ShowItemDescInRemark',
    tableId: '9009004Table1',
    tableName: '编码组成元素',
    columnProp: 'showItemDescInRemark',
    headerAlign: 'center',
    align: 'left',
    columnLabel: '在备注中显示元素名称',
    columnHidden: false,
    columnImage: false,
    columnSortable: false,
    sortLv: 0,
    status: true,
    fixed: '',
    columnWidth: 140
  }
];
const dataList = {
  itemNo:undefined,
  itemDesc:undefined,
  seqNo:undefined,
  postfix:undefined,
  bits:undefined,
  itemByCondition:undefined,
  seqFlag:undefined,
  itemType:undefined,
  seqNoBits:undefined,
  seqNoType:undefined,
  virtualItem:undefined,
  valueSeqNo:undefined,
  fixedValueFlag:undefined,
  showInDesc:undefined,
  showItemDescInDesc:undefined,
  showInRemark:undefined,
  showItemDescInRemark:undefined,
};

const dataLabels = {
  itemNo:"元素序号",
  itemDesc:"元素描述",
  seqNo:"排列次序号",
  postfix:"前面是否增加分割号",
  bits:"编码位数",
  itemByCondition:"可选值随元素变化而变化",
  seqFlag:"流水号标识",
  itemType:"元素输入类型",
  seqNoBits:"流水号位数",
  seqNoType:"流水号产生规则",
  virtualItem:"不参与编码",
  valueSeqNo:"值顺序号",
  fixedValueFlag:"固定值",
  showInDesc:"在描述中显示",
  showItemDescInDesc:"在描述显示元素名称",
  showInRemark:"在备注中显示",
  showItemDescInRemark:"在备注中显示元素名称",
};
const dataRules = {};
Object.keys(dataList).forEach(key => {
  dataRules[key] = [
    {
      required: true,
      message: `${dataLabels[key]}不能为空`,
      trigger: ['blur','input','change']
    }
  ];
});
export default {
  name: "CodeItem",
  components: {ItemValue},
  data(){
    return{
      currentRow:{},
      saveOrEditIndex:undefined,
      loading:false,
      defineOptionalValueFlag:false,
      visible: false,
      codeItemDefs: [],
      copyCodeItemDefs:[],
      columnList: columnList.map(item => {return {...item,userId:this.$store.state.user.id}}),
      descColumnList: descColumnList.map(item => {return {...item,userId:this.$store.state.user.id}}),
      searchCodeItemDef: {...dataList},
      selectionAllList: [],
      saveCodeItemDef:{...dataList},
      rules: dataRules,
      descOrRemarkDialog:false,
      codeItemSeqList:[],
      seqNoGenerateDialog:false,
      seqNoGenerateList:[],
    }
  },
  computed: {
    itemType(){
      return this.saveCodeItemDef.itemType;
    },
    sortCodeItemDefs(){
      let arr = JSON.parse(JSON.stringify(this.copyCodeItemDefs));
      return arr.sort((a,b) => a.seqNo - b.seqNo);
    },
    descDialog:{
      get(){
        return this.descOrRemarkDialog
      },
      set(val){
        if (this.saveOrEditIndex !== undefined){
          this.$confirm('存在信息正在编辑, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.descOrRemarkDialog = val
            this.saveOrEditIndex = undefined
          }).catch(() => {

          });
        }else {
          this.descOrRemarkDialog = val
        }
      }
    }
  },
  watch:{
    itemType(val,oldVal){
      if (val && !val.includes('流水号')){
        this.saveCodeItemDef.seqNoType = '*';
        this.saveCodeItemDef.seqNoBits = 0;
      }
    },
  },
  methods: {
    searchCodeItemDefs(){
      let params = {
        ...this.searchCodeItemDef,
        site: this.$store.state.user.site,
      }
      this.loading = true;
      searchCodeItemDefs(params).then(({data}) => {
        if (data && data.code === 0){
          this.codeItemDefs = data.rows;
          this.copyCodeItemDefs = data.rows;
          if (!this.currentRow.itemNo && this.codeItemDefs.length > 0){
            this.currentRow = {...this.codeItemDefs[0]};
          }
        }else {
          this.$message.error(data.msg)
        }
        this.loading = false
      }).catch(err => {
        console.log(err)
        this.loading = false
      })
    },
    removeBatchCodeItemDef(){
      if (this.selectionAllList.length === 0){
        this.$message.warning("请选择要删除的项")
        return
      }
      this.$confirm(`确定要删除组成元素${this.selectionAllList[0].itemDesc}以及所有该元素的有关信息吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeBatchCodeItemDef(this.selectionAllList).then(({data}) => {
          if (data && data.code === 0){
            this.$message.success(data.msg);
            this.currentRow = {};
            this.searchCodeItemDefs()
          }else {
            this.$message.error(data.msg)
          }
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {

      });
    },
    saveBatchCodeItemDef(params){
      saveBatchCodeItemDef(params).then(({data}) => {
        if (data && data.code === 0){
          this.$message.success(data.msg)
          this.visible = false;
          this.searchCodeItemDefs();
        }else {
          this.$message.error(data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    editBatchCodeItemDef(params){
      editBatchCodeItemDef(params).then(({data}) => {
        if (data && data.code === 0){
          this.$message.success(data.msg)
          this.visible = false;
          this.currentRow = {};
          this.saveOrEditIndex = undefined
          this.searchCodeItemDefs()
        }else {
          this.$message.error(data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    closeDialog(){
      this.resetData(this.saveCodeItemDef);
      this.$refs.saveCodeItemDefForm.resetFields();
    },
    resetData(data){
      Object.keys(data).forEach(key => {data[key] = undefined;});
    },
    clickEdit(row) {
      this.saveCodeItemDef = {...row};
      this.visible = true;
    },
    clickSave(){
      this.resetData(this.saveCodeItemDef);
      this.$nextTick(()=>{
        this.saveCodeItemDef.postfix = 'N';
        this.saveCodeItemDef.bits = 1;
        this.saveCodeItemDef.itemByCondition = 'N';
        this.saveCodeItemDef.seqNoBits = 0;
        this.saveCodeItemDef.virtualItem = 'N';
        this.saveCodeItemDef.seqNoType = '*';
        this.saveCodeItemDef.showInDesc = 'Y';
        this.saveCodeItemDef.showItemDescInDesc = 'Y';
        this.saveCodeItemDef.showInRemark = 'Y';
        this.saveCodeItemDef.showItemDescInRemark = 'Y';
        if (this.codeItemDefs.length === 0){
          this.saveCodeItemDef.seqNo = 1;
          this.saveCodeItemDef.valueSeqNo = 1;
        }else {
            this.saveCodeItemDef.seqNo = this.sortCodeItemDefs[this.codeItemDefs.length-1].seqNo + 1;
            let arr = this.sortCodeItemDefs.map(item=>item.valueSeqNo)
            this.saveCodeItemDef.valueSeqNo = Math.max(...arr) + 1;
        }
      })
      this.visible = true;
    },
    clickSaveCodeItemDef(){
      this.$refs.saveCodeItemDefForm.validate((valid,obj) => {
        if (valid) {
          if (this.saveCodeItemDef.itemType && this.saveCodeItemDef.itemType.includes('流水号') && this.saveCodeItemDef.seqNoBits <= 0){
            this.$message.warning("流水号位数不能小于等于0");
            return
          }
          if (this.saveCodeItemDef.itemType &&this.saveCodeItemDef.itemType.includes('流水号') && this.saveCodeItemDef.seqNoType === '*'){
            this.$message.warning("流水号产生规则不能为*");
            return
          }
          let arr = [];
          arr.push(this.saveCodeItemDef)
          if (this.saveCodeItemDef.itemNo){
            this.editBatchCodeItemDef(arr)
          }else {
            this.saveCodeItemDef.site = this.$store.state.user.site;
            this.saveBatchCodeItemDef(arr)
          }
        }else {
          Object.keys(obj).forEach(key => {
            this.$message.error(obj[key][0].message);
            return
          })
        }
      })
    },
    clickCopy(row){
      this.saveCodeItemDef = {...row};
      this.visible = true;
      this.saveCodeItemDef.itemNo = undefined;
    },
    saveDesc(row){
      let arr = [];
      arr.push(row)
      this.editBatchCodeItemDef(arr)
    },
    clickEditDesc(index){
      if (this.saveOrEditIndex !== undefined){
        this.$confirm('存在信息正在编辑, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.clickSettingDesc();
          this.saveOrEditIndex = index;
        }).catch(() => {

        });
      }else {
        this.saveOrEditIndex = index;
      }
    },
    clickSettingDesc(){
      this.copyCodeItemDefs = JSON.parse(JSON.stringify(this.codeItemDefs));
      this.descOrRemarkDialog = true;
    },
    clickRest(){
      this.clickSettingDesc();
      this.saveOrEditIndex = undefined;
    },
    rowStyle({row}){
      if (row){
        if (row.itemNo === this.currentRow.itemNo){
          return {'background-color': '#E8F7F6', cursor: 'pointer'};
        }
      }
    },
    quotationClickRow(row, column, event){
      this.currentRow = {...row};
    },
    defineOptionalValues(){
      if (!this.currentRow.itemNo){
        this.$message.warning("请先选择要定义可选值的元素");
        return
      }
      this.defineOptionalValueFlag = true;
    },
    removeCodeItemDef(row){
      this.selectionAllList = [row];
      this.removeBatchCodeItemDef();
    },
    searchCodeItemDefsSeq(){
      searchCodeItemDefsSeq(this.currentRow).then(({data}) => {
        if (data && data.code === 0){
          this.codeItemSeqList = data.rows;
        }else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    searchCodeSeqGenerate(){
      searchCodeSeqGenerate(this.currentRow).then(({data})=>{
        if (data && data.code === 0){
          this.seqNoGenerateList = data.rows.map(item=>item.relatedItemNo);
          this.searchCodeItemDefsSeq();
        }else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    clickSeqNoGenerateBtn(){
      this.searchCodeSeqGenerate();
      this.seqNoGenerateDialog = true;
    },
    closeSeqNoGenerate(){
      this.seqNoGenerateList = [];
      this.codeItemSeqList = [];
    },
    saveSeqNoGenerate(){
      let arr = this.seqNoGenerateList.map(item=>{
        return {
          site:this.currentRow.site,
          relatedItemNo:item,
          itemNo:this.currentRow.itemNo,
        }
      })
      let params = {...this.currentRow}
      params.seqNoGenerateRules = arr;
      saveCodeSeqGenerate(params).then(({data}) => {
        if (data && data.code === 0){
          this.$message.success(data.msg)
          this.seqNoGenerateDialog = false;
        }else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    }
  },
  created() {
    this.searchCodeItemDefs()
  }
}
</script>

<template>
<div>
  <!-- 搜索条件 -->
  <el-form :model="searchCodeItemDef" :inline="true" label-position="top">
    <el-form-item label="描述">
      <el-input v-model="searchCodeItemDef.itemDesc"></el-input>
    </el-form-item>
    <el-form-item label=" ">
      <el-button type="primary" icon="el-icon-search" @click="searchCodeItemDefs">搜索</el-button>
    </el-form-item>
  </el-form>
  <!-- 操作按钮 -->
  <el-form :inline="true" label-position="top">
    <el-form-item label=" ">
      <el-button type="primary" @click="clickSave">新增</el-button>
    </el-form-item>
    <el-form-item label=" " v-if="false">
      <el-button type="primary" icon="el-icon-delete"  @click="removeBatchCodeItemDef">删除</el-button>
    </el-form-item>
    <el-form-item label=" ">
      <el-button :type="`${currentRow.itemType && currentRow.itemType.includes('选择')?'primary':'info'}`" :disabled="currentRow.itemType && !currentRow.itemType.includes('选择')" @click="defineOptionalValues" plain>定义可选值</el-button>
    </el-form-item>
    <el-form-item label=" ">
      <el-button type="primary" :type="`${currentRow.itemType && currentRow.itemType.includes('流水号') && currentRow.seqNoType === '指定元素'?'primary':'info'}`" :disabled="!currentRow.itemType || !currentRow.itemType.includes('流水号') || currentRow.seqNoType !== '指定元素'" @click="clickSeqNoGenerateBtn" plain>流水号产生规则</el-button>
    </el-form-item>
    <el-form-item label=" ">
      <el-button type="primary" @click="clickSettingDesc" plain>设置描述/备注产生规则</el-button>
    </el-form-item>
  </el-form>
  <!-- 表格 -->
  <el-table :data="codeItemDefs"
            v-loading="loading"
            element-loading-text="拼命加载中"
            height="80vh"
            border
            @row-click="quotationClickRow"
            :row-style="rowStyle"
            style="width: 100%;margin-top: 5px;min-height: 200px">
    <el-table-column
      v-for="(item,index) in columnList" :key="index"
      :sortable="item.columnSortable"
      :prop="item.columnProp"
      :header-align="item.headerAlign"
      :show-overflow-tooltip="item.showOverflowTooltip"
      :align="item.align"
      :fixed="item.fixed === ''?false:item.fixed"
      :min-width="item.columnWidth"
      :label="item.columnLabel">
    </el-table-column>
    <el-table-column label="操作" align="center" fixed="left" header-align="center" width="150">
      <template slot-scope="{row,$index}">
        <el-link style="cursor:pointer;" @click="clickEdit(row)">编辑</el-link>
        <el-link style="cursor:pointer;" @click="clickCopy(row)">复制</el-link>
        <el-link style="cursor:pointer;" @click="removeCodeItemDef(row)">删除</el-link>
      </template>
    </el-table-column>
  </el-table>

  <!--可选值-->
  <el-dialog :visible.sync="defineOptionalValueFlag" v-drag title="可选值定义" top="10vh">
    <item-value v-if="defineOptionalValueFlag" @close="defineOptionalValueFlag=false" :item-value="currentRow"></item-value>
  </el-dialog>

  <!--新增/修改弹框-->
  <el-dialog :visible.sync="visible"  @close="closeDialog" width="500px" v-drag :title="`${saveCodeItemDef.itemNo? '修改编码组成元素' : '新增编码组成元素'}`">
    <el-form :model="saveCodeItemDef" :rules="rules" ref="saveCodeItemDefForm" label-position="top">
      <el-row :gutter="10">
        <el-col :span="16">
          <el-form-item label="描述" prop="itemDesc" :show-message="false">
            <el-input v-model="saveCodeItemDef.itemDesc"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="排列次序号" prop="seqNo" :show-message="false">
            <el-input-number v-model="saveCodeItemDef.seqNo" :min="1" style="line-height: 1.5;width: 100%;" :controls="false"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="前面是否增加分割号" prop="postfix" :show-message="false">
            <el-select v-model="saveCodeItemDef.postfix" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="编码位数" prop="bits" :show-message="false">
            <el-input-number v-model="saveCodeItemDef.bits" :min="1" style="line-height: 1.5;width: 100%;" :controls="false"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="可选值随元素变化而变化" prop="itemByCondition" :show-message="false">
            <el-select v-model="saveCodeItemDef.itemByCondition" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="元素输入类型" prop="itemType" :show-message="false">
            <el-select v-model="saveCodeItemDef.itemType" style="width: 100%;" placeholder="请选择">
              <el-option label="选择" value="选择"></el-option>
              <el-option label="手工" value="手工"></el-option>
              <el-option label="流水号" value="流水号"></el-option>
              <el-option label="选择或手工" value="选择或手工"></el-option>
              <el-option label="选择或流水号" value="选择或流水号"></el-option>
              <el-option label="手工或流水号" value="手工或流水号"></el-option>
              <el-option label="选择或手工或流水号" value="选择或手工或流水号"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="流水号参数规则" prop="seqNoType" :show-message="false">
            <el-select v-model="saveCodeItemDef.seqNoType" :disabled="!saveCodeItemDef.itemType || !saveCodeItemDef.itemType.includes('流水号')" style="width: 100%;" placeholder="请选择">
              <el-option label="*" value="*"></el-option>
              <el-option label="所有元素" value="所有元素"></el-option>
              <el-option label="指定元素" value="指定元素"></el-option>
              <el-option label="全局" value="全局"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="流水号位数" prop="seqNoBits" :show-message="false">
            <el-input-number v-model="saveCodeItemDef.seqNoBits" :disabled="!saveCodeItemDef.itemType || !saveCodeItemDef.itemType.includes('流水号')" :min="0" style="line-height: 1.5;width: 100%;" :controls="false"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="不参与编码" prop="virtualItem" :show-message="false">
            <el-select v-model="saveCodeItemDef.virtualItem" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="false">
          <el-form-item label="值顺序号" prop="valueSeqNo" :show-message="false">
            <el-input-number v-model="saveCodeItemDef.valueSeqNo" :min="1" style="line-height: 1.5;width: 100%;" :controls="false"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="false">
          <el-form-item label="固定值" :show-message="false">
            <el-input v-model="saveCodeItemDef.fixedValueFlag"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-footer style="height:30px;text-align:center;margin-top: 8px">
      <el-button type="primary" @click="clickSaveCodeItemDef">保存</el-button>
      <el-button type="primary" @click="visible = false">关闭</el-button>
    </el-footer>
  </el-dialog>

  <!--设置描述/备注产生规则-->
  <el-dialog ref="dialog" :visible.sync="descDialog" width="60%" v-drag title="设置描述/备注产生规则">
    <div>
      <el-button type="primary" :disabled="saveOrEditIndex >= 0" icon="el-icon-refresh" @click="()=>{
        this.searchCodeItemDef.itemDesc = undefined;
        this.searchCodeItemDefs();
      }">刷新</el-button>
      <el-button type="primary"  @click="descDialog = false">关闭</el-button>
    </div>
    <el-table :data="sortCodeItemDefs"
              height="400px"
              border stripe
              style="width: 100%;margin-top: 5px;min-height: 200px">
      <el-table-column
        v-for="(item,index) in descColumnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed === ''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="{row,$index}">
          <div v-if="saveOrEditIndex === $index && ['showInDesc','showItemDescInDesc','showInRemark','showItemDescInRemark'].includes(item.columnProp)">
            <el-select v-if="item.columnProp === 'showInDesc'" v-model="row.showInDesc" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N" :disabled="row.showItemDescInDesc === 'Y'"></el-option>
            </el-select>
            <el-select v-if="item.columnProp === 'showItemDescInDesc'" @change="()=>{
              if (row.showItemDescInDesc === 'Y'){
                row.showInDesc = 'Y';
              }
            }" v-model="row.showItemDescInDesc" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N"></el-option>
            </el-select>
            <el-select v-if="item.columnProp === 'showInRemark'" v-model="row.showInRemark" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N" :disabled="row.showItemDescInRemark === 'Y'"></el-option>
            </el-select>
            <el-select  v-if="item.columnProp === 'showItemDescInRemark'" @change="()=>{
              if (row.showItemDescInRemark === 'Y'){
                row.showInRemark = 'Y';
              }
            }" v-model="row.showItemDescInRemark" style="width: 100%;" placeholder="请选择">
              <el-option label="Y" value="Y"></el-option>
              <el-option label="N" value="N"></el-option>
            </el-select>
          </div>
          <div v-else>
            {{row[item.columnProp]}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" header-align="center" width="150">
        <template slot-scope="{row,$index}">
          <el-button v-if="saveOrEditIndex !== $index" @click="clickEditDesc($index)" type="text" style="cursor:pointer;" icon="el-icon-edit-outline">编辑</el-button>
          <div v-else>
            <el-button @click="saveDesc(row)" type="text" style="cursor:pointer;" icon="el-icon-edit-outline">保存</el-button>
            <el-button @click="clickRest" type="text" style="cursor:pointer;" icon="el-icon-circle-close">取消</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>

  <el-dialog title="流水号产生规则" v-drag @close="closeSeqNoGenerate" :visible.sync="seqNoGenerateDialog" width="520px">
    <el-form :inline="true" label-position="top" :model="currentRow">
      <el-form-item :label="'序号'">
        <el-input v-model="currentRow.itemNo" readonly style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'描述'">
        <el-input v-model="currentRow.itemDesc" readonly style="width: 120px"></el-input>
      </el-form-item>
    </el-form>
    <el-transfer class="rq" :props="{key: 'itemNo',label: 'itemDesc' }"
                 filterable v-model="seqNoGenerateList"
                 :data="codeItemSeqList" :titles="['元素列表', '已关联元素列表']">
      <span slot-scope="{option}">{{option.itemNo}} / {{option.itemDesc}}</span>
    </el-transfer>
    <el-footer style="height:40px;margin-top: 10px;text-align:center">
      <el-button type="primary" @click="saveSeqNoGenerate">确定</el-button>
      <el-button type="primary" @click="seqNoGenerateDialog = false">关闭</el-button>
    </el-footer>
  </el-dialog>
</div>
</template>

<style scoped>
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
.el-input-number /deep/ .el-input__inner{
  text-align: right;
  padding-right: 15px !important;
  padding-left: 0px !important;
}
/deep/ .el-button{
  line-height: 13px;
  height: 21px;
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header {
  height: 35px;
  line-height: 35px;
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header .el-checkbox {
  line-height: 35px;
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label {
  color: #fff
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label span {
  color: #3c3c3e;
}

.rq /deep/ .el-transfer-panel .el-checkbox__inner::after {
  height: 8px;
  width: 4px;
}
</style>
