<template>
  <div v-if="visible">
    <el-dialog
      id="reviseplanDialog"
      :title="title"
      :fullscreen="dialogFull"
      :destroy-on-close="true"
      :visible.sync="visible"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      :append-to-body="true"
      :before-close="closeDialog"
      width="90%"
    >
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span
              style="
                display: inline-block;
                width: 3px;
                height: 20px;
                margin-right: 5px;
                float: left;
                margin-top: 2px;
              "
            />
            {{ title }}
          </span>
          <div
            class="avue-crud__dialog__menu"
            @click="dialogFull ? (dialogFull = false) : (dialogFull = true)"
          >
            <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
            <svg-icon v-else icon-class="fullscreen" />
          </div>
        </div>
      </template>
      <el-row class="dialogMinHeight">
        <el-button
          class="successBorder"
          size="medium"
          style="position: absolute; z-index: 1; right: 2px; top: 2px"
          @click="saveData()"
          >{{ $t('message.msg304') }}</el-button
        >
        <el-tabs
          v-model="parentActiveName"
          type="border-card"
          @tab-click="handleClick"
        >
          <el-tab-pane :label="$t('message.msg305')" name="栏舍配方">
            <DhedFormula ref="DhedFormula" :parent-date="date" />
          </el-tab-pane>
          <el-tab-pane :label="$t('message.msg306')" name="撒料计划">
            <MaterialIssuancePlan
              ref="MaterialIssuancePlan"
              :parent-date="date"
            />
          </el-tab-pane>
          <el-tab-pane :label="$t('message.msg307')" name="预混计划">
            <PremixedPlan ref="PremixedPlan" :parent-date="date" />
          </el-tab-pane>
          <el-tab-pane :label="$t('message.msg308')" name="剩料计划">
            <SurplusMaterialPlan
              ref="SurplusMaterialPlan"
              :parent-date="date"
            />
          </el-tab-pane>
        </el-tabs>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelClose cancelClose1" @click="closeDialog()">{{
          $t('common.closed')
        }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { PostDataByName } from '@/api/common'
import DhedFormula from './typePage/dhedFormula.vue'
import MaterialIssuancePlan from './typePage/materialIssuancePlan.vue'
import PremixedPlan from './typePage/premixedPlan.vue'
import SurplusMaterialPlan from './typePage/surplusMaterialPlan.vue'
import { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
export default {
  name: 'RevisePlan',
  components: {
    DhedFormula,
    MaterialIssuancePlan,
    PremixedPlan,
    SurplusMaterialPlan
  },
  props: {
    show: { type: Boolean, default: false }, // 弹框可见标志
    parentActiveName: { type: String, defalut: '' },
    parentDate: { type: String, defalut: '' }
  },
  data() {
    return {
      dialogFull: false,
      typeList: [
        { id: '1', effect: 'dark', label: this.$t('dailyExecutionPlan.lspf') },
        { id: '2', effect: 'plain', label: this.$t('message.msg306') },
        { id: '3', effect: 'plain', label: this.$t('message.msg307') }
      ],
      visible: this.show,
      dialogFormVisible: false,
      dialogStatus: '',
      rules: {},
      date: '',
      // parentActiveName: '',
      temp: {},
      title: '',
      isDhedFormula: true,
      isMaterialIssuancePlan: false,
      isPremixedPlan: false,

      textMap: {
        revisePlan: this.$t('message.msg220')
      },
      isokDisable: false,
      requestParam: {}
    }
  },
  watch: {
    // 监听show,visible 随着show变化而变化
    show: {
      immediate: true,
      handler(show) {
        this.visible = show
      }
    },
    parentDate: {
      immediate: true,
      handler(newVal, oldVal) {
        console.log('newVal-date', newVal)
        this.date = newVal
        this.title = this.$t('message.msg220') + this.date
      }
    },
    parentActiveName: {
      immediate: true,
      handler(newVal, oldVal) {
        console.log('newVal===', newVal)
        console.log('oldVal', oldVal)
        this.parentActiveName = newVal
      }
    }
  },
  created() {},
  methods: {
    closeDialog() {
      this.dialogFull = false
      this.$emit('update:show', false) // 子组件更新弹框隐藏
      this.$emit('activeName', '栏舍配方')
    },
    saveData() {
      console.log('点击了应用')
      MessageBox.confirm(this.$t('message.msg309') + this.date, {
        confirmButtonText: this.$t('common.confirm'),
        cancelButtonText: this.$t('common.cancel'),
        type: 'warning'
      })
        .then(() => {
          this.requestParam.name = 'updatedownloadedplanDone'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.pastureid = Cookies.get('pastureid')
          this.requestParam.parammaps.date = this.date
          PostDataByName(this.requestParam).then((response) => {
            if (response.msg === 'fail') {
              this.$notify({
                title: this.$t('driver.saveFail'),
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.$notify({
                title: this.$t('common.succes'),
                message: this.$t('driver.saveSuccess'),
                type: 'success',
                duration: 2000
              })
              this.closeDialog()
              this.$parent.getList()
            }
          })
        })
        .catch(() => {
          this.$message({ type: 'info', message: this.$t('message.msg41') })
        })
    },
    handleClick(item) {
      console.log(item.name)
      if (item.name == this.$t('message.msg306')) {
        this.$refs.MaterialIssuancePlan.getButtons()
        this.$refs.MaterialIssuancePlan.getIsDisplay()
        this.$refs.MaterialIssuancePlan.getList()
      } else if (item.name == '栏舍配方') {
        this.$refs.DhedFormula.getIsDisplay()
        this.$refs.DhedFormula.getDownList()
      } else if (item.name == '栏舍配方') {
        this.$refs.PremixedPlan.getDownList()
        this.$refs.PremixedPlan.getIsDisplay()
        this.$refs.PremixedPlan.getList()
      } else if (item.name == '剩料计划') {
        this.$refs.SurplusMaterialPlan.getButtons()
        this.$refs.SurplusMaterialPlan.getDownList()
        this.$refs.SurplusMaterialPlan.getIsDisplay()
        this.$refs.SurplusMaterialPlan.getList()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
// #reviseplanDialog {
//    margin-top: -10vh !important
// }
</style>
