<template>

  <div class="app-container">

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="仪表盘" name="first">
        <div class="search">
          <el-input v-model="table.getdataListParm.parammaps.dname" placeholder="仪表盘名称" style="width: 180px;" class="filter-item" clearable />
          <el-select v-model="table.getdataListParm.parammaps.statue" placeholder="状态" class="filter-item" style="width: 120px;" clearable>
            <el-option v-for="item in statueList" :key="item.id" :label="item.value" :value="item.id" />
          </el-select>
          <el-button class="successBorder" @click="form_search">{{$t('common.query')}}</el-button>
          <el-button class="successBorder" @click="handleRefresh">{{$t('common.reset')}}</el-button>
        </div>
        <div class="operation">
          <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">{{$t('formulationEvaluation.add')}}</el-button>
        </div>
        <div class="table">
          <el-form ref="form" :rules="table.rules" :model="table">
            <el-table
              :key="table.tableKey"
              v-loading="table.listLoading"
              :element-loading-text="$t('common.tableMsg')"
              :data="table.list"
              border
              fit
              highlight-current-row
              style="width: 100%;"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
            >
              <!-- <el-table-column type="selection" align="center" width="50" /> -->
              <el-table-column :label="$t('formulationEvaluation.xh')" align="center" type="index" width="50px">
                <template slot-scope="scope">
                  <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column label="仪表盘名称" min-width="180px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.dname }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.dname" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:0 10px;" maxlength="32" />
                </template>
              </el-table-column>

              <el-table-column label="仪表盘描述" min-width="180px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.display }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.display" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:0 10px;" maxlength="32" />
                </template>
              </el-table-column>
              <el-table-column :label="$t('premixedPlan.status')" min-width="100px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit && scope.row.statue == 1">公开</span>
                  <span v-if="scope.row.NoEdit && scope.row.statue == 0">私有</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.statue" filterable placeholder="状态" class="filter-item" style="width:95%;padding:10px 0;" @change="changeStatue">
                    <el-option v-for="item in statueList" :key="item.id" :label="item.value" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>

              <el-table-column label="分发角色" min-width="150px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.rolenames }}</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.rolenamesId" multiple filterable placeholder="分发角色" class="filter-item" style="width:95%;padding:10px 0;" @change="changeRole">
                    <el-option v-for="item in roleList" :key="item.id" :label="item.rolename" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>

              <el-table-column label="显示到菜单" min-width="90px" align="center">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.reportenable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
                </template>
              </el-table-column>
              <el-table-column  :label="$t('role.cjr')" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.emp }}</span>
                </template>
              </el-table-column>
              <el-table-column
