<template>
  <criteria-paged :model="model" v-ref:paged>
    <criteria partial='criteria' v-ref:criteria @condition-changed='$parent.selfSearch'>
      <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
        <div class="row">
          <div class="col-sm-4 form-group">
            <role-selector-safe
              role-name="安检员"
              role-lable="安&nbsp;检&nbsp;员&nbsp;"
              @re-res="$parent.$parent.getRes"
              :value.sync="model.f_checker_name"
              v-model="model.f_checker_name"
              condition="f_checker_name = '{}'">
            </role-selector-safe>
          </div>
          <div class="col-sm-2 form-group">
            <label class="font_normal_body">处理状态</label>
            <v-select v-model="model.f_orderstate" style="width:60%"
                      placeholder='处理状态'
                      :value.sync="model.f_orderstate"
                      :options='$parent.$parent.getState'
                      condition= "f_orderstate like '%{}%'"
                      close-on-select value-single>
            </v-select>
          </div>
          <div class="col-sm-2 form-group">
            <label class="font_normal_body">安检项</label>
            <input type="text" class="input_search"
                   style="width:60%"
                   v-model="model.f_device_type"
                   condition="f_device_type like '%{}%'"
                   placeholder="安检项"/>
          </div>
          <div class="form-group col-sm-2">
            <label class="font_normal_body">区域</label>
            <v-select class="select_list select"
                      placeholder='请选择' style="width: 60%"
                      :value.sync="model.f_pcd" v-model="model.f_pcd"
                      :options='$parent.$parent.pcds'
                      filer-key="name"
                      close-on-select clear-button
                      condition="f_pcd='{}'"
                      :value-single="true">
            </v-select>
          </div>
          <div class="span col-sm-2 form-group button-range" style="float: right">
            <button class="button_search button_spacing" @click="search()" v-el:cx>查询</button>
            <button class="button_clear button_spacing" @click="clear">清空</button>
            <div style="float: right" class="button_spacing" :class="{'button_shrink_top': criteriaShow,'button_shrink_bottom': !criteriaShow}" @click="criteriaShow = !criteriaShow"></div>
            <div style="float: right" class="button_spacing"
            :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
            @click="$parent.$parent.hiddenr()"></div>
          </div>
          <div class="row" v-show="criteriaShow">
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">用户姓名</label>
              <input type="text" class="input_search"
                     style="width:60%"
                     v-model="model.f_user_name"
                     condition="f_user_name like '%{}%'"
                     placeholder="用户姓名"/>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search"
                     style="width:60%"
                     v-model="model.f_userinfo_code"
                     condition="f_userinfo_code = '{}'"
                     placeholder="用户编号"/>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">网&ensp;格&ensp;员</label>
              <v-select class="select_list select"
                        placeholder='请选择' style="width: 60%"
                        :value.sync="model.f_book_checker" v-model="model.f_book_checker"
                        :options='$parent.$parent.users'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_book_checker like '%{}%' and f_checker_name = '{}'"
                        :value-single="true">
              </v-select>
            </div>
          </div>
        </div>
      </div>
    </criteria>
    <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
      <template partial='head'>
        <tr>
          <th><nobr>用户编号</nobr></th>
          <th><nobr>用户姓名</nobr></th>
          <!--<th><nobr>联&ensp;系&ensp;人</nobr></th>-->
          <!--            <th>用户表号</th>-->
          <th><nobr>联系电话</nobr></th>
          <th><nobr>详细地址</nobr></th>
          <th><nobr>备注信息</nobr></th>
          <th><nobr>整改时间</nobr></th>
          <th><nobr>安检人</nobr></th>
          <th><nobr>隐患名称</nobr></th>
          <th><nobr>安检时间</nobr></th>
          <th><nobr>处理状态</nobr></th>
          <th><nobr>处&ensp;理&ensp;人</nobr></th>
          <th><nobr>处理时间</nobr></th>
          <th><nobr>处理意见</nobr></th>
        </tr>
      </template>
      <template partial='body'>
        <tr>
          <td style="text-align:center">{{row.f_userinfo_code}}</td>
          <td style="text-align:center">{{row.f_user_name}}</td>
          <!--<td style="text-align:center">{{row.f_contact}}</td>-->
          <!--            <td style="text-align:center">{{row.f_meternumber}}</td>-->
          <td style="text-align:center">{{row.f_user_phone}}</td>
          <td style="text-align:center">{{row.f_user_address}}</td>
          <td style="text-align:center">{{row.f_orderremark}}</td>
          <td style="text-align:center">{{row.f_orderdate}}</td>
          <td style="text-align:center">{{row.f_checker_name}}</td>
          <td style="text-align:center">{{row.f_item_name}}</td>
          <td style="text-align:center">{{row.f_onsite_time}}</td>
          <td style="text-align:center" v-if="row.f_orderstate === '待处理'">{{ row.f_orderstate }}</td>
          <td style="text-align:center" v-if="row.f_orderstate === '预约成功'">{{ '审核通过' }}</td>
          <td style="text-align:center" v-if="row.f_orderstate === '预约失败'">{{ '审核未通过' }}</td>
          <td style="text-align:center">{{row.f_dispose_operator || '***'}}</td>
          <td style="text-align:center">{{row.f_disposedate || '*** *** ***'}}</td>
          <td style="text-align:center;cursor: pointer;">
            <button type="button" name="button" class="btn btn-link" @click="$parent.$parent.$parent.showSuggest(row.f_suggest)">点击查看</button>
          </td>
        </tr>
      </template>
      <template partial='foot'></template>
    </data-grid>
  </criteria-paged>

  <modal :show.sync="suggetsShow" v-ref:model width="30%">
    <header slot="modal-header" class="modal-header">
      <h4 class="modal-title">处理意见</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="form-group">
        <p>{{f_suggest}}</p>
      </div>
    </article>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-default" @click="close()">关闭</button>
    </div>
  </modal>
