<template >
  <div class="span">
    <criteria-paged :model="model" v-ref:paged >
      <criteria partial='criteria' v-ref:criteria  @condition-changed='$parent.search'>
        <div novalidate class=" select-overspread container-fluid auto" partial>

            <div class="col-sm-4">
              <label class="font_normal_body">标记名称</label>
              <v-select :value.sync="model.f_parameter_name" v-model="model.f_parameter_name"
                        placeholder='标记名称'
                        style="width: 60%"
                        :options='$parent.$parent.signtype1'
                        close-on-select multiple
                        condition="f_parameter_name in {}"></v-select>
            </div>
            <div class="col-sm-4" >
              <label class="font_normal_body" >标记时间</label>
              <datepicker style="width: 60%" placeholder="起始时间"
                          :value.sync="model.f_start_date"
                          v-model="model.f_start_date"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          condition="f_parameter_date > '{}'"
              ></datepicker>
            </div>
          <div class="col-sm-4 " >
              <label class="font_normal_body">&nbsp;至</label>
              <!--&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;-->
              <datepicker style="width: 60%" placeholder="结束时间"
                          :value.sync="model.f_end_date"
                          v-model="model.f_end_date"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          condition="f_parameter_date < '{}'"
              ></datepicker>
          </div>
          <div class="col-sm-4">
            <label class="font_normal_body">处理状态</label>
            <v-select :value.sync="model.f_parameter_state" v-model="model.f_parameter_state"
                      placeholder='处理状态'
                      style="width: 60%"
                      :options='$parent.$parent.signstate1'
                      close-on-select
                      condition="f_parameter_state='{}'"
            ></v-select>
          </div>
          <div class="span" style="float:right;">
              <button class="button_search" @click="search()" v-el:cba>查询</button>
            </div>
        </div>

      </criteria>
      <data-grid  partial='list' v-ref:grid :model="model" class="list_area table_sy">
        <template partial='head'>
          <tr >
            <th style="text-align:center;"><nobr>序号</nobr></th>
            <!--<th style="text-align:center;"><nobr>标记类型</nobr></th>-->
            <th style="text-align:center;"><nobr>标记名称</nobr></th>
            <!--<th style="text-align:center;"><nobr>标记值</nobr></th>-->
            <th style="text-align:center;"><nobr>操作人</nobr></th>
            <th style="text-align:center;"><nobr>操作时间</nobr></th>
            <th style="text-align:center;"><nobr>备注</nobr></th>
            <th style="text-align:center;"><nobr>状态</nobr></th>
            <th style="text-align:center;"><nobr>操作</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center;"><nobr>{{$index+1}}</nobr></td>
            <!--<td style="text-align:center;"><nobr>{{row.f_parameter_type}}</nobr></td>-->
            <td style="text-align:center;"><nobr>{{row.f_parameter_name}}</nobr></td>
            <!--<td style="text-align:center;"><nobr>{{row.f_parameter_value}}</nobr></td>-->
            <td style="text-align:center;"><nobr>{{row.f_operator}}</nobr></td>
            <td style="text-align:center;"><nobr>{{row.f_parameter_date}}</nobr></td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '已处理' || row.f_parameter_state === '待处理'">
              <nobr>标记原因:{{row.f_beizhu}}</nobr>
            </td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '-处理-'">
              <nobr>撤销原因:{{row.f_beizhu}}</nobr>
            </td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '待处理'">
                <nobr>
                <span >待处理</span>
              </nobr>
            </td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '已处理'">
                <nobr>
                <span >已处理</span>
                </nobr></td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '-处理-'">
                <nobr>
              <span >-处理-</span>
              </nobr>
            </td>

            <td style="text-align:center;" v-if="row.f_parameter_state === '待处理'"><nobr>
              <span ><a href="#" @click.stop="$parent.$parent.$parent.backSend(row)" >处理</a></span>
            </nobr></td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '已处理'">

            </td>
            <td style="text-align:center;" v-if="row.f_parameter_state === '-处理-'">
              <span >处理完成</span>
            </td>
          </tr>
        </template>
      </data-grid>
    </criteria-paged>
    <modal :show.sync="handcental" v-ref:modal backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="close()"><span>&times;</span></button>
        <h4 class="modal-title">提醒</h4>
      </header>
      <article slot="modal-body" class="modal-body" >
        <label class="font_normal_body">撤销原因</label>
        <textarea name="name" rows="2" style="width: 100%"
                  placeholder='撤销原因'
                  class="ver-textarea" class="form-control"
                  v-model='cancelreason'></textarea>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button v-show="handcental" type="button" class="btn btn-default" @click='close()'>取消</button>
        <button v-show="handcental" type="button" class="button_search" @click='confirmcenta()'>确认</button>
      </footer>
    </modal>
  </div>

