<template>
  <el-dialog
    :title="$t2('用户列表', 'components.wf.userList')"
    :append-to-body="true"
    :modal-append-to-body="true"
    :close-on-click-modal="falseValue"
    :visible.sync="showDialog"
    :modal="falseValue"
    custom-class="dialog-style list-dialog dialog-checkbox pd_0"
    width="1200px"
    @close="dialogClose"
    v-el-drag-dialog
    v-el-dialog-center
  >
    <template #title>
      <span class="el-dialog__title">{{ $t2('加签', 'components.wf.addIncreaseSign') }}
        <span style="margin-left: 10px;margin-right: 10px;">—</span>
        <b class="f-red" style="font-size: 12px;">{{ $t2('节点', 'components.wf.node') }}：{{ wfInfo.taskName }}</b>
      </span>
    </template>
    <div class="cont" style="height:450px">
      <vxe-grid
        class="is-pointer"
        ref="table-m1"
        v-bind="vxeOption"
        @resizable-change="$vxeTableUtil.onColumnWitchChange"
        @custom="$vxeTableUtil.customHandle"
        @checkbox-change="addDataTable"
        @checkbox-all="checkAll"
        @cell-dblclick="checkWithSubmit"
      >
        <template #form>
          <div class="clearfix screen-btns">
            <div class="fr">
              <vxe-button icon="el-icon-brush" class="button-sty" @click="resetEvent" type="text" status="primary"
                          plain>{{ $t2('重置', 'system.button.reset') }}
              </vxe-button>
              <vxe-button status="warning" icon="el-icon-search" class="button-sty" @click="searchEvent">
                {{ $t2('搜索', 'system.button.search') }}
              </vxe-button>
            </div>
          </div>
          <vxe-form class="screen-box" title-width="92px" title-align="right" :data="formData" @submit="searchEvent"
                    @reset="resetEvent">
            <vxe-form-item :title="$t2('登录名', 'components.wf.loginAccount')+':'" field="loginAccount">
              <template v-slot>
                <el-input v-model="formData.loginAccount" size="small" clearable/>
              </template>
            </vxe-form-item>
            <vxe-form-item :title="$t2('姓名', 'components.wf.nickName')+':'" field="nickName">
              <template v-slot>
                <el-input v-model="formData.nickName" size="small" clearable/>
              </template>
            </vxe-form-item>
            <vxe-form-item :title="$t2('手机号', 'components.wf.mobile')+':'" field="mobile">
              <template v-slot>
                <el-input v-model="formData.mobile" size="small" clearable/>
              </template>
            </vxe-form-item>
            <vxe-button type="submit" @click="searchEvent" v-show="false"></vxe-button>
          </vxe-form>
        </template>
      </vxe-grid>
    </div>
    <label id="labBtn" class="transverse">
      <div class="icon">
        <i class="el-icon-more"></i>
        <i class="el-icon-more"></i>
      </div>
    </label>
    <div class="multipleChoice">
      <el-tooltip :enterable="false" effect="dark" :content="$t2('全部删除', 'system.button.allDelete')"
                  placement="top"><a class="allDel icon-quanbushanchu" @click="clearChecked()"></a></el-tooltip>
      <div class="list">
        <div class="item" v-for="(checkRow, index) in checkRows" :key="index">
          <p>{{ checkRow.nickName }}</p>
          <a class="el-icon-close" @click="clearTable1Select(index)"></a>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
			<span class="fl tips" v-if="!selectMulti">$t2('注：双击确认选择（单选）', 'system.button.singleCheckTip')</span>
			<el-button type="primary" plain class="button-sty" @click="dialogClose">
				<i class="el-icon-close el-icon"></i>
				{{ $t2('取 消', 'system.button.cancel2') }}
			</el-button>
			<el-button type="primary" @click="dialogPrimary" class="button-sty">
				<i class="el-icon-check el-icon"></i>
				{{ $t2('确 定', 'system.button.confirm2') }}
			</el-button>
		</span>
  </el-dialog>
</template>

<script>
import {selectDialogMixins} from '../../mixins/selectDialog/index.js';

import {addTaskUserMixin} from './wf.js';

export default {
  name: 'userDialog',
  props: ['visiable', 'multi', 'rows', 'param'],
  mixins: [selectDialogMixins, addTaskUserMixin],
  created() {
    this.initSetting();
    if (this.param) {
      if (this.param.userType !== null) {
        this.userType = this.param.userType;
      }
    }
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    var that = this;
    return {
      showDialog: true,
      falseValue: false,
      userType: 0,
      formData: {
        saleOrgId: '',
        saleOrgName: ''
      },
      selectMulti: true,
      vxeOption: {}
    };
  },
  methods: {
    initTableM1() {
      var that = this;
      let tableOption = {
        vue: that,
        tableRef: 'table-m1',
        tableName: 'basic_user_dialog-m1',
        path: USER_PREFIX + '/user/listCurrentPage',
        param: () => {
          // this.formData.userType = this.userType;
          return {
            enabled: true,
            ...this.formData,
            ...this.param
          }
        },
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: 'row'
          }
        },
        columns: [
          {type: 'checkbox', width: 50, resizable: false, fixed: 'left'},
          {title: this.$t2('登录名', 'components.wf.loginAccount'), field: 'loginAccount', width: 250, fixed: 'left'},
          {field: 'nickName', title: this.$t2('姓名', 'components.wf.nickName'), width: 150},
          {field: 'mobile', title: this.$t2('手机号', 'components.wf.mobile'), width: 150},
          {
            field: 'enabled',
            title: this.$t2('是否启用', 'components.wf.enabled'),
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.enabled) {
                  return [<div class="txt-status">{this.$t2('启用', 'components.wf.enabledTrue')}</div>];
                } else {
                  return [<div class="txt-status s-3">{this.$t2('禁用', 'components.wf.enabledFalse')}</div>];
                }
              }
            }
          },
          {field: 'roleNames', title: this.$t2('角色', 'components.wf.roleNames'), width: 150},
          {field: 'saleOrgNames', title: this.$t2('机构', 'components.wf.saleOrgNames'), width: 150},
          {field: 'zipCode', title: this.$t2('邮编', 'components.wf.zipCode'), width: 150},
          {field: 'address', title: this.$t2('地址', 'components.wf.address'), width: 150},
          {
            field: 'gender',
            title: this.$t2('性别', 'components.wf.gender'),
            width: 150,
            slots: {
              default: ({row}) => {
                var val = row.gender;
                if (val == 1) {
                  return this.$t2('男', 'components.wf.gender1');
                } else if (val == 2) {
                  return this.$t2('女', 'components.wf.gender2');
                }
              }
            }
          },
          {field: 'companyNames', title: this.$t2('所属组织', 'components.wf.companyNames'), width: 250},
          {field: 'createBy', title: this.$t2('创建人', 'system.label.createBy'), width: 150},
          {field: 'modifyBy', title: this.$t2('更新人', 'system.label.modifyBy'), width: 150},
          {field: 'modifyDate', title: this.$t2('更新时间', 'system.label.modifyDate'), width: 150},
          {field: 'createDate', title: this.$t2('创建时间', 'system.label.createDate'), width: 150},
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        that.vxeOption = opts;
      });
    }
  }
};
</script>
