<template>
  <u-navbar
      :title="title"
      :auto-back="true"
      left-icon-size="40rpx"
      :safe-area-inset-top="true"
      :placeholder="true"
      bgColor="#ffffff"
  ></u-navbar>
  <view class="body-background">

  </view>
  <u-row :custom-style="{padding:'16rpx 26rpx'}">
    <u-col :span="12" :custom-style="{
      backgroundColor:'#FFFFFF',
      borderRadius:'20rpx',
      padding:'40rpx 32rpx',
      minHeight:'1000rpx',
      position:'relative'
    }">
      <u-form
          errorType="toast"
          labelWidth="auto"
          labelPosition="left"
          :model="model"
          :rules="rules"
          ref="feedForm"
      >
        <u-form-item
            prop="content"
            :custom-style="{padding:'0'}"
        >
          <u-textarea
              v-model="model.content"
              border="none"
              placeholder="请描述您的问题"
              height="220"
              :custom-style="{
                backgroundColor:'#FAFAFA',
                padding:'8rpx 20rpx'
              }"
          ></u-textarea>
        </u-form-item>
        <u-form-item
            prop="userInfo.sex"
            :custom-style="{padding:'34rpx 0'}"
        >
          <MzUpload v-model="model.pictures" format="string"></MzUpload>
        </u-form-item>
      </u-form>
      <view class="bottom-btn border-box">
        <u-button
            type="primary"
            text="提交"
            shape="circle"
            :custom-style="{
              color:'#020B18',
              backgroundColor:'#FF9545',
              border:'none',
              fontSize:'36',
              fontWeight:'400',
              marginTop:'48rpx',
              height:'80rpx'
            }"
            @click="submit"

        ></u-button>
      </view>
    </u-col>
  </u-row>
</template>

<script>
import {
  imghost
} from '@/config/host.js'
import MzSubsection from '@/components/MzSubsection/Index.vue';
import api from '@/utils/functions.js';
import {feedback} from "@/api/feed";
import {userDetail, userEdit} from "@/api/user";
import {setQuestions} from "@/api/advisor";
import MzUpload from "@/components/MzUpload/index.vue";

export default {
  components: {
    MzUpload,
    MzSubsection
  },
  data() {
    return {
      title: '我要留言',
      loading: true,
      staticImage: {
        bg: imghost + '/BG.png',
        newIcon: imghost + '/new-icon.png',
      },
      model:{
        questions_id:'',
        advisor_id:'',
        content:'',
        pictures:[]
      },
      rules:{
        'content': {
          type: 'string',
          required: true,
          message: '请填写问题',
          trigger: ['blur', 'change']
        },
      },
    }
  },
  onLoad(option) {
    this.model.advisor_id = option.id || '';
    this.model.questions_id = option.questions_id || '';
  },
  computed: {
    api() {
      return api
    },
  },
  methods: {
    submit(){
      console.log(this.model.pictures);
      this.$refs.feedForm.validate().then(res => {
        setQuestions(this.model).then((res) => {
          if(res.code === 200){
              uni.showLoading('留言中');
              uni.$u.sleep(1000).then(() => {
                uni.hideLoading();
                api.navTo('/pages/LeaveMsg/done'+((this.model.questions_id!=='')?'?type=advisor':''));
              })
          }else{
            uni.$u.toast(res.msg)
          }
        })
      }).catch(errors => {
        uni.$u.toast(errors[0].message)
      })
    },
  },
  onPageScroll(res) {
    if (res.scrollTop <= 20) {
      uni.$emit('isTop', true);
    } else {
      uni.$emit('isTop', false);
    }
  },
  created() {

  }
}
</script>

<style lang="scss">
@import './components/index.scss';
</style>