<template>
  <div class="Transfer">
    <u-navbar back-icon-color="#000" title="事件上报" title-color="#000" title-width="300" title-size="32" 
      :title-bold="true" :background="backgroundNavbar" :is-fixed="true" height="44"></u-navbar>
    <div class="header-content-bg">
      <img src="https://cdn.sinoecare.com/i/2024/07/12/6690a1303d423.png" alt="">
    </div>
    <div class="contents">
      <u-form :model="forms" ref="uForm" label-width="auto" :border-bottom="false">
        <div class="border-r">
          <u-form-item label="转交给" prop="status" required :border-bottom="false" class="border" right-icon="arrow-right" v-if="status == 1">
            <u-input v-model="forms.name" placeholder="请选择转交人员" disabled @click="toSelectUser" />
          </u-form-item>
          <u-form-item label="事件分类" prop="groupName" required :border-bottom="false" class="border" right-icon="arrow-right" v-if="status != 1">
            <!-- <u-input v-model="forms.groupName" placeholder="请选择事件分类"  /> -->
            <span @click="show = true" class="right-span" :style="forms.groupName ? '' : 'color:#999;'">{{ forms.groupName || '请选择事件分类' }}</span>
            <u-select v-model="show" :list="myList" value-name="id" label-name="groupName" @confirm="selectStatus"></u-select>
          </u-form-item>
          <u-form-item :label="status == 3 ? '办结意见' : status == 2 ? '拒绝受理意见' : '办理意见'" prop="content" required :border-bottom="false" label-position="top"
            class="form-contents">
            <u-input v-model="forms.content" :placeholder="status == 2 ? '请写下拒绝受理意见…' : '请写下你的办结意见...'" type="textarea" auto-height height="100" maxlength="500"/>
          </u-form-item>
        </div>
        <div class="border-r">
          <u-form-item label="图片上传(最多9张)" prop="files" :border-bottom="false" class="avatars" label-position="top">
            <AiUploader :def.sync="forms.files" multiple placeholder="上传图片" :limit="9" action="/admin/file/add2"></AiUploader>
          </u-form-item>
        </div>

      </u-form>
    </div>

    <!-- <div class="btn" v-if="this.status == 1" @click="confirm">
      <span>转交事件</span>
    </div>

    <div class="btn" v-if="this.status == 2" @click="confirm">
      <span>拒绝受理</span>
    </div>

    <div class="btn" v-if="this.status == 3" @click="confirm">
      <span>我已办结</span>
    </div> -->
    <div class="footer" @click="confirm">
      <div class="btn">{{titleList[status]}}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Content',
  customNavigation: true,
  data() {
    return {
      forms: {
        groupName: '',
        groupId: '',
        content: '',
        files: [],
        name: ''
      },
      flag: false,
      show: false,
      status: '',  //1转交  2拒绝受理  3我已办结
      myList: [],
      id: '',
      selectUser: {},
      titleList: ['', '转交事件', '拒绝受理', '我已办结'],
      backgroundNavbar: {
        background: 'url(https://cdn.sinoecare.com/i/2024/07/12/6690a1309c7d3.png) no-repeat',
        backgroundSize: 'cover',
      },
    }
  },
  onLoad(option) {
    this.status = option.status
    this.id = option.id
    this.forms.groupId = option.groupId
    this.forms.groupName = option.groupName
    this.typeList()
    uni.$on('goback', (res) => {
      this.selectUser = res
      this.forms.girdId = res.girdId
      this.forms.girdName = res.girdName
      this.forms.girdMemberId = res.id
      this.forms.girdMemberName = res.name
      this.forms.name = `${res.girdName}${res.name ? '-' + res.name : ''}`
    })
  },
  onShow() {
    // document.title = this.titleList[this.status]
  },
  methods: {
    typeList() {
      this.$instance.post(`/app/apppatrolreportgroupv2/list`, null, {
        params: {
          size: 9999,
        },
      })
      .then((res) => {
        if (res.code == 0) {
          this.myList = res.data.records
          this.$forceUpdate()
        }
      })
    },

    confirm() {
      if(this.flag) return
      if (this.status == 1 && !this.forms.name) {
        return this.$u.toast('请选择转交对象')
      }
      if (this.status != 1 && !this.forms.groupName) {
        return this.$u.toast('请选择分类')
      }
      if (this.status != 1 && !this.forms.content) {
        return this.$u.toast('请输入意见')
      }
      this.flag = true
      this.submit()
    },
    submit() {  //status 1转交  2拒绝受理  3我已办结
      var url = '', successText = '', params = ''
      if (this.status == 1) {
        url = `/app/apppatrolreportinfov2/transfer`
        successText = '转交成功'
        params = {
          ...this.forms,
          // girdId: this.selectUser.id,
          // girdName: this.selectUser.girdName,
        }
        // if (this.selectUser.name) { //选择的网格员
        //   params.girdId = this.selectUser.girdId
        //   params.girdMemberId = this.selectUser.id
        //   params.girdMemberName = this.selectUser.name
        // }
      }
      if (this.status == 2) {
        url = `/app/apppatrolreportinfov2/finish`
        successText = '拒绝成功'
        params = {...this.forms, eventStatus: 0}
      }
      if (this.status == 3) {
        url = `/app/apppatrolreportinfov2/finish`
        successText = '办结成功'
        params = {...this.forms, eventStatus: 1}
      }
      params.id = this.id
      this.$instance.post(url, params).then((res) => {
        if (res.code == 0) {
          this.$u.toast(successText)
          uni.$emit('updateDeatil')
          uni.$emit('getListInit')
          setTimeout(() => {
            if (this.status == 1) {
              uni.navigateBack({delta: 2})
            } else {
              uni.navigateBack()
            }
          }, 600)
        }
      })
    },
    selectStatus(e) {
      this.forms.groupName = e[0].label
      this.forms.groupId = e[0].value
    },
    toSelectUser() {
      uni.navigateTo({url: `./SelectUser?detailId=${this.id}`})
    },
  },
}
</script>

