<template>
  <div class="span">
    <validator name='v'>
      <p class="bg-info text-center" style="padding: 8px;" v-if="operation=='add'">添加安检周期</p>
      <p class="bg-info text-center" style="padding: 8px;" v-if="operation=='modify'">修改安检周期</p>
      <div class="auto select-overspread form-horizontal">
        <div style="text-align:right;margin-top:6px;" class="col-sm-12">
          <div  class="row">
            <div class="col-sm-6 form-group "
                 :class="[$v.f_circle.required ? 'has-error' : 'has-success']">
              <label class="font_normal_body">安检周期</label>
                <input type="text" v-show="false"  v-model="circlemodel.f_circle"
                       v-validate:f_circle='{required: true }'>
                <v-select
                  :value.sync="circlemodel.f_circle" :value-single="true"
                  :options='clirclelist' placeholder='请选择安检周期'
                  close-on-select  >
                </v-select>
            </div>
            <div class="col-sm-6 form-group "
                 :class="[$v.f_start_time.required ? 'has-error' : 'has-success']">
              <label class="font_normal_body">开始日期</label>
                <input type="text" v-show="false" v-model="circlemodel.f_start_time"
                       class="input_search" style="width:60%" placeholder="街道名称"
                       v-validate:f_start_time='{required: true }'>
              <datepicker  placeholder="开始日期"
                          v-model="circlemodel.f_start_time"
                          :value.sync="circlemodel.f_start_time"
                          style="width: 60%;"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-01-01 00:00:00'"
                        >
              </datepicker>
            </div>
            <div class="col-sm-12 form-group">
              <label  class="font_normal_body " style="">备&emsp;&emsp;注</label>
              <textarea class="input_textarea" rows="3" style="margin-top:25px;width:80%;height: auto;" v-model="circlemodel.f_remarks"></textarea>
            </div>
          </div>
          <div class="row">
          <div style="margin-top:40px;text-align:right;">
            <button class="button_search button_spacing" @click="confirm()" :disabled='!$v.valid'>保存</button>
            <button class="button_clear button_spacing" @click="cancel()">取消</button>
          </div>
          </div>
        </div>
      </div>
    </validator>
  </div>
</template>

<script>
  export default {
    title: '安检周期添加',
    data () {
      return {
        //初始化周期数据
        clirclelist:this.$appdata.getParam('安检周期'),
        //街道
        circlemodel: {
          f_circle:'',
          f_start_time:'',
          f_remarks: ''
        }
      }
    },
    props: ['f_filialeids','row','operation','f_filiale'],
    ready(){

    },
    methods: {
      //保存
      async confirm(){
        await this.savestreet()
        this.cleardara()
        this.$dispatch('confirm')
      },
      //保存街道
      async savestreet(){
        if(this.operation == 'add'){
          this.circlemodel.f_filialeid = this.f_filialeids
          this.circlemodel.f_filiale = this.f_filiale
        }
        this.circlemodel.f_operator= this.$login.f.name
        this.circlemodel.f_operatorid = this.$login.f.id
        this.circlemodel.f_orgid = this.$login.f.orgid
        this.circlemodel.f_orgname = this.$login.f.orgs
        //tag
        await this.$resetpost('rs/logic/safe_savecircle', this.circlemodel)
      },
      cancel(){
        this.cleardara()
        this.$dispatch('cancel')
      },
      cleardara () {
        this.circlemodel = {
          f_circle: '',
          f_start_time: '',
          f_remarks:''
        }
      }

    },
    watch: {
      'f_filialeids'(){
        if (this.circlemodel.f_filialeid) {
          if (this.circlemodel.f_filialeid != this.f_filialeids) {
            this.$dispatch('cancel')
          }
        }
      }
    }
  }
</script>