</template>

<script>
import {HttpResetClass, PagedList} from 'vue-client'
  export default {
    data () {
      return {
        model: new PagedList('/rs/sql/queryOrderCenterSafe',20, {tablename: '`t_order_center`',items: '`*`',orderitem: '`f_orderdate`'},
          null,null,null),
        f_orgids: this.$login.f.orgid,
        // f_orgids: '1522.255', //测试使用
        suggetsShow: false,
        f_suggest: '',
        users:[{label: '全部', value: ''}],

        curorgid: [this.$login.f.orgid],
        f_orgid: '',
        sliceArea: [],
        pcds: []
      }
    },
    ready(){
      // 默认查询待处理状态预约
      this.search()
      this.initBookChecker()
    },
    methods: {
      initBookChecker(){
        new HttpResetClass().load('POST', '/rs/search', {
          data: {
            source: `root.getResourceById($${this.$login.f.orgid}$,$organization$).getSpecialResByType($user$).where(row.getAttributes().get($rolestr$).indexOf($网格员$) != -1)`,
            userid: this.$login.f.id
          }
        }, {resolveMsg: null, rejectMsg: null}).then(res=>{
          let data = res.data
          const addedNames = new Set()
          this.users = []
          data.forEach(user => {
            if (user.state === '在职') {
              if (!addedNames.has(user.name)) {
                this.users.push({ label: user.name, value: user.name })
                addedNames.add(user.name)
              }
            }
          });
        })
      },
      getPcds(val) {
        this.pcds = [{label: '全部', value: ''}]
        new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_OrderBy`,
          {data: {items: "*", tablename: "t_pcd", orderitem: "id", condition: `f_orgid in ${val}`}},
          {resolveMsg: null, rejectMsg: null}).then((pcdlist) => {
          pcdlist.data.forEach((result) => {
            this.pcds.push({label: result.f_pcd, value: result.f_pcd})
          })
        })
      },
      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          // this.getorg(this.curorgid)
          this.f_orgid = this.$login.convertToIn(this.curorgid);
        }
        args.condition = `${args.condition} and f_orgstr in ${this.f_orgid}`
        this.model.search(args.condition, args.model)
      },
      // 显示处理意见
      showSuggest (f_suggest) {
        this.f_suggest = f_suggest
        this.suggetsShow = true
      },
      close () {
        this.suggetsShow = false
      },
      hiddenr() {
        this.$parent.showItem = !this.$parent.showItem
      },
      getRes(obj) {
        this.f_orgid = this.$login.convertToIn(obj.resids);
        this.getPcds(this.f_orgid)
        this.$refs.paged.$refs.criteria.model.f_pcd = ''
      }
    },
    computed: {
      getState () {
        return [{label: '全部', value: ''},{label: '待处理', value: '待处理'},{label: '审核通过', value: '预约成功'},{label: '审核未通过', value: '预约失败'}]
      },
      orderType () {
        return [{label: '全部', value: ''},...this.$appdata.getParam('预约类型')]
      }
    },
    watch: {
      'sliceArea' () {
        this.model.model.f_slice_area = ''
      }
    }
  }
</script>
<style lang="less" >
</style>
