<template>
  <el-dialog :close-on-click-modal="false" :modal-append-to-body="false" :visible.sync="cuDialogVisible" :title="title">
    <span class="dialog-right-top" />
    <span class="dialog-left-bottom" />
    <div class="setting-dialog">
      <div class="fields-list">
        <el-form ref="form" :model="formData" size="small" label-width="100px">
          <el-row v-for="(item) in formData.fields" :key="item.id" :gutter="10">
            <el-col :span="13">
              <el-form-item label="组成字段">
                <el-input v-model="item.fieldCnName" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="排序方式">
                <el-radio-group v-model="item.displayOrderBy">
                  <el-radio label="asc">升序</el-radio>
                  <el-radio label="desc">降序</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cuDialogVisible=false">取消</el-button>
        <el-button type="primary" :loading="loading" @click="save">确定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { edit } from '@/api/category/orderingRule'
export default {
  data() {
    return {
      cuDialogVisible: false,
      formData: {},
      title: '',
      loading: false
    }
  },
  methods: {
    save() {
      this.loading = true
      edit(this.formData.fields).then((res) => {
        this.$message({
          message: '保存成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.cuDialogVisible = false
        this.$emit('refresh')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.fields-list {
  max-height: calc(100vh - 312px);
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
}
</style>
