<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search'>
        <div novalidate class="form-inline auto" partial>
          <div class="form-group">
          用户名:
          <input type="text" class="form-control" v-model="model.f_user_name" v-on:keyup.enter="search"
          condition="f_username like '%{}%'">
          用户电话:
          <input type="text" class="form-control" v-model="model.f_user_phone" v-on:keyup.enter="search"
          condition="f_user_phone like '%{}%'">
          小区地址:
          <input type="text" class="form-control" v-model="model.f_residential_area" v-on:keyup.enter="search"
          condition="f_districtname like '%{}%'">
          建档月份
          <datepicker id="startdate"
            :value.sync="$parent.$parent.model.f_archive_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM'">
          </datepicker>
          <label for="f_subcompany">分公司：</label>
          <v-select id="f_subcompany"
          placeholder='请选择'
          :value.sync="$parent.$parent.model.f_subcompany"
          :options='$parent.$parent.f_divisions'
          close-on-select clear-button></v-select>
          <label for="f_user_state">档案状态：</label>
          <v-select id="f_user_state"
          placeholder='请选择'
          :value.sync="$parent.$parent.model.f_user_state"
          :options='$parent.$parent.f_user_states'
          close-on-select clear-button></v-select>
          安检员:
          <input type="text" class="form-control" v-model="model.f_checker" v-on:keyup.enter="search"
          condition="f_checker = '{}'">
          <button class="btn btn-default" @click="search()">查询</button>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>用户编号</th>
            <th>用户姓名</th>
            <th>安检负责人</th>
            <th>所属子公司</th>
            <th>建档日期</th>
            <th>用户类型</th>
            <th>详细地址</th>
            <th>是否录入</th>
            <th>状态</th>
            <th>修改</th>
            <th>设置状态</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{row.f_userid}}</td>
          <td>{{row.f_username}}</td>
          <td>{{row.f_checker }}</td>
          <td>{{row.f_subcompany}}</td>
          <td>{{row.f_archive_date}}</td>
          <td>{{row.f_user_type}}</td>
          <td>{{row.f_address}}</td>
          <td>{{row.f_sign=='1'?'是':'否'}}</td>
          <td>{{row.f_state}}</td>
          <td>
            <button class="btn btn-default"  @click='$parent.$parent.$parent.change(row)'>修改</button>
          </td>
          <td>
            <button class="btn btn-default"  @click="$parent.$parent.$parent.writeoff(row, '正常')">正常</button>
            <button class="btn btn-default"  @click="$parent.$parent.$parent.writeoff(row, '注销')">注销</button>
            <button class="btn btn-default"  @click="$parent.$parent.$parent.writeoff(row, '点火')">点火</button>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'
import co from 'co'
import AppData from '../../stores/AppData'

let writeOff = function * (self, row, state) {
  yield self.$resetpost('rs/logic/档案状态修改', { data: {id: row.id, f_state: state} }, {resolveMsg: '修改状态成功！', rejectMsg:'修改状态失败！'}).then((response) => {
    row.f_state = state
  })
}

export default {
  title: '档案修改',
  props: ['f'],
  data () {
    let model = new PagedList('rs/sql/用户档案查询', 20, {items: '"CAST(id as varchar) strid,*"', tablename: '"t_userfiles"', groupitem: '""', orderitem: '"f_userid"',
      f_OrgStr: `this.f_OrgStr`, f_archive_date: 'this.f_archive_date', f_state:'this.f_user_state[0]'})
    model.f_OrgStr = Vue.f_OrgStr
    model.f_archive_date = ''
    model.f_user_state =['']
    return {
      model: model,
      f_divisions: Vue.f_subcompany != '' ? [{label: Vue.f_subcompany, value: Vue.f_subcompany}]: this.$appdata.getParam('安检系统用子公司'),
      f_user_states: this.$appdata.getParam('用户档案状态')
    }
  },
  methods: {
    change (row) {
      this.$goto('userfile-change', {model: row, f: this.f})
    },
    writeoff (row, state) {
      let gen = writeOff(this, row, state)
      return co(gen)
    },
  }
}
</script>
