<template>
  <super-dialog
    v-bind="$attrs"
    v-model="isShowDialog"
    width="70%"
    title="问题上报"
    :modal="false"
    top="10vh"
    @open="open"
    @closed="closed"
  >
    <div v-loading="formLoading" class="form-content" element-loading-background="rgba(10 ,38 ,61, 0.95)"
         element-loading-text="数据加载中...">
      <el-form ref="addEditForm" :model="addEditForm" :rules="addEditRules" label-position="left" label-suffix="："
               label-width="120px">
        <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
          <el-col :span="16">
            <el-form-item label="工单标题" prop="title">
              <el-input v-model="addEditForm.title"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px" type="flex">
          <el-col :span="16">
            <el-form-item label="所属模块" prop="module">
              <el-radio-group v-model="addEditForm.module" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode('gd-ssmk')" :key="index" :label="item.value" :value="item.value">{{ item.name }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
          <el-col :span="16">
            <el-form-item label="工单类型" prop="type">
              <el-radio-group v-model="addEditForm.type" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode('gd-gdlx')" :key="index" :label="item.value" :value="item.value">{{ item.name }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
          <el-col :span="16">
            <el-form-item label="紧急程度" prop="urgency">
              <el-radio-group v-model="addEditForm.urgency" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode('gd-jjcd')" :key="index" :label="item.value" :value="item.value" border>{{ item.name }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
          <el-col :span="20">
            <el-form-item label="问题描述" prop="problemDescription">
              <quill-editor v-model="addEditForm.problemDescription" ref="myQuillEditor" :options="editorOption"> </quill-editor>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="footer" >
      <el-button @click="closed">
        {{ $t('domestic.cancel') }}
      </el-button>
      <el-button :disabled="formLoading" :loading="saveLoading" type="primary" @click="handleSave">
        {{ $t('domestic.save') }}
      </el-button>
    </div>
  </super-dialog>
</template>

<script>
import { ticketsHaveBeenAdded } from '@/api/workOrder'
import { getDictionaryByCode } from '@/utils/dictionary'
import SuperDialog from '@/components/SuperDialog/index.vue'

export default {
  name: 'AddEdit',
  components: {SuperDialog},
  props: {
    isShow: {
      default: false,
      type: Boolean
    },
  },
  computed: {
    isShowDialog: {
      get() {
        return this.isShow
      },
      set(val) {
        this.$emit('update:isShow', val)
      }
    },
  },
  data() {
    return {
      dialogFormVisible:false,
      formLoading:false,
      saveLoading:false,
      addEditForm: {
        handlingStatus:'1',
        title: '',
        module:'1',
        type:'1',
        urgency:'1',
        problemDescription:'',
      },
      addEditRules: {
        title: [
          {required: true, message: '工单标题不能为空', trigger: 'blur'}
        ],
        module: [
          {required: true, message: '所属模块不能为空', trigger: 'change'}
        ],
        type: [
          {required: true, message: '工单类型不能为空', trigger: 'change'}
        ],
        urgency: [
          {required: true, message: '紧急程度不能为空', trigger: 'change'}
        ],
        problemDescription: [
          {required: true, message: '问题描述不能为空', trigger: ['change','blur']}
        ],
      },
      editorOption: {
        placeholder: '请输入内容......',
      },
    }
  },
  created() {
  },
  methods: {
    getDictionaryByCode,
    open(){},
    closed(){
      this.$refs.addEditForm.resetFields()
      this.isShowDialog = false
    },
    handleSave(){
      this.$refs.addEditForm.validate( async (valid) => {
        if (valid) {
          this.saveLoading = true
          let { state } = await ticketsHaveBeenAdded(this.addEditForm)
          if(state){
            this.saveLoading = false
            this.$message.success('上报成功')
            this.closed()
          }
        } else {
          this.saveLoading = false
        }
      });
    },
  },
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/element-variables";
::v-deep .ql-container {
  height: 250px !important;
}
::v-deep .el-dialog__body{
  color: #ffffff !important;
}

.edit-add-detail{
  display: flex;
  justify-content: center;
  .footer{
    text-align: center;
    margin-top: 60px;
  }
  .edit-detail-head{
    width: 1200px;
  }
}

.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #43a1ff50;
  margin-bottom: 16px;
  padding: 10px 0;

  .rows-left {
    margin-right: 10px;

    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #43a1ff;;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
      color: $--color-white;
    }
  }
}
</style>
