<template>
  <div id="unit" class="flex-row">
    <batch-user-list  :class="{'basic-main': !isdetail,'binary-left': isdetail}" style="width: auto;" v-ref:userlist   @save="save"></batch-user-list>
    <div class="binary-right" style="overflow-y: auto;" v-if="isdetail" style="width: 50%">
      <batch-edit-operate v-ref:editoperate @batchedit="batchedit"  :info='pinfo'></batch-edit-operate>
    </div>
  </div>
</template>
<script>
  // 批量修改档案查询列表
  import batchUserList from './batchUserList'
  import batchEditOperate from './batchEditOperate'
  import * as Util from "../../../Util";

  export default {
    title: '批量修改档案',
    name: 'batchEditManagee',
    components: {
      batchUserList, batchEditOperate
    },
    data () {
      return {
        // 单选数据
        row: {},
        // 多选数据
        rowsdata: [],
        files: {},
        pinfo: {},
        isdetail: true,
        chinesename: {
          files: {
            'f_inputtor': '抄表员',
            'f_position': '表安装位置',
            'f_aroundmeter': '左右表',
            'f_install_person': '安装人',
            'f_install_date': '安装日期',
            'f_gas_person': '通气人',
            'f_hand_month': '抄表月份',
            'f_gas_date': '通气日期',
            'f_changetube_person': '改管人',
            'f_changetube_date': '改管日期',
            'f_usestate': '使用状态',
            'f_comments': '备注',
            'f_overdue_set': '违约金规则',
            'f_adjustable_name': '调 压 箱',
            'f_book_slice_area': '表册片区'
          }
        }
      }
    },
    created () {
    },
    ready () {
      this.arrAddFun()
    },
    methods: {
      selected (obj) {
        console.log(obj)
        this.pinfo = obj.val
      },
      batchedit (value) {
        this.files = value
      },
      arrAddFun () {
        // 拓展数组去空值的方法
        Array.prototype.removeEmpty = function () {
          for (var i = 0; i < this.length; i++) {
            if (this[i] === '' || typeof (this[i]) === 'undefined') {
              this.splice(i, 1)
              i--
            }
          }
          return this
        }
      },
      async save () {
        var edititem = []
        var flag = 0
        for (var item in this.files) {
          if (this.files[item] !== '') {
            flag = 1
          }
          if (this.files[item] instanceof Array) {
            this.files[item] = this.files[item].length > 0 ? this.files[item][0] : ''
          }
          var file = {
            chinesename: this.chinesename.files[item],
            fieldname: item,
            tablename: 't_userfiles',
            newvalue: this.files[item],
            state: '有效',
            modifitime: Util.toStandardDateString()
          }
          var operateinfo = {
            f_operator: this.$login.f.name,
            f_operatorid: this.$login.f.id,
            f_orgid: this.$login.f.orgid,
            f_orgname: this.$login.f.orgs,
            f_depid: this.$login.f.depids,
            f_depname: this.$login.f.deps,
            f_comments: this.files.f_comments
          }
          edititem.push(file)
        }
        let rowsdatas = this.rowsdata
        if (flag === 1) {
          await this.$resetpost('rs/logic/batchEditFiles',
            {rowsdata: rowsdatas, edititem: edititem, operateinfo: operateinfo})
          this.init()
        } else {
          // 没有需要更改的数据
          this.$showAlert('没有需要更改的数据', 'warning', 1500)
          this.init()
        }
      },
      init () {
        this.files = {}
        this.rowsdata = []
        this.$refs.userlist.search()
        this.$refs.editoperate.init()
      }
    },
    events: {

    }
  }
</script>

<style lang="less">

</style>
