<template>
  <div class="">
    <el-table
      :row-style="{ color: '#303133' }"
      :header-cell-style="{
        backgroundColor: 'rgb(245, 247, 250)',
        color: '#606266'
      }"
      :data="dialysis_off_data"
      border
      fit
      highlight-current-row
      style="width: 100%;min-height:500px;"
    >
      <el-table-column align="center" label="字段名">
        <template slot-scope="scope">
          <span>{{ scope.row.filed_name_cn }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="字段">
        <template slot-scope="scope">
          <span>{{ scope.row.filed_name }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="是否显示">
        <template slot-scope="scope">
          <span v-if="scope.row.is_show == 1">是</span>
          <span v-if="scope.row.is_show == 2">否</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="是否必填">
        <template slot-scope="scope">
          <span v-if="scope.row.is_write!=undefined &&scope.row.is_write == 1">是</span>
          <span v-if="scope.row.is_write!=undefined &&scope.row.is_write == 0">否</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
            <el-button
              v-if="scope.row.is_show == 1"
              size="small"
              type="danger"
              icon="el-icon-remove-outline"
              @click="handleHide(scope.$index, scope.row)"
            >
            </el-button>
          
            <el-button
              v-if="scope.row.is_show == 2"
              size="small"
              type="primary"
              icon="el-icon-view"
              @click="handleShow(scope.$index, scope.row)"
            >
            </el-button>

            <el-button
              v-if="scope.row.is_write!=undefined&&scope.row.is_write == 1"
              :disabled="scope.row.is_second_menu!=undefined&&scope.row.is_second_menu ==0?false:true"
              size="small"
              type="danger"
              icon="el-icon-remove-outline"
              @click="handleHideOne(scope.$index, scope.row)"
            >
            </el-button>

           
            <el-button
              v-if="scope.row.is_write!=undefined&&scope.row.is_write == 0"
              :disabled="scope.row.is_second_menu!=undefined&&scope.row.is_second_menu ==0?false:true"
              size="small"
              type="primary"
              icon="el-icon-view"
              @click="handleShowOne(scope.$index, scope.row)"
            >
            </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { updateFieldIsShow } from "@/api/data";
import store from "@/store";

export default {
  name: "dialysisAfter",

  props: {
    dialysis_off_data: {
      type: Array
    }
  },
  data(){
    return {
    is_show:2,
    is_write:0,
   }
  },
  methods: {
    handleHide: function(index, row) {
      this.$confirm("是否将该字段设为不可见?", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning"
      })
        .then(() => {
          updateFieldIsShow(row.id, 2,row.is_write).then(response => {
            if (response.data.state == 1) {
              this.is_show = response.data.data.is_show
              let params = {
                id: response.data.data.id,
                is_show: response.data.data.is_show,
                is_write:response.data.data.is_write,
              };
              store.dispatch("updateFiledConfigList", params).then(() => {});
              this.$emit("change", params);
            }
          });
          this.$message({
            type: "success",
            message: "设置成功!"
          });
        })
        .catch(() => {});
    },
    handleHideOne: function(index, row) {
      this.$confirm("是否将该字段设为不必填?", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning"
      })
        .then(() => {
          updateFieldIsShow(row.id,row.is_show,0).then(response => {
          
            if (response.data.state == 1) {
              this.is_write = response.data.data.is_write
              let params = {
                id: response.data.data.id,
                is_show: response.data.data.is_show,
                is_write:response.data.data.is_write,
              };
              store.dispatch("updateFiledConfigList", params).then(() => {});
              this.$emit("change", params);
            }
          });
          this.$message({
            type: "success",
            message: "设置成功!"
          });
        })
        .catch(() => {});
    },
    handleShow: function(index, row) {
      this.$confirm("是否将该字段设为可见?", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning"
      }).then(() => {
          updateFieldIsShow(row.id, 1,row.is_write).then(response => {
            if (response.data.state == 1) {
              this.is_show = response.data.data.is_show
              let params = {
                id: response.data.data.id,
                is_show: response.data.data.is_show,
                is_write:response.data.data.is_write,
              };
              store.dispatch("updateFiledConfigList", params).then(() => {});
              this.$emit("change", params);
            }
          });
          this.$message({
            type: "success",
            message: "设置成功!"
          });
        })
        .catch(() => {});
    },
    handleShowOne: function(index, row) {
      this.$confirm("是否将该字段设为必填?", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning"
      }).then(() => {
         
          updateFieldIsShow(row.id,row.is_show,1).then(response => {
            if (response.data.state == 1) {
              this.is_write = response.data.data.is_write
              let params = {
                id: response.data.data.id,
                is_show: response.data.data.is_show,
                is_write:response.data.data.is_write,
              };
              store.dispatch("updateFiledConfigList", params).then(() => {});
              this.$emit("change", params);
            }
          });
          this.$message({
            type: "success",
            message: "设置成功!"
          });
        })
        .catch(() => {});
    }
  },
  created(){
    console.log("dialysis_off_data",this.dialysis_off_data)
  }
};
</script>

<style scoped></style>
<style>
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}
</style>
