<template>
  <el-dialog
    :title="$t1('用户列表')"
    :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
  >
    <div class="cont" style="height:65vh">
      <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>
          <tableForm :formData.sync="formData" @searchEvent="searchEvent" @resetEvent="resetEvent">
            <template #buttonRight>
              <vxe-button icon="el-icon-brush" class="button-sty" @click="resetEvent" type="text" status="primary"
                          plain>{{ $t1('重置') }}
              </vxe-button>
              <vxe-button status="warning" icon="el-icon-search" class="button-sty" @click="searchEvent">
                {{ $t1('搜索') }}
              </vxe-button>
            </template>
            <template #saleOrgName>
              <vxe-form-item :title="$t1('机构')+':'">
                <template v-slot>
                  <el-input
                    class="search-input"
                    v-model="formData.saleOrgName"
                    clearable
                    @clear="
                  formData.saleOrgId = null;
                  formData.saleOrgName = null;
                "
                    v-el-readonly
                  >
                    <i slot="suffix" class="el-input__icon el-icon-search"
                       @click="showSaleOrgDialog=true"></i>
                  </el-input>
                </template>
              </vxe-form-item>
            </template>
          </tableForm>
        </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="$t1('全部删除')" 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>{{ getCheckLabel(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">{{ $t1('注：双击确认选择（单选）') }}</span>
			<el-button type="primary" plain class="button-sty" @click="dialogClose">
				<i class="el-icon-close el-icon"></i>
				{{ $t1('取 消') }}
			</el-button>
			<el-button type="primary" @click="dialogPrimary" class="button-sty">
				<i class="el-icon-check el-icon"></i>
				{{ $t1('确 定') }}
			</el-button>
		</span>
    <saleOrgDialog v-if="showSaleOrgDialog" :visiable.sync="showSaleOrgDialog" :multi="false"
                   @confirm="confirmSaleOrgDialog"></saleOrgDialog>
  </el-dialog>
</template>

<script>
import {selectDialogMixins} from '@base/mixins/selectDialog/index.js';
import tableForm from "@base/components/table/tableForm.vue";
import saleOrgDialog from "@base/views/user/sale_org/dialog.vue";

export default {
  name: 'userDialog',
  components: {tableForm, saleOrgDialog},
  props: ['visiable', 'multi', 'rows', 'param'],
  mixins: [selectDialogMixins],
  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: {},
      showSaleOrgDialog: false
    };
  },
  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
          }
        },
        searchColumns: [
          {title: this.$t1('登录名'), field: "loginAccount", type: "input", common: true},
          {title: this.$t1('姓名'), field: "nickName", type: "input", common: true},
          {title: this.$t1('机构'), field: "saleOrgName", type: "input", common: true, slot: "saleOrgName"},
        ],
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: 'row'
          }
        },
        columns: [
          {type: 'checkbox', width: 50, resizable: false, fixed: 'left'},
          {title: this.$t1('登录名'), field: 'loginAccount', width: 250, fixed: 'left'},
          {field: 'nickName', title: this.$t1('姓名'), width: 150},
          {
            field: 'enabled',
            title: this.$t1('是否启用'),
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.enabled) {
                  return [<div class="txt-status">{this.$t1('启用')}</div>];
                } else {
                  return [<div class="txt-status s-3">{this.$t1('禁用')}</div>];
                }
              }
            }
          },
          {field: 'roleNames', title: this.$t1('角色'), width: 150},
          {field: 'saleOrgNames', title: this.$t1('机构'), width: 150},
          {field: 'zipCode', title: this.$t1('邮编'), width: 150},
          {field: 'address', title: this.$t1('地址'), width: 150},
          {
            field: 'gender',
            title: this.$t1('性别'),
            width: 150,
            slots: {
              default: ({row}) => {
                var val = row.gender;
                if (val == 1) {
                  return this.$t1('男');
                } else if (val == 2) {
                  return this.$t1('女');
                }
              }
            }
          },
          {field: 'companyNames', title: this.$t1('所属组织'), width: 250},
          {field: 'createBy', title: this.$t1('创建人'), width: 150},
          {field: 'modifyBy', title: this.$t1('更新人'), width: 150},
          {field: 'modifyDate', title: this.$t1('更新时间'), width: 150},
          {field: 'createDate', title: this.$t1('创建时间'), width: 150},
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        that.vxeOption = opts;
      });
    },
    confirmSaleOrgDialog(rows) {
      if (rows.length) {
        let row = rows[0];
        this.$set(this.formData, 'saleOrgId', row.id);
        this.$set(this.formData, 'saleOrgName', row.name);
      }
    }
  }
};
</script>
