<template>
    <div class="app-container">
      <van-nav-bar
        title="投诉回复"
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      />
      <div class="main">
        <van-form @submit="goAdd">
          <div class="main_box">
            <van-field
              readonly
              clickable
              name="picker"
              v-model="typeValue"
              label="类型"
              placeholder="选择类型"
              @click="showType = true"
              input-align="right"
              right-icon="arrow-down"
              :rules="[{ required: true }]" required
            />
            <van-popup v-model="showType" position="bottom">
              <van-picker
                show-toolbar
                :columns="typeOptions"
                @confirm="onConfirmType"
                @cancel="showType = false"
              />
            </van-popup>
            <van-field :rules="[{ required: true }]" required v-model="form.title" label="标题" placeholder="标题" input-align="right"/>
            <van-field v-model="form.name" label="姓名" placeholder="姓名" input-align="right"/>
            <van-field :rules="[{ required: true }]" required v-model="form.phone" label="联系电话" placeholder="联系电话" input-align="right"/>
            <van-field :rules="[{ required: true }]" required v-model="form.content" label="投诉内容" placeholder="投诉内容" input-align="right"/>
          </div>
          <div style="margin: 16px;">
            <van-row>
              <van-col span="24" align="center">
                <van-button type="info" native-type="submit" class="submitButton">发布</van-button>
              </van-col>
            </van-row>
          </div>
        </van-form>
      </div>
    </div>
</template>

<script>
  import { communicateAdd , getTopDeptId } from "@/api/lawEnforcement/index";
  import $ from "jquery";
  export default {
  name: "complaintAdd",
  data() {
    return {
      form:{
        title:'',
        communicateType:'',
        content:'',
        name:'',
        phone:'',
        deptId:''
      },
      showType:false,
      typeValue:'',
      typeOptions:[]
    };
  },
  created() {
    this.getDicts("communicate_type").then(response => {
      response.data.map(item => {
        this.typeOptions.push({ value:item.dictValue, text: item.dictLabel});
      });
    });
    this.getDeptId();
  },
  methods: {
    getDeptId(){
      getTopDeptId().then(response => {
        this.form.deptId = response.data;
      })
    },
    onConfirmType(data){
      this.typeValue = data.text;
      this.form.communicateType = data.value;
      this.showType = false;
    },
    goAdd(){
      communicateAdd(this.form).then(res => {
        console.log(res);
        this.$toast.success('发布成功');
        self.location=document.referrer;
      });
    }
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding-bottom: 5%;
  }
  #mapWrap{
    width: 96%;
    margin: 0 auto;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    overflow: hidden;
  }
  .mapBox{
    position: relative;
    .mapBox_button{
      position: absolute;
      top: 0.2rem;
      right: 2%;
    }
  }
  .van-steps{
    padding: 2% 6% 0;
  }
  .topTit{
    margin-top: 0.4rem;
    font-size: 0.45rem;
    background-color: #1D6FE9;
    color: #FFFFFF;
    line-height: 58px;
    text-align: center;
    padding: 15px 0;
    box-shadow: 0px 3px 6px 0px rgba(15,67,145,0.40);
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    position: relative;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
    margin-top: 10PX;
  }
  .collapse{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    margin-bottom: 15px;
  }
  /deep/.van-radio--horizontal{
    margin-left: 20px;
    margin-right: 0;
  }
  .file-box{
    padding: 2% 5% 0;
  }
  .submitButton{
    width: 80%;
    margin: 0 auto;
    background-color: #1D6FE9;
    border-radius: 14px;
  }
  .timeTit{
    text-align: center;
    font-size: 16px;
    line-height: 27px;
  }
  .action-box{
    padding: 15px 0!important;
    margin-top: 0.4rem;
  }
  .check-box{
    margin-top: 0.4rem;
  }
  .addFamily{
    position: absolute;
    top: -2px;
    right: 0;
    border-radius: 50%;
  }
  .deleteFamily{
    position: absolute;
    top: -0.3rem;
    right: 6%;
    z-index: 9;
    border-radius: 50%;
  }
  .familyList{
    margin-top: 0.4rem;
    position: relative;
  }
  .noModify{
    .topTit{
      background-color:#ABABAB ;
      box-shadow: 0px 3px 6px 0px rgba(171,171,171,0.40);
    }
    .van-cell__title{
      color: #B4B0B0;
    }
  }
</style>
