<template>
  <div class="">
    <el-table
      :row-style="{ color: '#303133' }"
      :header-cell-style="{
        backgroundColor: 'rgb(245, 247, 250)',
        color: '#606266'
      }"
      :data="dialysis_before_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 label="操作" align="center">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="不展示" placement="top" v-if="scope.row.is_show == 1">
            <el-button
              size="small"
              type="danger"
              icon="el-icon-remove-outline"
              @click="handleHide(scope.$index, scope.row)">
            </el-button>
          </el-tooltip>

          <el-tooltip class="item" effect="dark" content="展示" placement="top"  v-if="scope.row.is_show == 2">
            <el-button
              size="small"
              type="primary"
              icon="el-icon-view"
              @click="handleShow(scope.$index, scope.row)">
            </el-button>
          </el-tooltip>

        </template>
      </el-table-column>
    </el-table>

  </div>

</template>


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

  export default {
    name: 'dialysisBefore',

    props: {
      dialysis_before_data: {
        type: Array
      }
    }, methods: {
      handleHide: function(index, row) {
        this.$confirm('是否将该字段设为不可见?', '提示', {
          confirmButtonText: '确 定',
          cancelButtonText: '取 消',
          type: 'warning'
        }).then(() => {
          updateFieldIsShow(row.id, 2).then(response => {
            if (response.data.state == 1) {
              const params = {
                id: response.data.data.id,
                is_show: response.data.data.is_show
              }
              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).then(response => {
            if (response.data.state == 1) {
              const params = {
                id: response.data.data.id,
                is_show: response.data.data.is_show
              }
              store.dispatch('updateFiledConfigList', params).then(() => {

              })
              this.$emit('change', params)
            }
          })
          this.$message({
            type: 'success',
            message: '设置成功!'
          })
        }).catch(() => {

        })
      }

    },
    created() {
    }
  }

</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>
