<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="35%"
    @close="close"
  >
    <el-form
      ref="form"
      label-position="left"
      label-width="110px"
      :model="form"
      :rules="rules"
      size="medium"
    >
      <el-form-item :label="__('请选择银行卡')" prop="user_bank_id">
        <el-select
          v-model="form.user_bank_id"
          class="filter-item"
          clearable
          :placeholder="__('请选择银行卡')"
        >
          <el-option
            v-for="item in dataList"
            :key="item.user_bank_id"
            :label="item.bank_name"
            :value="item.user_bank_id"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">{{ __('取消') }}</el-button>
      <el-button type="primary" @click="save">{{ __('保存') }}</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { bankCards } from '@/api/card/type'
  import { settlemented } from '@/api/order/base'

  export default {
    name: 'AddressEdit',
    components: {},
    data() {
      return {
        dataList: [],
        form: {},
        title: '',
        dialogFormVisible: false,
        rules: {
          user_bank_id: [
            {
              required: true,
              message: this.__('请选择银行卡'),
              trigger: 'change',
            },
          ],
        },
      }
    },
    created() {
      this.functionbankCards()
    },
    methods: {
      __,
      showType() {
        this.dialogFormVisible = true
      },
      close() {
        this.form = {}
        this.$refs['form'].resetFields()
        this.dialogFormVisible = false
      },
      async functionbankCards() {
        // 发请求获取渠道下拉框的值
        await bankCards().then((res) => {
          this.dataList = res.data // 把获取到的数据赋给this.dataList
        })
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await settlemented(this.form)
            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }
            this.$emit('fetch-data')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
