<!--
 * @Descripttion: 编辑账号
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-11-13 14:24:53
 * @LastEditors: 无尘
 * @LastEditTime: 2020-11-13 16:32:30
-->
<template>
  <el-dialog :title="!!editRow.id ? '编辑账号':'新增账号'" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
    <div class="">
      <el-form :model="ruleForm"  ref="ruleForm" label-width="10px" class="demo-ruleForm" @submit.native.prevent>
        <el-form-item label="用户姓名" prop="">
          <el-input class="w-363"  v-model="ruleForm.sqlCheckSql" maxlength="500" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="用户手机号" prop="">
          <el-input class="w-363"  v-model="ruleForm.sqlCheckSql" maxlength="500" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="试用账号" prop="">
          <el-input class="w-363"  v-model="ruleForm.sqlCheckSql" maxlength="500" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="账号类型" prop="">
          <el-radio v-model="ruleForm.radio" label="1">手机号</el-radio>
          <el-radio v-model="ruleForm.radio" label="2">企微账号</el-radio>
        </el-form-item>
        <el-form-item label="试用企业" prop="">
          <el-popover placement="bottom" title="" width="363">
            <div class="select-search">
              <el-input placeholder="搜索企业/商户名称" clearable maxlength="40" v-model="searchSelect" style="width: 100%;" prefix-icon="el-icon-search" @keyup.native="value => toInput(value, searchSelect)" @clear="clearSearch"> </el-input>
            </div>
            <div class="daily-store-select">
              <div class="el-scrollbar define-search-select">
                <div class="el-select-dropdown__wrap el-scrollbar__wrap" style="overflow: auto;">
                  <ul class="el-scrollbar__view el-select-dropdown__list">
                    <li :class="['el-select-dropdown__item', item.enterpriseId == ruleForm.enterpriseId ? 'selected hover' : '']" v-for="item in companyData" :key="item.enterpriseId" @click="checkCompany(item)">
                      <div class="flex flex-space-between">
                        <div style="line-height:26px;">
                          <div class="text-ellipsis font-12 color-909399">{{ item.enterpriseName || '--' }}</div>
                        </div>
                      </div>
                    </li>
                    <li v-if="!companyData.length" class="text-center"><span>暂无数据</span></li>
                  </ul>
                </div>
              </div>
            </div>
            <div class="show-select-num cursor-pointer w-558" slot="reference">
              <div class="select-search-input">{{ ruleForm.enterpriseName }}</div>
            </div>
          </el-popover>
        </el-form-item>
        <el-form-item label="有效期" prop="">
          <el-select v-model="ruleForm.date" placeholder="请选择">
            <el-option
              v-for="item in validOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import fetch from '@/api/dictionary';

const { getEnterpriseList } = fetch;
export default {
  name: 'SqlDetail',
  components: {},
  props: {
    editRow: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      dialogVisible: true,
      loadBtn: false,
      ruleForm: {
        sqlCheckSqlId: '',
        sqlCheckSql: '',
        sqlCheckProjectName: '',
        sqlCheckTableName: '',
        sqlCheckIndexType: '',
        statusFlag: ''
      },
      validOptions: [
        {
          value: '',
          label: '不限'
        },
        {
          value: '1',
          label: '1天'
        },
        {
          value: '7',
          label: '7天'
        },
        {
          value: '30',
          label: '30天'
        },
        {
          value: '90',
          label: '90天'
        },
        {
          value: '180',
          label: '180天'
        },
        {
          value: '360',
          label: '360天'
        }
      ],
      searchSelect: '',
      companyData: []
    };
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    const that = this;
    if (Object.keys(that.sqlRow).length) {
      that.ruleForm = JSON.parse(JSON.stringify(that.sqlRow));
    }
  },
  // methods
  methods: {
    /**
     * 输入
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.getData();
    }, 500),
    getData() {
      const that = this;
      let para = {
        search: that.searchSelect
      };
      getEnterpriseList(para)
        .then(res => {
          if (res.code == '0000') {
            that.companyData = res.result || [];
          }
        })
        .catch(function(error) {

        });
    },
    /**
     * @description: 选择企业
     * @param {Object} item
     * @author: 无尘
     */
    checkCompany(item) {
      const that = this;
      that.ruleForm.enterpriseName = item.enterpriseName;
      that.ruleForm.enterpriseId = item.enterpriseId;
    },
    /**
     * @description: 关闭弹窗
     * @author: 无尘
     */
    handleClose() {
      const that = this;
      that.$emit('closeDetail');
      that.$refs['ruleForm'].resetFields();
    },

  },
  watch: {
    editRow(newData) {
      const that = this;
      if (Object.keys(newData).length) {
        that.ruleForm = JSON.parse(JSON.stringify(newData));
      }
    }
  }
};
</script>
<style lang='less' scoped>
  .w-363 {
    width: 363px;
  }
  .selected {
    div {
      color: #2f54eb;
    }
  }
</style>
