<template>
  <div class="app-container">
    <div class="filter-container">
      <!-- 搜索条件 -->
      <el-select v-model="getdataListParm.parammaps.pastureName" placeholder="牧场" class="filter-item" style="width: 110px" @change="changePastureName">
        <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>

      <el-input v-model="getdataListParm.parammaps.eqCode" placeholder="设备内部编号" clearable class="filter-item" style="width: 130px" />
      <el-input v-model="getdataListParm.parammaps.eqName" placeholder="设备名称" style="width: 130px;" class="filter-item" />

      <el-select v-model="getdataListParm.parammaps.deptId" clearable placeholder="部门" class="filter-item" style="width: 100px">
        <el-option v-for="item in findAllDepart" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.syStatus" clearable placeholder="状态" class="filter-item" style="width:100px;">
        <el-option v-for="item in getDictByName" :key="item.id" :label="item.label" :value="item.value" />
      </el-select>
      <el-date-picker v-model="getdataListParm.parammaps.enabledTime" type="date" placeholder="开启日期" style="width:140px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />
      <el-date-picker v-model="getdataListParm.parammaps.blockTime" type="date" placeholder="关闭日期" style="width:140px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
      <div>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_add">启停</el-button>
      </div>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      element-loading-text="给我一点时间"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      :row-style="rowStyle"
      :cell-style="cellStyle"
      class="elTable"
    >
      <el-table-column label="序号" align="center" type="index" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="牧场" min-width="90px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.pastureName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备名称" min-width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.eqName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备内部编号" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.eqCode }}</span>
        </template>
      </el-table-column>

      <el-table-column label="规格" min-width="90px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.specification }}</span>
        </template>
      </el-table-column>
      <el-table-column label="品牌" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.brandName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备图片" min-width="110px" align="center">
        <template slot-scope="scope">
          <el-popover placement="right" title="" trigger="hover">
            <img v-if="scope.row.picpath !== ''" :src="scope.row.picpath">
            <img v-if="scope.row.picpath !== ''" slot="reference" :src="scope.row.picpath" :alt="scope.row.srcpath" style="height: 100px;width:100px;">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="启停状态" min-width="70px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.changeStatue }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门" min-width="80px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.deptName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最近开启时间" sortable prop="enabledTime" min-width="120px" align="center" />
      <el-table-column label="最近关闭时间" sortable prop="blockTime" min-width="120px" align="center" />
      <el-table-column label="操作" align="center" width="300" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button type="success" size="mini" :disabled="row.changeStatue=='启用'? true : false" @click="handleSST(row)">开启</el-button>
          <el-button type="danger" size="mini" :disabled="row.changeStatue=='停用'? true : false" @click="handleSST(row)">关闭</el-button>
          <el-button type="primary" size="mini" @click="form_see(row)">启停记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
    <!-- 弹出层新增or修改 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form ref="temp" :rules="rules" :model="temp" label-position="right" label-width="140px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="设备名称：" prop="assetName">
              <el-autocomplete
                ref="assetName"
                v-model="temp.assetName"
                value-key="assetName"
                class="inline-input"
                :fetch-suggestions="formNameSearch"
                placeholder="请输入内容"
                :disabled="dialogStatus==='update'"
                style="width:100%;"
                @select="handleformNameSelect"
              >
                <template slot-scope="{ item }">
                  <div class="name" style="display: inline;">{{ item.eqName }}</div>
                  <span class="addr">{{ item.eqCode }}</span>
                </template>
              </el-autocomplete>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备内部编号：" prop="eqCode">
              <el-autocomplete
                ref="eqCode"
                v-model="temp.eqCode"
                value-key="eqCode"
                class="inline-input"
                :fetch-suggestions="formNumberSearch"
                placeholder="请输入内容"
                :disabled="dialogStatus==='update'"
                style="width:100%;"
                @select="handleformNumberSelect"
              >
                <template slot-scope="{ item }">
                  <div class="name" style="display: inline;">{{ item.eqName }}</div>
                  <span class="addr">{{ item.eqCode }}</span>
                </template>
              </el-autocomplete>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="启停状态：">
              <el-input v-model="temp.changeStatue" disabled style="width:100%;" />

            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="牧场：">
              <!-- <span>{{ temp.pastureName }}</span> -->
              <el-input v-model="temp.pastureName" disabled style="width:100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门：">
              <el-input v-model="temp.deptName" disabled style="width:100%;" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="操作人：" prop="employeId">
              <el-select v-model="temp.employeId" placeholder="操作人" class="filter-item" style="width:100%;">
                <el-option
                  v-for="item in findAllEmploye"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="false">
          <el-col :span="8">
            <el-form-item label="操作时间：" prop="inputDatetime">
              <el-date-picker
                v-model="temp.inputDatetime"
                type="datetime"
                placeholder="操作时间"
                style="width:100%;"
                :picker-options="pickerOptions0"
              />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button v-if="temp.changeStatue =='停用'" type="primary" @click="createStartData()">开启</el-button>
        <el-button v-if="temp.changeStatue =='启用'" type="primary" @click="createStopData()">停用</el-button>
        <el-button @click="dialogFormVisible = false;getList()">关闭</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="textMap[dialogStatusSST]" :visible.sync="dialogFormVisibleSST" :close-on-click-modal="false" style="width:500px;margin:0 auto;margin-bottom:50px">
      <div class="app-SST">
        <el-form ref="tempSST" :rules="rules" :model="tempSST" label-position="right" label-width="100px">
          <h3 style="margin-bottom:50px;">是否{{ tempSST.changeStatue =="停用"?"开启":"关闭" }}？</h3>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="tempSST.changeStatue =='停用'?add_dialog_saveSST1():add_dialog_saveSST2()">确认</el-button>
          <el-button @click="dialogFormVisibleSST = false">关闭</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 启停记录 -->
    <el-dialog :title="cardTitle" :visible.sync="dialogFormVisibleCard" :close-on-click-modal="false" width="90%">
      <div class="app-contentcard">
        <el-form ref="rowSeeData" :rules="rules" :model="rowSeeData" label-position="right" label-width="120px" style="width: 100%;margin:0 auto;">
          <div class="filter-container">
            <el-date-picker v-model="getdataListParmSee.parammaps.startTime" type="date" placeholder="开启日期" style="width:140px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />
            <el-date-picker v-model="getdataListParmSee.parammaps.stopTime" type="date" placeholder="关闭日期" style="width:140px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_searchDelivery">搜索</el-button>
          </div>
        </el-form>
        <el-table
          :key="tableKey"
          v-loading="listLoadingSee"
          element-loading-text="给我一点时间"
          :data="listSee"
          border
          fit
          highlight-current-row
          style="width: 100%;"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable"
          @sort-change="tableSort"
        >
          <el-table-column label="序号" align="center" type="index" width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="开启时间" sortable prop="enabledTime" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.enabledTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="关闭时间" sortable prop="blockTime" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.blockTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="运行时间(分钟)" sortable prop="runTime" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.runTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="开启人" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.enabledName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="关闭人" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.blockName }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalSee>0" :total="totalSee" :page.sync="getdataListParmSee.offset" :limit.sync="getdataListParmSee.pagecount" @pagination="getListSee" />
      </div>
      <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom:10px">
        <el-button @click="dialogFormVisibleCard = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入
