<template>
  <div class="border-style">
    <div class="inner-style">
      <div class="white-border" />
      <div class="align-center">
        <div class="name">{{ name }}</div>
        <div v-if="num" class="storage">{{ num }}</div>
        <div class="statement">{{ statement }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { fireStore, mtStore} from '@/api/equipment'
export default {
  name: 'SubTitle',
  props: ['name', 'statement', 'num', 'step'],
  data() {
    var checkcurrentStore = (rule, value, callback) => {
      if (!value) {
        return callback(new Error(`请选择${this.dialogType === 'check' ? '检修仓' : '故障仓'}`))
      } else {
        callback()
      }
    }
    var checktargetStore = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请选择目标仓位'))
      } else if (value === this.StoreForm.currentStore) {
        callback(new Error(`${this.dialogType === 'check' ? '检修仓' : '故障仓'}不可与目标仓位重名`))
      } else {
        callback()
      }
    }
    return {
      dialogType: 'fire',
      dialogStoreVisible: false,
      dialogCarLock:false,
      StoreForm: {
        currentStore: null,
        targetStore: null
      },
      rules: {
        currentStore: [
          { validator: checkcurrentStore, trigger: 'blur' }
        ],
        targetStore: [
          { validator: checktargetStore, trigger: 'blur' }
        ]
      },
      formLabelWidth: '120px',
      StoreCodeList: null,
      loading:false,
    }
  },
  mounted() {

  },
  methods: {
    // 手动发起换电
    changePower() {
      this.loading=true
      this.$confirm('请确认站控系统手动发起换电？', '开始换电', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          const res = await beginSwap()
          if(res.code === 0){
              this.$message({
              type: 'success',
              message: res.data,
            })
          }else{
              this.$message({
              type: 'warning',
              message: res.msg,
            })
          }
          this.loading=false
        })
        .catch(err => { console.error(err) })
    },
    ResetStationControl(){
      this.loading=true
      this.$confirm('请确认是否复位站控系统？', '单步执行', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          // const res = await beginSwap()
          // this.$message({
          //   type: 'success',
          //   message: '后端接口数据为空',
          // })
          // this.loading=false
        })
        .catch(err => { console.error(err) })
    },
    CheckStoreHouse() {
      this.dialogType = 'check'
      this.dialogStoreVisible = true
    },
    FireControlStoreHouse() {
      this.dialogType = 'fire'
      this.dialogStoreVisible = true
    },
    //车辆解锁上锁
    CheckCarOnLock(){
      this.dialogCarLock = true
    },
    // 检修换仓、消防换仓下发指令
    ChangeStore(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          const params = this.StoreForm
          this.loading=true;
          // 检修换仓
          if (this.dialogType === 'check') {
            mtStore(params).then(res => {
              if (res) {
                this.loading = false
                this.dialogStoreVisible = false
                this.$message({
                  type: 'success',
                  message: res.data,
                })
                this.resetForm()
              } else {
                this.loading = false
                this.dialogStoreVisible = false
                this.resetForm()
              }
            })
          }
          // 消防换仓
          else {
            fireStore(params).then(res => {
              if (res) {
                this.loading = false
                this.dialogStoreVisible = false
                this.$message({
                  type: 'success',
                  message: res.data,
                })
                this.resetForm()
              } else {
                this.loading = false
                this.dialogStoreVisible = false
                this.resetForm()
              }
            })
          }
        }
      })
    },
    // 清空下拉仓位
    resetForm() {
      this.StoreForm.currentStore = null
      this.StoreForm.targetStore = null
    }
  }
}
</script>

<style scoped>
.border-style {
  border: 2px solid rgb(25, 34, 51);
  border-left: none;
  border-right: none;
  padding: 2px;
}

.inner-style {
  background: #121a29;
  padding: 3px;
  display: flex;
  height: 32px;
  flex-direction: row;
}

.white-border {
  width: 28px;
  height: 18px;
  background-image: url("../assets/ico2.png");
  background-size: 100% 100%;
}

.align-center {
  display: flex;
  flex-direction: row;
  margin: 0 5px;
  align-items: center;
}

.name {
  color: white;
  font-size: 20px;
  font-weight: 600;
  text-shadow: 0 0 3px #1753ce, 0 0 4px #1753ce, 0 0 3px #1753ce, 0 0 3px #1753ce;
  margin-left: -4.2%;
}

.storage {
  background: #192b7d;
  width: 20px;
  height: 20px;
  color: white;
  font-size: 16px;
  font-weight: 600;
  border-radius: 50%;
  text-indent: 6px;
  line-height: 22px;
  margin-left: 3px;
}

.statement {
  color: #324264;
  font-size: 12px;
  margin: 0 8px;
  font-weight: 600;
  padding-top: 9px;
}

.exchange-store {
  flex: 1;
  height: 32px;
  position: relative;
  bottom: 3px;
  display: flex;
  justify-content: flex-end;
}

.store-list {
  padding: 0 12px;
  height: 32px;
  text-align: center;
  line-height: 32px;
  border: #414a63 solid 1px;
  color: #84988c;
  font-size: 14px;
  font-weight: 600;
  margin-right: 15px;
  cursor: pointer;
}

.active {
  border: #91fdb9 solid 1px;
  color: #91fdb9;
}
.top{
  border-top: none;
}
</style>
