<script xmlns="http://www.w3.org/1999/html">
import {editDrawing, removeDrawing, searchDrawingDetailList, searchDrawingList} from "../../../api/code/codeDrawing";
import dayjs from "dayjs";

export default {
  name: "CodeList",
  data(){
    return{
      drawingList:[],
      searchModel:{
        site:this.$store.state.user.site,
        drawingNo:undefined,
        creator:undefined,
        drawingDesc:undefined,
        remark:undefined,
        erpPartNo:undefined,
        erpPartDesc:undefined,
        startDate:"",
        endDate:"",
      },
      drawing:{

      },
      drawingDetailList:[],
      detailLoading:false,
      detailDialogVisible:false,
      saveDialogVisible:false,
    }
  },
  created() {
    this.searchModel.startDate = dayjs().hour(0).minute(0).second(0).format("YYYY-MM-DD HH:mm:ss");
    this.searchDrawingList();
  },
  methods:{
    searchDrawingList(){
      searchDrawingList(this.searchModel).then(({data})=>{
        if (data && data.code === 0){
          this.drawingList = data.rows;
        }else {
          this.$message.warning(data.msg);
        }
      }).catch((error)=>{
        this.$message.error(error);
      })
    },
    handleDelete(row){
      removeDrawing(row).then(({data})=>{
        if (data && data.code === 0){
          this.searchDrawingList();
          this.$message.success(data.msg);
        }else {
          this.$message.warning(data.msg);
        }
      }).catch((error)=>{
        this.$message.error(error);
      });
    },
    handleEdit(row){
      this.drawing = {...row}
      this.saveDialogVisible = true;
    },
    editDrawing(){
      editDrawing(this.drawing).then(({data})=>{
        if (data && data.code === 0){
          this.searchDrawingList();
          this.$message.success(data.msg);
          this.saveDialogVisible = false;
        }else {
          this.$message.warning(data.msg);
        }
      }).catch((error)=>{
        this.$message.error(error);
      });
    },
    handleDetail(row){
      this.detailLoading = true;
      this.drawingDetailList = [];
      this.detailDialogVisible = true;
      searchDrawingDetailList(row).then(({data})=>{
        if (data && data.code === 0){
          this.drawingDetailList = data.rows;
        }else {
          this.$message.warning(data.msg);
        }
        this.detailLoading = false;
      }).catch((error)=>{
        this.$message.error(error);
        this.detailLoading = false;
      })
    }
  }
}
</script>

<template>
<div>
  <el-form label-position="top" :model="searchModel">
    <el-row :gutter="10">
      <el-col :span="3">
        <el-form-item label="编码:">
          <el-input v-model="searchModel.drawingNo"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label="编码描述:">
          <el-input v-model="searchModel.drawingDesc" ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label="备注:">
          <el-input v-model="searchModel.remark" ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label="创建人:">
          <el-input v-model="searchModel.creator" ></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <el-col :span="3">
        <el-form-item label="IFS Part No:">
          <el-input v-model="searchModel.erpPartNo" ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label="IFS Part Description:">
          <el-input v-model="searchModel.erpPartDesc" ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label="开始日期:">
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="searchModel.startDate"
            style="width: 100%"
            type="date"
            placeholder="开始日期">

          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label="结束日期:">
          <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="searchModel.endDate" style="width: 100%" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="3">
        <el-form-item label=" ">
          <el-button type="primary" @click="searchDrawingList">搜索</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
  <el-table :data="drawingList" height="750" border style="width: 100%">
    <el-table-column prop="drawingNo" header-align="center" width="140" align="left" label="编码"></el-table-column>
    <el-table-column prop="drawingDesc" show-overflow-tooltip width="600" header-align="center" align="left" label="编码描述"></el-table-column>
    <el-table-column prop="erpPartNo" show-overflow-tooltip width="150" header-align="center" align="left" label="IFS Part No"></el-table-column>
    <el-table-column prop="erpPartDesc" show-overflow-tooltip width="180" header-align="center" align="left" label="IFS Part Description"></el-table-column>
    <el-table-column prop="creator" header-align="center" width="100" align="left" label="创建人"></el-table-column>
    <el-table-column prop="createDate" header-align="center" width="130" align="center" label="创建时间"></el-table-column>
    <el-table-column prop="remark" show-overflow-tooltip width="600" header-align="center" align="left" label="备注"></el-table-column>
    <el-table-column header-align="center" width="140" align="center" fixed="right" label="操作">
      <template slot-scope="{row}">
        <el-link style="cursor:pointer;" type="text" @click="handleEdit(row)">编辑</el-link>
        <el-link style="cursor:pointer;" type="text" @click="handleDelete(row)">删除</el-link>
        <el-link style="cursor:pointer;" type="text" @click="handleDetail(row)">详情</el-link>
      </template>
    </el-table-column>
  </el-table>
  <el-dialog title="编辑编码" :close-on-click-modal="false" :visible.sync="saveDialogVisible">
<!--    <fieldset-->
<!--      style="margin-top: 2px;border-color: rgb(255,255,255);">-->
<!--      <legend>更改前信息</legend>-->
      <el-form label-position="top" :model="drawing" ref="drawingForm">
        <el-form-item label="编码:">
          <el-input readonly v-model="drawing.drawingNo" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="编码描述:">
          <el-input v-model="drawing.drawingDesc" ></el-input>
        </el-form-item>
        <el-form-item label="备注:">
          <el-input v-model="drawing.remark" ></el-input>
        </el-form-item>
      </el-form>
<!--    </fieldset>-->
<!--    <fieldset-->
<!--      style="margin-top: 2px;border-color: rgb(255,255,255);">-->
<!--      <legend>更改后信息</legend>-->
<!--      <el-form label-position="top" :model="drawing" ref="drawingForm">-->
<!--        <el-form-item label="编码:">-->
<!--          <el-input v-model="drawing.drawingNo" style="width: 200px"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="编码描述:">-->
<!--          <el-input readonly v-model="drawing.drawingDesc"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备注:">-->
<!--          <el-input readonly v-model="drawing.remark"></el-input>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--    </fieldset>-->
    <el-footer style="height:30px;margin-top: 20px;text-align:center">
      <el-button type="primary" @click="editDrawing">保存</el-button>
      <el-button type="primary" @click="saveDialogVisible = false">关闭</el-button>
    </el-footer>
  </el-dialog>

  <el-dialog title="编码详情" :close-on-click-modal="false" v-drag :visible.sync="detailDialogVisible" :loading="detailLoading">
    <el-table :data="drawingDetailList" height="400" border style="width: 100%">
      <el-table-column prop="itemNo" header-align="center" width="140" align="right" label="序号"></el-table-column>
      <el-table-column prop="itemDesc" header-align="center" width="140" align="left" label="描述"></el-table-column>
      <el-table-column prop="itemName" header-align="center" width="140" align="left" label="元素名称"></el-table-column>
      <el-table-column prop="itemType" show-overflow-tooltip header-align="center" align="left" label="类型"></el-table-column>
      <el-table-column prop="itemLabel" show-overflow-tooltip header-align="center" align="left" label="选中项描述"></el-table-column>
      <el-table-column prop="itemValue" show-overflow-tooltip header-align="center" align="left" label="选中项值"></el-table-column>
    </el-table>
  </el-dialog>
</div>
</template>

<style scoped>
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
</style>