<style scoped lang="scss">
.Transfer {
  height: 100%;
  .header-content-bg {
    width: 100%;
    position: fixed;
    z-index: -1;
    img {
      width: 100%;
      height: 592px;
    }
  }
  .border-r {
    border-radius: 16px;
    margin-bottom: 32px;
    background-color: #fff;
  }
  .contents {
    width: calc(100% - 64px);
    margin: 16px 0 0 32px;
    padding-bottom: 252px;
  }
  ::v-deep .u-form {
    .u-form-item {
      padding-left: 32px;
      padding-right: 32px;

      .u-form-item__body {
        .u-form-item--right__content__slot {
          padding-bottom: 0;

          .u-input {
            text-align: right !important;
          }
        }
      }
    }
    .form-contents {
      padding-bottom: 20px !important;
      .u-form-item__body {
        .u-form-item--right__content__slot {
          .u-input {
            text-align: left !important;
          }
        }
      }
    }
  }
  .border {
    ::v-deep .u-form-item {
      border-bottom: 1px solid #ddd;
    }
  }
  .avatars {
    padding-bottom: 20px !important;
  }
  ::v-deep .u-form-left__content--required {
    font-size: 32px!important;
  }
  .footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    background-color: #F4F5FA;
    padding: 64px 64px 68px 64px;
    z-index: 9;
    .btn {
      width: calc(100% - 128px);
      line-height: 88px;
      background: #026AF2;
      border-radius: 44px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #FFF;
      text-align: center;
    }
  }
  .right-span {
    display: inline-block;
    width: 100%;
    text-align: right;
  }
  ::v-deep .AiPagePicker {
    width: 100%;
    text-align: right;
  }
}
</style>