// eslint-disable-next-line no-unused-vars
import { GetDataByName, GetDataByNames, ExecDataByConfig, PostDataByName } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import { parseTime, sortChange } from '@/utils/index.js'
// eslint-disable-next-line no-unused-vars
import { validateEMail } from '@/utils/validate.js'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
// eslint-disable-next-line no-unused-vars
import { parse } from 'querystring'
import Cookies from 'js-cookie'
export default {
  name: 'SST',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      requestParam: {
        name: 'insertAsset',
        offset: 0,
        pagecount: 0,
        parammaps: {}
      },
      // 1-2:table&搜索传参
      getdataListParm: {
        // name: 'getAssetSTTList',
        name: 'geteqSTTList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          eqCode: '',
          eqName: '',
          pastureName: Cookies.get('pasturename'),
          deptName: '',
          syStatus: '',
          deptId: this.$route.query.deptId,
          blockTime: '',
          enabledTime: ''
        }
      },
      requestParamSST: {
        name: 'updateEQStartStop',
        parammaps: {
          inputDatetime: new Date(),
          employeId: Cookies.get('employeid'),
          pastureId: Cookies.get('pastureid'),
          sttId: ''
        }
      },
      temp: {
        pastureName: '',
        deptName: '',
        deptId: '',
        employeName: '',
        eqName: '',
        assetId: '',
        eqCode: '',
        inputDatetime: new Date(),
        typeName: '',
        assTypeId: '',
        syStatus: '',
        employeId: this.$store.state.user.employeid,
        departmentId: this.$store.state.user.departmentid,
        pastureId: this.$store.state.user.pastureid
      },
      tempSST: {

      },
      // 2-3：下拉框请求后数据加入[]
      findAllProvider: [],
      findAllAssetType: [],
      findAllPasture: [],
      findAllDepart: [],
      findAllEmploye: [],
      getDictByName: [], createDepartList: [], edit: 0,
      // 2-1.请求下拉框接口
      requestParams: [
        { name: 'findAllProvider', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllAssetType', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'getDictByName', offset: 0, pagecount: 0, params: ['设备使用记录'] }
      ],
      getDepartParam: {
        name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }
      },
      postDataPramas: {},
      assetA: { eqName: '', eqCode: '' },
      requestFilterParams: {
        name: 'findAssetMain',
        page: 1,
        offset: 1,
        pagecount: 20,
        returntype: 'Map',
        parammaps: {}
      },
      dialogFormVisible: false,
      dialogFormVisibleCheck: false,

      dialogStatus: '',
      dialogFormVisibleSST: false,
      dialogStatusSST: '',
      dialogStatusCheck: '',
      textMap: {
        create: '新增',
        sst: '设备启停'
      },
      dialogPvVisible: false,

      // 新加的列表用的==========================================
      cardTitle: '启停记录',
      dialogFormVisibleCard: false,
      dialogStatusCard: '',
      listLoadingSee: true,
      rowSeeData: {},
      listSee: [],
      totalSee: 0,
      getdataListParmSee: {
        name: 'getAssetSTT1',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          assetId: '',
          startTime: '',
          stopTime: '',
          pastureId: Cookies.get('pastureid')
        }
      },
      // 新加的列表用的==========================================
      // 时间设置
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6
        }
      },

      // 校验规则
      rules: {
        assetName: [{ required: true, message: '必填', trigger: 'remove-tag' }],
        eqCode: [{ required: true, message: '必填', trigger: 'expand-change' }]
      },
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },
  created() {
    this.$store.dispatch('user/getInfo')
    this.getDownList()
    this.getList()
  },

  methods: {
    tableSort(column) {
      sortChange(column, this.listSee)
    },
    // 模糊查询-名称
    formNumberSearch(queryString, cb) {
      this.requestFilterParams.parammaps['eqCode'] = queryString
      this.requestFilterParams.parammaps['assetName'] = ''
      this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
      GetDataByName(this.requestFilterParams).then(response => {
        cb(response.data.list)
      })
    },
    formNameSearch(queryString, cb) {
      this.requestFilterParams.parammaps['eqCode'] = ''
      this.requestFilterParams.parammaps['assetName'] = queryString
      this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
      GetDataByName(this.requestFilterParams).then(response => {
        cb(response.data.list)
      })
    },

    handleformNumberSelect(item) {
      this.temp.assetNumber = item.assetNumber
      this.temp.assetName = item.assetName
      this.temp.eqCode = item.eqCode
      this.temp.eqName = item.eqName
      this.temp.eqCode = item.eqCode
      this.temp.eqName = item.eqName
      this.temp.eqId = item.eqId
      this.temp.id = item.assetId
      this.temp.pastureId = item.pastureId
      this.temp.pastureName = item.pastureName
      this.temp.deptName = item.deptName
      this.temp.deptId = item.deptName
      this.temp.changeStatue = item.changeStatue
      // this.temp.inputDatetime = parseTime(new Date(), '{y}-{m}-{d}')
      // this.temp.inputDatetime = this.temp.inputDatetime
      if (item.sttId === undefined || item.sttId === null) {
        this.temp.sttId = 0
      } else {
        this.temp.sttId = item.sttId
      }
    },

    handleformNameSelect(item) {
      console.log(item)
      this.temp.assetNumber = item.assetNumber
      this.temp.assetName = item.assetName
      this.temp.eqCode = item.eqCode
      this.temp.eqName = item.eqName
      this.temp.id = item.assetId
      this.temp.eqId = item.eqId
      this.temp.pastureId = item.pastureId
      this.temp.pastureName = item.pastureName
      this.temp.deptName = item.deptName
      this.temp.deptId = item.deptName
      this.temp.changeStatue = item.changeStatue
      // this.temp.inputDatetime = parse(new Date(), '{y}-{m}-{d} {h}:{i}')
      // this.temp.inputDatetime = this.temp.inputDatetime
      console.log(item.inputDatetime)
      if (item.sttId === undefined || item.sttId === null) {
        this.temp.sttId = 0
      } else {
        this.temp.sttId = item.sttId
      }
    },
    // 1-1: table&搜索
    getList() {
      this.listLoading = true

      if (this.getdataListParm.parammaps.enabledTime === null) {
        this.getdataListParm.parammaps.enabledTime = ''
      }
      if (this.getdataListParm.parammaps.blockTime === null) {
        this.getdataListParm.parammaps.blockTime = ''
      }
      GetDataByName(this.getdataListParm).then(response => {
        console.log('表格', response.data.list)
        this.list = response.data.list
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            if (response.data.list[i].srcpath !== null && response.data.list[i].picpath !== null && response.data.list[i].srcpath !== undefined && response.data.list[i].picpath !== undefined) {
              this.list[i].srcpath = process.env.VUE_APP_BASE_API + response.data.list[i].srcpath
              this.list[i].picpath = process.env.VUE_APP_BASE_API + response.data.list[i].picpath
            } else {
              this.list[i].srcpath = ''
              this.list[i].picpath = ''
            }
            console.log(this.list[i].srcpath)
          }
        }
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.total = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })

      this.temp = {
        pastureName: '',
        deptName: '',
        deptId: '',
        employeName: '',
        eqName: '',
        assetId: '',
        eqCode: '',
        inputDatetime: new Date(),
        typeName: '',
        assTypeId: '',
        syStatus: '',
        employeId: this.$store.state.user.employeid,
        departmentId: this.$store.state.user.departmentid,
        pastureId: this.$store.state.user.pastureid
      }
    },
    // 2-2：下拉框
    getDownList() {
      GetDataByNames(this.requestParams).then(response => {
        this.findAllProvider = response.data.findAllProvider.list
        this.findAllAssetType = response.data.findAllAssetType.list
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.getDictByName = response.data.getDictByName.list
        this.getDepartDownList()
      })
    },
    getDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.findAllDepart = response.data.list
      })
    },
    changePastureName(item) {
      this.getDepartParam.parammaps.pastureId = this.findAllPasture.find(obj => obj.name == item).id
      this.getdataListParm.parammaps.deptId = ''
      this.getDepartDownList()
    },
    getCreateDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.createDepartList = response.data.list
        if (this.edit == 1) {
          if (this.createDepartList.find(obj => obj.id == Cookies.get('departmentid'))) {
            this.createTemp.departmentId = parseInt(Cookies.get('departmentid'))
            this.createTemp.departmentName = this.createDepartList.find(obj => obj.id == Cookies.get('departmentid')).name
          } else {
            this.createTemp.departmentId = response.data.list[0].id
            this.createTemp.departmentName = response.data.list[0].name
          }
          console.log(this.createTemp.departmentName, 'this.createTemp.departmentName')
        }
      })
    },
    changePasture(item) {
      this.getDepartParam.parammaps.pastureId = item
      this.edit = 1
      this.getCreateDepartDownList()
    },
    changeDepart(item) {
      this.createTemp.departmentName = this.createDepartList.find(obj => obj.id == item).name
    },
    form_search() {
      this.listLoading = true
      this.getdataListParm.offset = 1
      this.getList()
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    },

    form_reset() {
      this.temp = {
        pastureName: '',
        deptName: '',
        deptId: '',
        employeName: '',
        eqName: '',
        assetId: '',
        eqCode: '',
        inputDatetime: new Date(),
        typeName: '',
        assTypeId: '',
        syStatus: '',
        employeId: parseInt(Cookies.get('employeid')),
        departmentId: parseInt(Cookies.get('departmentid')),
        pastureId: parseInt(Cookies.get('pastureid'))
      }
    },
    form_edit(row) {
      this.temp = Object.assign({}, row) // copy obj
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },

    form_add() {
      this.form_reset()
      this.edit = 1
      this.getDepartParam.parammaps.pastureId = this.temp.pastureId
      this.getCreateDepartDownList()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },
    // 设备启停按钮
    handleSST(row) {
      // console.log(1)
      this.dialogStatusSST = 'sst'
      this.dialogFormVisibleSST = true
      this.tempSST = Object.assign({}, row)
      console.log(this.tempSST)
    },

    // 启用
    add_dialog_saveSST1() {
      console.log(this.tempSST)
      var sendData = {
        name: 'updateEQStartStop',
        parammaps: {
          SSPstatue: '启用',
          id: this.tempSST.id,
          sttId: this.tempSST.sttId1,
          employeId: Cookies.get('employeid'),
          pastureId: this.tempSST.pastureId
        }
      }
      PostDataByName(sendData).then(response => {
        console.log(response)
        if (response.msg === 'fail') {
          this.$notify({
            title: '失败',
            message: '保存失败-' + response.data,
            type: 'warning',
            duration: 2000
          })
        } else {
          this.getList()
          this.dialogFormVisibleSST = false
          this.$notify({
            title: '成功',
            message: '修改成功',
            type: 'success',
            duration: 2000
          })
        }
      })
    },
    add_dialog_saveSST2() {
      console.log(this.tempSST)
      var sendData = {
        name: 'updateEQStartStop',
        parammaps: {
          SSPstatue: '停用',
          id: this.tempSST.id,
          sttId: this.tempSST.sttId1,
          employeId: Cookies.get('employeid'),
          pastureId: this.tempSST.pastureId
        }
      }
      PostDataByName(sendData).then(response => {
        console.log(response)
        if (response.msg === 'fail') {
          this.$notify({
            title: '失败',
            message: '保存失败-' + response.data,
            type: 'warning',
            duration: 2000
          })
        } else {
          this.getList()
          this.dialogFormVisibleSST = false
          this.$notify({
            title: '成功',
            message: '修改成功',
            type: 'success',
            duration: 2000
          })
        }
      })
    },

    add_dialog_saveSST() {
      this.requestParamSST.parammaps.id = this.tempSST.id
      this.requestParamSST.parammaps.pastureId = this.tempSST.pastureId
      this.requestParamSST.parammaps.sttId = this.tempSST.sttId
      this.requestParamSST.parammaps.changeStatue = this.tempSST.changeStatue
      PostDataByName(this.requestParamSST).then(response => {
        console.log(response)
        if (response.msg === 'fail') {
          this.$notify({
            title: '失败',
            message: '保存失败-' + response.data,
            type: 'warning',
            duration: 2000
          })
        } else {
          this.getList()
          this.dialogFormVisibleSST = false

          this.$notify({
            title: '成功',
            message: '修改成功',
            type: 'success',
            duration: 2000
          })
        }
      })
    },
    // 启用
    // createStartData() {
    //   this.$refs['temp'].validate(valid => {
    //     if (valid) {
    //       if (this.temp.changeStatue === '停用') {
    //         this.postDataPramas.common = { 'returnmap': '0' }
    //         this.postDataPramas.data = []
    //         this.postDataPramas.data[0] = { 'name': 'updateByIdEnabled', 'type': 'e', 'parammaps': { }}
    //         this.postDataPramas.data[0].parammaps = this.temp

    //         this.postDataPramas.data[1] = { 'name': 'insertSTT', 'type': 'e', 'parammaps': { }}
    //         this.postDataPramas.data[1].parammaps.inputDatetime = this.temp.inputDatetime
    //         this.postDataPramas.data[1].parammaps.employeId = this.temp.employeId
    //         this.postDataPramas.data[1].parammaps.id = this.temp.id
    //         this.postDataPramas.data[1].parammaps.pastureId = this.temp.pastureId

    //         this.postDataPramas.data[2] = { 'name': 'updateByIdAsset', 'type': 'e', 'parammaps': { }}
    //         this.postDataPramas.data[2].parammaps.sttId = '@insertSTT.LastInsertId'
    //         this.postDataPramas.data[2].parammaps.id = this.temp.id
    //         this.postDataPramas.data[2].parammaps.pastureId = this.temp.pastureId

    //         ExecDataByConfig(this.postDataPramas).then(response => {
    //           if (response.msg === 'fail') {
    //             this.$notify({
    //               title: '变更失败',
    //               message: response.data,
    //               type: 'warning',
    //               duration: 2000
    //             })
    //           } else {
    //             this.getList()
    //             this.dialogFormVisible = false
    //             this.$notify({
    //               title: '',
    //               message: '变更成功',
    //               type: 'success',
    //               duration: 2000
    //             })
    //           }
    //         })
    //       } else {
    //         this.$notify({
    //           title: '',
    //           message: '设备启用中，必须先停止才能再次启用',
    //           type: 'warning',
    //           duration: 2000
    //         })
    //       }
    //     }
    //   })
    // },
    createStartData() {
      this.$refs['temp'].validate(valid => {
        if (valid) {
          console.log(this.temp)
          var sendData = {
            name: 'updateEQStartStop',
            parammaps: {
              SSPstatue: '启用',
              sttId: this.temp.sttId,
              id: this.temp.eqId,
              employeId: Cookies.get('employeid'),
              pastureId: this.temp.pastureId
            }
          }
          PostDataByName(sendData).then(response => {
            console.log(response)
            if (response.msg === 'fail') {
              this.$notify({
                title: '失败',
                message: '保存失败-' + response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getList()
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },

    // 停用
    // createStopData() {
    //   this.$refs['temp'].validate(valid => {
    //     if (valid) {
    //       if (this.temp.changeStatue === '启用') {
    //         this.postDataPramas.common = { 'returnmap': '0' }
    //         this.postDataPramas.data = []
    //         this.postDataPramas.data[0] = { 'name': 'updateByIdBlock', 'type': 'e', 'parammaps': { }}
    //         this.postDataPramas.data[0].parammaps = this.temp

    //         this.postDataPramas.data[1] = { 'name': 'updateSTT', 'type': 'e', 'parammaps': { }}
    //         this.postDataPramas.data[1].parammaps.inputDatetime = this.temp.inputDatetime
    //         this.postDataPramas.data[1].parammaps.employeId = this.temp.employeId
    //         this.postDataPramas.data[1].parammaps.id = this.temp.sttId
    //         this.postDataPramas.data[1].parammaps.pastureId = this.temp.pastureId

    //         ExecDataByConfig(this.postDataPramas).then(response => {
    //           if (response.msg === 'fail') {
    //             this.$notify({
    //               title: '变更失败',
    //               message: response.data,
    //               type: 'warning',
    //               duration: 2000
    //             })
    //           } else {
    //             this.getList()
    //             this.dialogFormVisible = false
    //             this.$notify({
    //               title: '',
    //               message: '变更成功',
    //               type: 'success',
    //               duration: 2000
    //             })
    //           }
    //         })
    //       } else {
    //         this.$notify({
    //           title: '',
    //           message: '设备停止中，必须先启用才能停止使用',
    //           type: 'warning',
    //           duration: 2000
    //         })
    //       }
    //     }
    //   })
    // },
    createStopData() {
      this.$refs['temp'].validate(valid => {
        if (valid) {
          console.log(this.temp)
          var sendData = {
            name: 'updateEQStartStop',
            parammaps: {
              SSPstatue: '停用',
              sttId: this.temp.sttId,
              id: this.temp.eqId,
              employeId: Cookies.get('employeid'),
              pastureId: this.temp.pastureId
            }
          }
          PostDataByName(sendData).then(response => {
            console.log(response)
            if (response.msg === 'fail') {
              this.$notify({
                title: '失败',
                message: '保存失败-' + response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getList()
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },

    form_see(row) {
      this.rowSeeData = Object.assign({}, row)
      this.cardTitle = '启停记录  设备名称：' + row.eqName + '设备编号：' + row.eqCode
      this.dialogFormVisibleCard = true
      this.getdataListParmSee.parammaps.assetId = row.id
      this.getListSee()
    },
    form_searchDelivery() {
      if (this.getdataListParmSee.parammaps.inputDatetime === null) {
        this.getdataListParmSee.parammaps.inputDatetime = ''
      }
      this.getdataListParmSee.offset = 1
      this.getListSee()
    },
    getListSee() {
      if (this.getdataListParmSee.parammaps.startTime !== undefined && this.getdataListParmSee.parammaps.startTime !== null) {

      } else {
        this.getdataListParmSee.parammaps.startTime = ''
      }
      if (this.getdataListParmSee.parammaps.stopTime !== undefined && this.getdataListParmSee.parammaps.stopTime !== null) {

      } else {
        this.getdataListParmSee.parammaps.stopTime = ''
      }

      GetDataByName(this.getdataListParmSee).then(response => {
        this.listSee = response.data.list
        console.log('记录列表数据', response.data.list)
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.totalSee = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingSee = false
        }, 300)
      })
    }

  }
}
</script>
