<template>
  <div class="mydiy-form q-mt-lg">
    <div class="form1 diy-form-block">
      <h2 class="block-title q-mb-lg">專人服務</h2>
      <q-form class="q-gutter-md" ref="myform">
        <div class="row q-gutter-xl q-mb-lg q-pl-md" v-if="!$q.screen.xs">
          <q-input filled v-model="params.Name" label="如何稱呼您" class="col" lazy-rules
            :rules="[ val => val && val.length > 0 || '請填寫您的稱呼']" />
          <q-input filled v-model="params.Mobile" label="聯絡電話" class="col" lazy-rules
            :rules="[ val => val && val.length > 0 || '請填寫您的聯絡電話哦']" />
        </div>
        <div class="row q-mb-lg" v-if="$q.screen.xs">
          <q-input filled v-model="params.Name" label="如何稱呼您" class="col" lazy-rules
            :rules="[ val => val && val.length > 0 || '請填寫您的稱呼']" />
        </div>
        <div class="row q-mb-lg" v-if="$q.screen.xs">
          <q-input filled v-model="params.Mobile" label="聯絡電話" class="col" lazy-rules
            :rules="[ val => val && val.length > 0 || '請填寫您的聯絡電話哦']" />
        </div>
        <div class="row q-mb-lg">
          <q-input filled v-model="params.EMail" label="聯絡E-Mail" class="col" lazy-rules
            :rules="[ val => val && val.length > 0 || '請填寫您的聯絡E-Mail哦']" />
        </div>
        <div class="row q-mb-lg">
          <q-input filled v-model="params.Remarks" label="備註" class="col" type="textarea" />
        </div>
        <div class="row q-mb-lg">
          <q-btn type="submit" unelevated color="primary" style="margin-top:10px;" size="lg" label="送出" class="col"
            @click="onSubmit" />
        </div>
      </q-form>
    </div>
  </div>
</template>

<script>
  export default {
    props: ["TCID"],
    data() {
      return {
        showLoading: false,
        params: {
          Name: "",
          Mobile: "",
          EMail: "",
          Remarks: "",
          RB_Group_Id: 0,
          CreateBy: 0,
          TCID: 0,
        }
      };
    },
    methods: {
      onSubmit() {
        if (localStorage.b2bUser) {
          var b2bUser = JSON.parse(window.localStorage.getItem('b2bUser'))
          if (b2bUser) {
            this.params.CreateBy = b2bUser.customerId;
            var jObj = JSON.parse(window.localStorage.getItem('groupinfo'));
            this.params.RB_Group_Id = jObj.GroupId;
            this.params.TCID = this.TCID;
            if (this.params.Name == '') {
              this.$q.notify({
                type: 'negative',
                message: '請填寫您的稱呼',
                position: 'top',
                timeout: 2000, // 以毫秒为单位; 0意味着没有超时
              })
              return;
            }
            if (this.params.Mobile == '') {
              this.$q.notify({
                type: 'negative',
                message: '請填寫您的聯絡電話哦',
                position: 'top',
                timeout: 2000, // 以毫秒为单位; 0意味着没有超时
              })
              return;
            }
            if (this.params.EMail == '') {
              this.$q.notify({
                type: 'negative',
                message: '請填寫您的聯絡E-Mail',
                position: 'top',
                timeout: 2000, // 以毫秒为单位; 0意味着没有超时
              })
              return;
            }
            this.$q.loading.show();
            this.apipost(
              "ws_post_SetService", this.params,
              res => {
                this.$q.loading.hide();
                if (res.data.resultCode == 1) {
                  this.params.Name = '';
                  this.params.Mobile = '';
                  this.params.EMail = '';
                  this.params.Remarks = '';
                  this.$q.notify({
                    color: "green-4",
                    textColor: "white",
                    icon: "cloud_done",
                    message: "提交成功",
                    position:'center',
                    timeout: 1000, // 以毫秒为单位; 0意味着没有超时
                  });
                  this.$refs.myform.resetValidation();
                  this.$emit('closeDialog')
                }
              },
              err => {}
            );
          } else {
            this.$q.notify({
              color: "green-4",
              textColor: "white",
              icon: "cloud_done",
              message: "请登录后再提交需求单"
            });
            this.CommonJump('/login', {});
          }
        } else {
          this.$q.notify({
            color: "green-4",
            textColor: "white",
            icon: "cloud_done",
            message: "请登录后再提交需求单"
          });
          this.CommonJump('/login', {});
        }
      }
    }
  };

</script>

<style>
  .mydiy-form {
    margin-top: 0 !important;
  }

  .mydiy-form .q-mb-lg {
    margin-bottom: 0;
  }
  .mydiy-form .q-gutter-md{
    margin-top:0!important;
  }
  .form1 .block-title {
    font-size: 24px;
    font-weight: 600;
    padding: 0;
    margin: 0;
    margin-bottom: 20px;
    line-height: unset;
  }

  .diy-form-block {
    width: 100%;
    margin: 0 auto;
    max-width: 1200px;
  }

  .mydiy-form .q-field--with-bottom {
    padding-bottom: 14px;
  }
  .mydiy-form .q-textarea.q-field--labeled .q-field__control-container{
    padding-top:15px!important;
  }

</style>