:label="$t('supplier.cjsj')" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.opratetime }}</span>
                </template>
              </el-table-column>
              <el-table-column  :label="$t('errorAnalysis.cz')" align="center" width="180" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="{row}">

                  <!-- 跳转页面 -->
                  <el-button class="miniSuccess" icon="el-icon-search" @click="jumpSee(row)" />
                  <span v-if="isRoleEdit" class="centerSpan">|</span>
                  <!-- <el-button class="miniSuccess" :disabled="row.empid != empid" @click="jumpEdit(row)">修改仪表盘</el-button> -->

                  <!-- 新增 -->
                  <el-button v-if="row.isCreate && isRoleEdit" class="miniSuccess" :disabled="isokDisable" icon="el-icon-folder-checked" @click="createData(row)" />
                  <span v-if="row.isCreate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isCreate && isRoleEdit" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
                  <!-- 编辑 -->
                  <el-button v-if="row.isUpdate &&isRoleEdit" class="miniSuccess" :disabled="row.empid != empid" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
                  <span v-if="row.isUpdate &&isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdate &&isRoleEdit" class="miniDanger" :disabled="row.empid != empid" icon="el-icon-delete" @click="handleRowDelete(row)" />
                  <!-- 编辑保存 -->
                  <el-button v-if="row.isUpdateSave && isRoleEdit" class="miniSuccess" :disabled="isokDisable" icon="el-icon-folder-checked" @click="updateData(row)" />
                  <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />

                </template>
              </el-table-column>
            </el-table>
          </el-form>
          <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
        </div>
      </el-tab-pane>
      <el-tab-pane label="图表" name="second">
        <div class="search">
          <el-input v-model="table2.getdataListParm.parammaps.dname" placeholder="图表名称" style="width: 180px;" class="filter-item" clearable />
          <el-select v-model="table2.getdataListParm.parammaps.statue" placeholder="状态" class="filter-item" style="width: 120px;" clearable>
            <el-option v-for="item in statueList2" :key="item.id" :label="item.value" :value="item.id" />
          </el-select>
          <el-button class="successBorder" @click="form_search2">{{$t('common.query')}}</el-button>
          <el-button class="successBorder" @click="handleRefresh2">{{$t('common.reset')}}</el-button>
        </div>
        <div class="operation">
          <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate2">{{$t('formulationEvaluation.add')}}</el-button>
        </div>
        <div class="table">
          <el-form ref="form" :rules="table2.rules" :model="table2">
            <el-table
              :key="table2.tableKey"
              v-loading="table2.listLoading"
              :element-loading-text="$t('common.tableMsg')"
              :data="table2.list"
              border
              fit
              highlight-current-row
              style="width: 100%;"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
            >
              <!-- <el-table-column type="selection" align="center" width="50" /> -->
              <el-table-column :label="$t('formulationEvaluation.xh')" align="center" type="index" width="50px">
                <template slot-scope="scope">
                  <span>{{ scope.$index + (table2.pageNum-1) * table2.pageSize + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column label="图表名称" min-width="200px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.cname }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.cname" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:0 10px;" maxlength="32" />
                </template>
              </el-table-column>

              <el-table-column label="图表描述" min-width="200px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.display }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.display" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:0 10px;" maxlength="32" />
                </template>
              </el-table-column>
              <el-table-column :label="$t('premixedPlan.status')" min-width="200px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit && scope.row.statue == 1">公开</span>
                  <span v-if="scope.row.NoEdit && scope.row.statue == 0">私有</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.statue" filterable placeholder="状态" class="filter-item" style="width:95%;padding:10px 0;" @change="changeStatue2">
                    <el-option v-for="item in statueList" :key="item.id" :label="item.value" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>

              <el-table-column  :label="$t('role.cjr')" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.emp }}</span>
                </template>
              </el-table-column>
              <el-table-column