</template>

<script>
  import {PagedList} from 'vue-client'
  import Vue from 'vue'
  export default {
    title: '标记信息',
    name: 'SignParameter',
    props: {
      meternumberf: '',
      f_meterNumber: '',
      searchobj: {},
      isdeal: {},
      tablename: {
        type: String,
        default: 't_userparameter'
      },
      orderitem: {
        type: String,
        default: 'id'
      },
      items: {
        type: String,
        default: '*'
      }
    },
    data () {
      return {
        handcental: false,
        cancelid: '',
        cancelreason: '',
        cancelrow: null,
        f_user_id: '',
        model: new PagedList('rs/sql/singleTable_OrderBy', 30, {tablename: "'" + this.tablename + "'",
          orderitem: "'" + this.orderitem + "'",
          items: "'" + this.items + "'"}),
        row: null,
        searchshow: false,
        obj: {
          userid: this.$login.f.id,
          source: `tool.getFullTree(this.getRights().where(row.getType() == $organization$))`,
          res: this.$login.f.f_fengongsi,
          resids: this.$login.f.f_orgids
        },
        show: false,
        isdeal: true
      }
    },

    ready () {
      this.$refs.paged.$refs.criteria.search()
    },
    watch: {
      'searchobj' (val) {
        console.log('f_user_id8:', val.f_user_id)
        this.f_user_id = val.f_user_id
        if (this.searchobj != null) {
          this.$refs.paged.$refs.criteria.model.f_meternumber = this.searchobj.f_meternumber
          this.$refs.paged.$refs.criteria.search()
        }
      },
      'meternumberf' (val) {
        this.meternumberf = val
        if (this.meternumberf != null) {
          this.$refs.paged.$refs.criteria.model.f_meternumber = this.meternumberf
          this.$refs.paged.$refs.criteria.search()
        }
      }
    },
    methods: {
      clickshow () {
        this.searchshow = !this.searchshow
      },
      backSend (megrow) {
        if (megrow) {
          this.handcental = true
          this.cancelid = megrow.id
          this.cancelrow = megrow
        } else {
          this.$showAlert('操作失败！。', 'warning', 3000)
        }
      },
      confirmcenta () {
        let send = {
          id: this.cancelid,                      // 当前记录ID
          f_parameter_state: '已处理',         // 撤销人id
          f_operator: this.$login.f.name        // 撤销人姓名
        }
        let param = {
          tablename: 't_userparameter',
          id: 1,
          basedata: send
        }
        this.$resetpost('rs/logic/iot_saveTable', param).then(() => {
          this.writeForUserPara()
          this.handcental = false
          this.$refs.paged.$refs.criteria.search()
        })
      },
        // 写入用户标记表
      writeForUserPara () {
        let send = {
          f_meternumber: this.cancelrow.f_meternumber,
          f_parameter_state: '-处理-',
          f_operator: Vue.$login.f.name,
          f_parameter_type: '自定义参数',
          f_parameter_name: this.cancelrow.f_parameter_name,
          f_beizhu: this.cancelreason,
          f_filiale: this.cancelrow.f_filiale,
          f_filialeids: this.cancelrow.f_filialeids,
          f_outlets: this.cancelrow.f_outlets,
          f_orgstr: this.cancelrow.f_orgstr
        }
        let param = {
          tablename: 't_userparameter',
          id: 1,
          basedata: send
        }
        this.$resetpost('rs/logic/iot_saveTable', param).then(() => {
          this.cancelreason = ''
          this.$refs.paged.$refs.criteria.search()
        })
      },
      close () {
        this.cancelreason = ''
        this.handcental = false
      },
      search () {
        this.obj.resids = this.obj.resids
        this.condition = `${this.$refs.paged.$refs.criteria.condition} and f_meternumber ='${this.meternumberf} ' and f_user_id='${this.f_user_id}'`
        this.model.search(this.condition, this.model)
      },
      getRes (obj) {
        this.obj.res = obj.res
        this.obj.resids = obj.resids
      }
    },
    computed: {
      signtype1 () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('标记名称')]
      },
      signstate1 () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('处理状态')]
      }
    }
  }
</script>
<style>
  .form-input-group label {
    text-align: right;
    width: auto;
  }
</style>
