<template>
  <div class="Transfer">
    <div class="contents">
      <u-form :model="forms" ref="uForm" label-width="auto" :border-bottom="false">
        <u-form-item label="转交给" prop="status" required :border-bottom="false" right-icon="arrow-right" class="first-form">
          <u-input v-model="forms.status" placeholder="请选择转交对象" />
        </u-form-item>

        <u-form-item label="办理意见" prop="content" :border-bottom="false" label-position="top" class="contents">
          <u-input v-model="forms.content" placeholder="请写下你的办理意见..." type="textarea" auto-height height="100" maxlength="500" />
        </u-form-item>

        <div class="line"></div>

        <u-form-item label="图片上传(最多9张)" prop="fileIds" :border-bottom="false" class="avatars" label-position="top">
          <AiUploader :def.sync="forms.fileIds" multiple placeholder="上传图片" :limit="9"></AiUploader>
        </u-form-item>
      </u-form>
    </div>

    <div class="btn" @click="submit">转交事件</div>
  </div>
</template>

<script>
export default {
  name: 'Transfer',
  components: {},
  props: {},
  data() {
    return {
      forms: {
        status: '',
        content: '',
        fileIds: [],
      },
      flag: false,
    }
  },
  computed: {},
  watch: {},
  onLoad() {},
  onShow() {},
  methods: {
    submit() {
      if (this.flag) return

      this.$refs.uForm.validate((valid) => {
        if (valid) {
          if (!this.forms.content) {
            return this.$u.toast('请选择转交人')
          }

          const imgs = []
          if (this.forms.fileIds) {
            this.forms.fileIds.map((e) => {
              imgs.push({ url: e.url, id: e.id })
            })
          }

          this.flag = true
          this.$http
            .post(`/app/appvisitvondolence/addOrUpdate`, {
              title: this.forms.title,
              content: this.forms.content,
              // images: JSON.stringify(imgs) || [],
              images: imgs || [],

              people: this.forms.people,
              phone: this.forms.phone,
              id: this.id,
            })
            .then((res) => {
              if (res.code == 0) {
                this.$u.toast('发布成功')
                this.flag = false
                uni.navigateTo({ url: `./AppHandSnapshot` })
              }
            })
        } else {
          this.$u.toast('失败')
        }
      })
    },
  },
}
</script>

<style scoped lang="scss">
.Transfer {
  height: 100%;
  .contents {
    ::v-deep .u-form {
      .u-form-item {
        padding: 0 45px !important;
        .u-form-item__body {
          .u-form-item--right__content__slot {
            padding-bottom: 0;
            .u-input {
              text-align: right !important;
            }
          }
        }
      }

      .u-form-item:first-child {
        .u-form-item__body {
          border-bottom: 1px solid #ddd;
        }
      }

      .line {
        height: 24px;
        background: #f3f6f9;
      }

      .contents {
        padding-bottom: 20px !important;
        .u-form-item__body {
          .u-form-item--right__content__slot {
            .u-input {
              text-align: left !important;
            }
          }
        }
      }

      .avatars {
        padding-bottom: 20px !important;
        .u-form-item__body {
          .default {
            width: 160px;
            height: 160px;
          }
        }
      }
    }
  }

  .btn {
    position: fixed;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    background: #3975c6;
    padding: 34px 0;
    text-align: center;
    font-size: 32px;
    font-weight: 500;
    color: #ffffff;
  }
}
</style>
