<template>
  <div class="search-box">
    <el-form :model="form" ref="create" :rules="ruleson">
      <el-form-item
        v-for="item in searchInputData"
        :key="item.props"
        :label="item.name"
        :prop="item.props"
        label-width="110px"
      >
        <el-input
          style="width: 250px"
          v-model="form[item.props]"
          :placeholder="item.placeholder"
          clearable
        />
      </el-form-item>
      <el-form-item
        label="银行行别代码"
        prop="bankTypeCode"
        label-width="110px"
      >
        <el-input
          style="width: 250px"
          v-model="form.bankTypeCode"
          placeholder="请选择银行行别代码"
          clearable
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click.stop="selectDevice()"
          ></el-button>
        </el-input>
      </el-form-item>
    </el-form>
    <el-dialog
      title="银行代码"
      :visible.sync="deviceVisible"
      width="50%"
      :before-close="handleClose"
      append-to-body
      destroy-on-close
    >
      <DeviceView @selectRowList="selectRowList" />
    </el-dialog>
  </div>
</template>
<script>
import { InputData } from "./form";
import DeviceView from "./device.vue";
// import { getStoreRoomData } from "@/api/storerom-manage/allcation-manage";
export default {
  name: "searchView",
  components: {
    DeviceView,
  },
  data() {
    var validatePass = async (rules, value, callback) => {
      const reg = /^[0-9]*$/;
      if (reg.test(value)) {
        callback();
      } else {
        callback(new Error("请输入正确的银行账号"));
      }
    };
    return {
      form: {
        supId: "",
        supName: "",
        bankTypeCode: "",
        bankcode: "",
        bankacct: "",
        acctname: "",
      },
      ruleson: {
        bankTypeCode: [{ required: true, message: "请输入银行行别代码" }],
        bankcode: [
          {
            required: true,
            message: "请输入银行行号",
            trigger: "change",
          },
          {
            validator: validatePass,
            trigger: "change",
          },
        ],
        bankacct: [
          { required: true, message: "请输入银行账号" },
          {
            validator: validatePass,
            trigger: "change",
          },
        ],
        acctname: [{ required: true, message: "请输入银行卡户名" }],
      },
      modalTitle: "",
      deviceVisible: false,
      searchInputData: InputData,
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6;
        },
      },
    };
  },
  mounted() {},
  methods: {
    //加工数据符合下拉组件属性
    processData(data, label) {
      let newData = [];
      data.forEach((item) => {
        newData.push({
          label: item[label],
          value: item.id,
        });
      });
      return newData;
    },
    onSubmit() {
      let { userID, username } = this.$store.state.user;
      this.$refs["create"].validate((valid) => {
        if (valid) {
          this.form.supId = userID;
          this.form.supName = username;
          this.$emit("searchSuses", { ...this.form });
        }
      });
    },
    selectRowList(data) {
      this.form.bankTypeCode = data.bankTypeCode;
      this.deviceVisible = false;
    },
    // 选择智能设备弹窗
    selectDevice() {
      this.deviceVisible = true;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$emit("searchSuses", this.form);
    },
  },
};
</script>
<style scoped lang="scss">
.search-box {
  padding: 0;
}
</style>