:label="$t('supplier.cjsj')" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.opratetime }}</span>
                </template>
              </el-table-column>
              <el-table-column  :label="$t('errorAnalysis.cz')" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="{row}">

                  <!-- 跳转页面 -->
                  <el-button class="miniSuccess" icon="el-icon-search" @click="jumpSee2(row)" />
                  <span v-if="isRoleEdit" class="centerSpan">|</span>
                  <a v-if="isRoleEdit" class="correcting" :disabled="row.empid != empid" @click="jumpEdit2(row)">修改图表</a>
                  <span v-if="isRoleEdit" class="centerSpan">|</span>
                  <!-- 新增 -->
                  <el-button v-if="row.isCreate && isRoleEdit" class="miniSuccess" :disabled="isokDisable" icon="el-icon-folder-checked" @click="createData2(row)" />
                  <span v-if="row.isCreate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isCreate && isRoleEdit" class="minCancel" icon="el-icon-close" @click="createCancel2(row)" />
                  <!-- 编辑 -->
                  <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" :disabled="row.empid != empid" icon="el-icon-edit-outline" @click="handleUpdate2(row)" />
                  <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" :disabled="row.empid != empid" icon="el-icon-delete" @click="handleRowDelete2(row)" />
                  <!-- 编辑保存 -->
                  <el-button v-if="row.isUpdateSave && isRoleEdit" class="miniSuccess" :disabled="isokDisable" icon="el-icon-folder-checked" @click="updateData2(row)" />
                  <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel2(row)" />

                </template>
              </el-table-column>
            </el-table>
          </el-form>
          <pagination v-show="table2.total>=0" :total="table2.total" :page.sync="table2.getdataListParm.offset" :limit.sync="table2.getdataListParm.pagecount" @pagination="getList2" />
        </div>
      </el-tab-pane>

    </el-tabs>
    <el-dialog title="新增仪表盘" width="750px" :visible.sync="editDialogVisible">
      <el-form label-width="160px">
        <el-form-item label="仪表盘名称">
          <el-input v-model="dbObj.dname" size="small" style="width: 450px;" placeholder="请输入仪表盘名称" />
        </el-form-item>
        <el-form-item label="仪表盘描述">
          <el-input v-model="dbObj.display" type="textarea" :rows="5" size="small" style="width: 450px;" placeholder="请输入仪表盘描述" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose" @click="editDialogVisible = false">{{$t('formulationEvaluation.cancel')}}</el-button>
        <el-button class="save" @click="handleSubmit"> 确认</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { GetDataByName, GetDataByNames, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
import Cookies from 'js-cookie'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'
export default {
  name: 'BoardEchartManagement',
  components: { Pagination },
  data() {
    return {
      empid: Cookies.get('employeid'),
      editDialogVisible: false,
      dbObj: {},
      // requestParams: [
      //   { name: 'getDictByName', offset: 0, pagecount: 0, params: ['牲畜父类'] }
      // ],
      requestParams: [
        { name: 'getRoleAll', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
      ],

      statueList: [{ id: '1', value: '公开' }, { id: '0', value: '私有' }],
      statueList2: [{ id: '1', value: '公开' }, { id: '0', value: '私有' }],

      roleList: [],

      rolenamesIdTempArr: [],

      table: {
        rules: {
          name: { type: 'string', required: true, message:  this.$t('message.msg159'), trigger: 'change' }
        },
        getdataListParm: {
          name: 'getDashboardList',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pageCount')),
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            dname: '',
            statue: '',
            empid: Cookies.get('employeid')
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      table2: {
        rules: {
          name: { type: 'string', required: true, message:  this.$t('message.msg159'), trigger: 'change' }
        },
        getdataListParm: {
          name: 'getChartList',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pageCount')),
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            cname: '',
            statue: '',
            empid: Cookies.get('employeid')
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' },

      activeName: 'first',
      isRoleEdit: []

    }
  },

  created() {
    this.getList()
    this.getList2()
    this.getDownList()
    this.getButtons()

    if (this.$route.params.tab == 'second') {
      this.activeName = 'second'
    } else {
      this.activeName = 'first'
    }
  },

  methods: {
    getButtons() {
      const Edit = 'BoardEchartManagement'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit
    },
    handleClick(tab, event) {
      console.log(tab, event)
    },
    getDownList() {
      GetDataByNames(this.requestParams).then(response => {
        console.log('下拉框数据', response.data)
        this.roleList = response.data.getRoleAll.list
      })
    },
    getList() {
      this.table.listLoading = true
      console.log(this.table.getdataListParm)
      GetDataByName(this.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.$set(response.data.list[i], 'Edit', false) // 编辑
            this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
            this.$set(response.data.list[i], 'isCreate', false) // 新增操作
            this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
            this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
          }

          var arr = response.data.list

          arr.map(function(i, j) {
            // console.log(i, '====')
            if (i.roleids) {
              return i.rolenamesId = i.roleids.split(',')
            } else {
              return i.rolenamesId = []
            }
          })

          arr.map(function(i, j) {
            if (i.roleids) {
              return i.rolenamesId2B = i.roleids.split(',')
            } else {
              return i.rolenamesId2B = []
            }
          })
          this.table.list = arr

          this.table.pageNum = response.data.pageNum
          this.table.pageSize = response.data.pageSize
          this.table.total = response.data.total
        } else {
          this.table.list = []
        }
        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    },
    getList2() {
      this.table2.listLoading = true
      console.log(this.table2.getdataListParm)
      GetDataByName(this.table2.getdataListParm).then(response => {
        console.log('table2数据', response.data.list)
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.$set(response.data.list[i], 'Edit', false) // 编辑
            this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
            this.$set(response.data.list[i], 'isCreate', false) // 新增操作
            this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
            this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
          }
          this.table2.list = response.data.list
          this.table2.pageNum = response.data.pageNum
          this.table2.pageSize = response.data.pageSize
          this.table2.total = response.data.total
        } else {
          this.table2.list = []
        }
        setTimeout(() => {
          this.table2.listLoading = false
        }, 100)
      })
    },
    handleEnableChange(val) {
      console.log('点击了是否启用', val)
    },
    form_search() {
      console.log('点击了查询')
      this.table.getdataListParm.offset = 1
      this.getList()
    },
    form_search2() {
      console.log('点击了查询')
      this.table2.getdataListParm.offset = 1
      this.getList2()
    },

    handleRefresh() {
      console.log('点击了重置')
      this.table.getdataListParm.parammaps.cname = ''
      this.table.getdataListParm.parammaps.dname = ''
      this.table.getdataListParm.parammaps.statue = ''
      this.table.getdataListParm.offset = 1
      this.getList()
    },
    handleRefresh2() {
      console.log('点击了重置')
      this.table2.getdataListParm.parammaps.cname = ''
      this.table2.getdataListParm.parammaps.dname = ''
      this.table2.getdataListParm.parammaps.statue = ''
      this.table2.getdataListParm.offset = 1
      this.getList2()
    },

    // changeParent(val) {
    //   console.log('点击了牲畜类别父类', val)
    //   console.log(this.parentList.find(obj => obj.value == val).label)
    //   this.table.temp.parentname = this.parentList.find(obj => obj.value == val).label
    // },id
    changeStatue(val) {
      console.log('点击了状态', val)
      // console.log(this.statueList.find(obj => obj.value == val).id)
      this.table.temp.statueid = val
      this.table.temp.statue = val
    },
    changeStatue2(val) {
      console.log('点击了状态', val)
      // console.log(this.statueList.find(obj => obj.value == val).id)
      this.table2.temp.statueid = val
      this.table2.temp.statue = val
    },

    changeRole(val) {
      console.log('点击了角色', val)

      console.log('this.table.list', this.table.list)
      var arr = []

      this.roleList.forEach(function(i) {
        val.forEach(function(j) {
          if (i.id == j) {
            arr.push(i)
          }
        })
      })

      console.log('点击了角色', arr)

      this.table.temp.rolenamesId = arr

      this.rolenamesIdTempArr = arr
    },
    handleCreate() {
      this.editDialogVisible = true
    },
    handleSubmit() {
      var data = {
        name: 'insertDashboard',
        parammaps: {
          dname: this.dbObj.dname,
          display: this.dbObj.display,
          pastureid: Cookies.get('pastureid'),
          empid: Cookies.get('employeid'),
          emp: Cookies.get('employename')
        }
      }

      PostDataByName(data).then(res => {
        console.log('新增保存发送参数', data)
        this.$message({
          type: 'success',
          message: this.$t('common.saveSuccess')
        })

        this.editDialogVisible = false
        console.log('res', res)
        if (res.data.LastInsertId) {
          this.$router.push({ name: 'Addboard', params: { id: res.data.LastInsertId, isEdit: 'create' }})
          Cookies.set('AddboardIsEdit', 'create')
          Cookies.set('AddboardIsEditId', res.data.LastInsertId)

          localStorage.setItem('AddboardIsEditId', res.data.LastInsertId)
        }
      })
    },

    createData(row) {
      console.log('点击了新增保存')
      this.table.temp.pastureid = Cookies.get('pastureid')
      this.table.temp.dname = row.dname
      this.table.temp.display = row.display
      this.table.temp.statue = row.statue
      this.table.temp.reportenable = row.reportenable
      this.table.temp.emp = row.emp
      this.table.temp.opratetime = row.opratetime

      // 仪表盘名称/状态是否为空
      if (this.table.temp.dname == '' && this.table.temp.statue == '') {
        this.$message({ type: 'error', message:  this.$t('message.msg160'), duration: 2000 })
        return false
      } else if (this.table.temp.dname == '') {
        this.$message({ type: 'error', message:  this.$t('message.msg161'), duration: 2000 })
        return false
      }
      const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
      if (pattern.test(this.table.temp.dname)) {
        this.$message({ type: 'error', message:  this.$t('message.msg162'), duration: 2000 })
        return false
      }

      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.requestParam.name = 'insertDashboard'
      this.requestParam.parammaps = this.table.temp
      PostDataByName(this.requestParam).then(response => {
        console.log('新增保存发送参数', this.requestParam)
        if (response.msg !== 'fail') {
          this.$notify({ title: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), type: 'success', duration: 2000 })
          this.getList()
        } else {
          this.$notify({ title: this.$t('driver.saveFail'), message: response.data, type: 'warning', duration: 2000 })
        }
      })
    },

    createCancel(row) {
      console.log('点击了新增取消')
      for (let i = 0; i < this.table.list.length; i++) {
        if (row.myId === this.table.list[i].myId) {
          var listIndex = this.table.list.indexOf(this.table.list[i])
        }
        if (listIndex > -1) {
          this.table.list.splice(listIndex, 1)
          return
        }
      }
    },
    handleCreate2(row) {
      this.$router.push({ name: 'ChartPanel', params: { id: 'create', isEdit: 'edit' }})
      Cookies.set('ChartPanelIsEdit', 'edit')
      Cookies.set('ChartPanelIsEditId', 'create')
      localStorage.setItem('ChartPanelIsEditId', 'create')
    },
    jumpSee(row) {
      console.log('点击了查看', row)
      this.$router.push({ name: 'Addboard', params: { id: row.id, isEdit: 'view', isRoleEdit: this.isRoleEdit }})
      Cookies.set('AddboardIsEdit', 'view')
      Cookies.set('AddboardIsEditId', row.id)

      localStorage.setItem('AddboardIsEditId', row.id)
    },
    jumpEdit(row) {
      console.log('点击了编辑', row)
      this.$router.push({ name: 'Addboard', params: { id: row.id, isEdit: 'edit' }})
      Cookies.set('AddboardIsEdit', 'edit')
      Cookies.set('AddboardIsEditId', row.id)

      localStorage.setItem('AddboardIsEditId', row.id)
    },
    jumpSee2(row) {
      console.log('点击了查看', row)
      this.$router.push({ name: 'ChartPanel', params: { id: row.id, isEdit: 'view', isRoleEdit: this.isRoleEdit }})
      Cookies.set('ChartPanelIsEdit', 'view')
      Cookies.set('ChartPanelIsEditId', row.id)

      localStorage.setItem('ChartPanelIsEditId', row.id)
      localStorage.setItem('ChartPanelIsEdit', 'view')
      this.$store.state.user.dashchartid = row.id
      this.$store.state.user.dashchartidisedit = 'view'
    },
    jumpEdit2(row) {
      console.log('点击了编辑', row)
      this.$router.push({ name: 'ChartPanel', params: { id: row.id, isEdit: 'edit' }})
      Cookies.set('ChartPanelIsEdit', 'edit')
      Cookies.set('ChartPanelIsEditId', row.id)

      localStorage.setItem('ChartPanelIsEditId', row.id)
      localStorage.setItem('ChartPanelIsEdit', 'edit')
      this.$store.state.user.dashchartid = row.id
      this.$store.state.user.dashchartidisedit = 'edit'
    },

    handleUpdate(row) {
      console.log('点击了设置', row)
      for (let i = 0; i < this.table.list.length; i++) {
        if (this.table.list[i].Edit == true) {
          this.$message({ type: 'error', message: this.$t('driver.messageNote'), duration: 2000 })
          return false
        }
      }
      // 编辑true,不可编辑false
      row.Edit = true
      row.NoEdit = false
      // 新增false,编辑false,编辑保存true
      row.isCreate = false
      row.isUpdate = false
      row.isUpdateSave = true
      // console.log(row.parentid)
      row.statue = String(row.statue)
      console.log('row.statue ', row.statue)
      this.table.temp.statue = row.statue
      this.table.temp.statueid = row.statueid
      this.table.temp.parentname = row.parentname
    },
    handleUpdate2(row) {
      console.log('点击了设置', row)
      for (let i = 0; i < this.table2.list.length; i++) {
        if (this.table2.list[i].Edit == true) {
          this.$message({ type: 'error', message: this.$t('driver.messageNote'), duration: 2000 })
          return false
        }
      }
      // 编辑true,不可编辑false
      row.Edit = true
      row.NoEdit = false
      // 新增false,编辑false,编辑保存true
      row.isCreate = false
      row.isUpdate = false
      row.isUpdateSave = true
      // console.log(row.parentid)
      row.statue = String(row.statue)
      this.table2.temp.statue = row.statue
      this.table2.temp.statueid = row.statueid
    },
    updateData(row) {
      console.log('点击了编辑保存')
      this.table.temp.pastureid = Cookies.get('pastureid')
      this.table.temp.dname = row.dname
      this.table.temp.display = row.display
      this.table.temp.reportenable = row.reportenable
      this.table.temp.emp = row.emp
      this.table.temp.opratetime = row.opratetime
      this.table.temp.id = row.id
      this.table.temp.statue = row.statue
      this.table.temp.rolenamesId = row.rolenamesId
      console.log(this.table.temp.rolenamesId)

      var rolenamesIdArr = []

      this.table.temp.rolenamesId.forEach(function(i, j) {
        rolenamesIdArr.push({ 'id': i })
      })
      // 仪表盘名称/状态是否为空
      if (this.table.temp.dname == '' && this.table.temp.statue == '') {
        this.$message({ type: 'error', message:  this.$t('message.msg160'), duration: 2000 })
        return false
      } else if (this.table.temp.dname == '') {
        this.$message({ type: 'error', message:  this.$t('message.msg161'), duration: 2000 })
        return false
      }
      const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
      if (pattern.test(this.table.temp.dname)) {
        this.$message({ type: 'error', message:  this.$t('message.msg162'), duration: 2000 })
        return false
      }

      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)

      console.log(this.table.temp)

      var send_data3 = {
        'common': { 'returnmap': '0' },
        'data': [
          {
            'name': 'updateDashboard',
            'type': 'e',
            'parammaps': this.table.temp
          },
          {
            'name': 'deleteDrole',
            'type': 'e',
            'parammaps': {
              'id': row.id,
              'pastureid': Cookies.get('pastureid')
            }
          },
          {
            'name': 'insertSpotList',
            'resultmaps': {
              'list': rolenamesIdArr
            },
            'children': [
              {
                'name': 'insertDrole',
                'type': 'e',
                'parammaps':
                  {
                    'id': row.id,
                    'pastureid': Cookies.get('pastureid'),
                    'roleid': '@insertSpotList.id'
                  }
              }
            ]
          }
        ]
      }

      ExecDataByConfig(send_data3).then(response => {
        if (response.msg !== 'fail') {
          this.$notify({ title: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), type: 'success', duration: 2000 })
          this.getList()
        } else {
          this.$notify({ title: this.$t('driver.saveFail'), message: response.data, type: 'warning', duration: 2000 })
        }
      })
    },
    updateData2(row) {
      console.log('点击了编辑保存')
      this.table2.temp.pastureid = Cookies.get('pastureid')
      this.table2.temp.cname = row.cname
      this.table2.temp.display = row.display

      this.table2.temp.emp = row.emp
      this.table2.temp.opratetime = row.opratetime
      this.table2.temp.id = row.id
      this.table2.temp.statue = row.statue
      // 仪表盘名称/状态是否为空
      if (this.table2.temp.dname == '' && this.table.temp.statue == '') {
        this.$message({ type: 'error', message:  this.$t('message.msg160'), duration: 2000 })
        return false
      } else if (this.table2.temp.dname == '') {
        this.$message({ type: 'error', message:  this.$t('message.msg161'), duration: 2000 })
        return false
      }
      const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
      if (pattern.test(this.table2.temp.dname)) {
        this.$message({ type: 'error', message:  this.$t('message.msg162'), duration: 2000 })
        return false
      }

      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)

      console.log(this.table2.temp)

      var send_data3 = {
        'name': 'updateChart',
        'parammaps': this.table2.temp
      }

      PostDataByName(send_data3).then(response => {
        console.log('新增保存发送参数', send_data3)
        if (response.msg !== 'fail') {
          this.$notify({ title: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), type: 'success', duration: 2000 })
          this.getList2()
        } else {
          this.$notify({ title: this.$t('driver.saveFail'), message: response.data, type: 'warning', duration: 2000 })
        }
      })
    },
    updateCancel(row) {
      console.log('点击了编辑取消')
      // 编辑false,不可编辑true
      row.Edit = false
      row.NoEdit = true
      // 新增false,编辑true,编辑保存false
      row.isCreate = false
      row.isUpdate = true
      row.isUpdateSave = false

      row.rolenamesId = row.rolenamesId2B
    },
    updateCancel2(row) {
      console.log('点击了编辑取消')
      // 编辑false,不可编辑true
      row.Edit = false
      row.NoEdit = true
      // 新增false,编辑true,编辑保存false
      row.isCreate = false
      row.isUpdate = true
      row.isUpdateSave = false
    },
    handleRowDelete(row) {
      console.log('点击了行内删除')
      MessageBox.confirm( this.$t('common.delMsg'), {
        confirmButtonText: this.$t('common.confirm'), cancelButtonText: this.$t('common.cancel'), type: 'warning'
      }).then(() => {
        this.requestParam.name = 'deleteDashboard'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.pastureid = row.pastureid
        this.requestParam.parammaps.id = row.id
        PostDataByName(this.requestParam).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.$notify({ title: this.$t('common.succes'),message: this.$t('common.delSuccess'), type: 'success', duration: 2000 })
            this.getList()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: this.$t('common.cancelMsg') })
      })
    },
    handleRowDelete2(row) {
      console.log('点击了行内删除')

      var send_data = {
        'name': 'getChartuseCount',
        'parammaps': {
          'pastureid': Cookies.get('pastureid'),
          'id': row.id
        }

      }

      GetDataByName(send_data).then(res => {
        console.log(res)
        if (res.data.list[0].cou > 0) {
          MessageBox.confirm('当前图表已被引用，是否进行删除?', {
            confirmButtonText: this.$t('common.confirm'), cancelButtonText: this.$t('common.cancel'), type: 'warning'
          }).then(() => {
            this.requestParam.name = 'deleteChart'
            this.requestParam.parammaps = {}
            this.requestParam.parammaps.pastureid = row.pastureid
            this.requestParam.parammaps.id = row.id
            PostDataByName(this.requestParam).then(response => {
              if (response.msg === 'fail') {
                this.$notify({ title: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
              } else {
                this.$notify({ title: this.$t('common.succes'),message: this.$t('common.delSuccess'), type: 'success', duration: 2000 })
                this.getList2()
              }
            })
          }).catch(() => {
            this.$message({ type: 'info', message: this.$t('common.cancelMsg') })
          })
        } else {
          this.requestParam.name = 'deleteChart'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.pastureid = row.pastureid
          this.requestParam.parammaps.id = row.id
          PostDataByName(this.requestParam).then(response => {
            if (response.msg === 'fail') {
              this.$notify({ title: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
            } else {
              this.$notify({ title: this.$t('common.succes'),message: this.$t('common.delSuccess'), type: 'success', duration: 2000 })
              this.getList2()
            }
          })
        }
      })

      // MessageBox.confirm('当前图表已被引用，是否进行删除?', {
      //   confirmButtonText: this.$t('common.confirm'), cancelButtonText: this.$t('common.cancel'), type: 'warning'
      // }).then(() => {
      //   this.requestParam.name = 'deleteChart'
      //   this.requestParam.parammaps = {}
      //   this.requestParam.parammaps.pastureid = row.pastureid
      //   this.requestParam.parammaps.id = row.id
      //   PostDataByName(this.requestParam).then(response => {
      //     if (response.msg === 'fail') {
      //       this.$notify({ title: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
      //     } else {
      //       this.$notify({ title: this.$t('common.succes'),message: this.$t('common.delSuccess'), type: 'success', duration: 2000 })
      //       this.getList2()
      //     }
      //   })
      // }).catch(() => {
      //   this.$message({ type: 'info', message: this.$t('common.cancelMsg') })
      // })
    }

  }
}
</script>
<style lang="scss" scoped>
.search {
  margin-top: 10px;
}
.table {
  margin-top: 10px;
}
</style>
