<script>
  module.exports = {
    data() {
      return {
        gridData: [{
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }],
        dialogVisible: false,
        dialogTableVisible: false,
        dialogFormVisible: false,
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        formLabelWidth: '80px'
      };
    },
    methods: {
      openDialog() {
        this.$refs.dialogBind.open();
      }
    }
  };
</script>

<style>
  .demo-box.demo-dialog {
    .dialog-footer button:first-child {
      margin-right: 10px;
    }
    .full-image {
      width: 100%;
    }
    .fs-dialog__wrapper {
      margin: 0;
    }
    .fs-select {
      width: 300px;
    }
    .fs-input {
      width: 300px;
    }
    .fs-button--text {
      margin-right: 15px;
    }
  }
</style>
## Dialog 对话框
在保留当前页面状态的情况下，告知用户并承载相关操作。

### 基本用法

Dialog 弹出一个对话框，适合需要定制性更大的场景。

:::demo 需要设置`v-model`属性，它接收`Boolean`，当为`true`时显示 Dialog。Dialog 分为两个部分：`body`和`footer`，`footer`需要具名为`footer`的`slot`。`title`属性用于定义标题，它是可选的，默认值为空。本例通过显式改变`v-model`的值来打开 Dialog，此外我们还为 Dialog 实例提供了`open`和`close`方法，可以通过调用它们来打开/关闭 Dialog。

```html
<fs-button type="text" @click="dialogVisible = true">点击打开 Dialog</fs-button>

<fs-dialog title="提示" v-model="dialogVisible" size="tiny">
  <span>这是一段信息</span>
  <span slot="footer" class="dialog-footer">
    <fs-button @click="dialogVisible = false">取 消</fs-button>
    <fs-button type="primary" @click="dialogVisible = false">确 定</fs-button>
  </span>
</fs-dialog>

<script>
  export default {
    data() {
      return {
        dialogVisible: false
      };
    }
  };
</script>
```
:::

### 自定义内容

Dialog 组件的内容可以是任意的，甚至可以是表格或表单，下面是应用了 Element Table 和 Form 组件的两个样例。

:::demo
```html
<!-- Table -->
<fs-button type="text" @click="dialogTableVisible = true">打开嵌套表格的 Dialog</fs-button>

<fs-dialog title="收货地址" v-model="dialogTableVisible">
  <fs-table :data="gridData">
    <fs-table-column property="date" label="日期" width="150"></fs-table-column>
    <fs-table-column property="name" label="姓名" width="200"></fs-table-column>
    <fs-table-column property="address" label="地址"></fs-table-column>
  </fs-table>
</fs-dialog>

<!-- Form -->
<fs-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</fs-button>

<fs-dialog title="收货地址" v-model="dialogFormVisible">
  <fs-form :model="form">
    <fs-form-item label="活动名称" :labfs-width="formLabelWidth">
      <fs-input v-model="form.name" auto-complete="off"></fs-input>
    </fs-form-item>
    <fs-form-item label="活动区域" :labfs-width="formLabelWidth">
      <fs-select v-model="form.region" placeholder="请选择活动区域">
        <fs-option label="区域一" value="shanghai"></fs-option>
        <fs-option label="区域二" value="beijing"></fs-option>
      </fs-select>
    </fs-form-item>
  </fs-form>
  <div slot="footer" class="dialog-footer">
    <fs-button @click="dialogFormVisible = false">取 消</fs-button>
    <fs-button type="primary" @click="dialogFormVisible = false">确 定</fs-button>
  </div>
</fs-dialog>

<script>
  export default {
    data() {
      return {
        gridData: [{
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }],
        dialogTableVisible: false,
        dialogFormVisible: false,
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        formLabelWidth: '120px'
      };
    }
  };
</script>
```
:::

### Attributes
| 参数      | 说明          | 类型      | 可选值                           | 默认值  |
|---------- |-------------- |---------- |--------------------------------  |-------- |
| title     | Dialog 的标题，也可通过具名 slot （见下表）传入 | string    | — | — |
| size      | Dialog 的大小 | string    | tiny/small/large/full | small |
| top       | Dialog CSS 中的 top 值（仅在 size 不为 full 时有效） | string | — | 15% |
| modal     | 是否需要遮罩层   | boolean   | — | true |
| modal-append-to-body     | 遮罩层是否插入至 body 元素上，若为 false，则遮罩层会插入至 Dialog 的父元素上   | boolean   | — | true |
| lock-scroll | 是否在 Dialog 出现时将 body 滚动锁定 | boolean | — | true |
| custom-class      | Dialog 的自定义类名 | string    | — | — |
| close-on-click-modal | 是否可以通过点击 modal 关闭 Dialog | boolean    | — | true |
| close-on-press-escape | 是否可以通过按下 ESC 关闭 Dialog | boolean    | — | true |
| show-close | 是否显示关闭按钮 | boolean    | — | true |

### Slot
| name | 说明 |
|------|--------|
| — | Dialog 的内容 |
| title | Dialog 标题区的内容 |
| footer | Dialog 按钮操作区的内容 |

### 方法
每个 `fs-dialog` 实例都暴露了如下方法，用于在不显式改变 `v-model` 值的情况下打开 / 关闭实例：
| 方法名 | 说明 |
|------|--------|
| open | 打开当前实例 |
| close | 关闭当前实例 |

### Events
| 事件名称      | 说明    | 回调参数      |
|---------- |-------- |---------- |
| close  | Dialog 关闭的回调 | — |
| open  | Dialog 打开的回调 | — |
