<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-02-21 15:10:27
 * @Description: file content
 * @FilePath: \frontend_mobile\pages\project\downgrade.vue
-->
<template>
  <view class="home">
    <view class="nav">
      <view :style="{ paddingTop }">
        <view class="title" :style="[{ height }, { lineHeight: height }]">
          <view class="back" @click="goBack()">
            <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
          </view>
          <text>项目降级</text>
        </view>
      </view>
    </view>
    <view class="main">
      <u-form :model="addForm" :rules="rules" ref="addForm" label-width="0">
        <u-form-item prop="nboType" borderBottom customStyle="padding:40rpx 0 30rpx">
          <view class="form-label flex_l">
            <view class="label-tag"></view>
            项目级别
          </view>
          <u-radio-group v-model="addForm.nboType" placement="row">
            <u-radio
              customStyle="margin-right:40rpx"
              :disabled="['10', '20'].includes(projectDetails.nboType)"
              label="A"
              name="10"></u-radio>
            <u-radio
              customStyle="margin-right:40rpx"
              :disabled="projectDetails.nboType === '20'"
              label="B"
              name="20"></u-radio>
            <u-radio customStyle="margin-right:40rpx" label="C" name="30"></u-radio>
            <u-radio v-if="projectDetails.nboType === '10'" label="储备" name="50"></u-radio>
          </u-radio-group>
        </u-form-item>
        <u-form-item borderBottom customStyle="padding:40rpx 0 30rpx">
          <view class="form-label flex_l">技术支持人员</view>
          <u-input
            placeholder="输入技术支持人员"
            v-model="addForm.technicalSupportName"
            border="none"
            suffixIconStyle="color:#CDCDCD"
            clearable
            customStyle="padding: 0 30rpx 0 12rpx"></u-input>
        </u-form-item>
        <u-form-item borderBottom customStyle="padding:40rpx 0 30rpx">
          <view class="form-label flex_l">
            <view class="label-tag"></view>
            技术支持内容
          </view>
          <u-input
            placeholder="输入技术支持内容"
            v-model="addForm.technicalSupportContent"
            border="none"
            suffixIconStyle="color:#CDCDCD"
            clearable
            customStyle="padding: 0 30rpx 0 12rpx"></u-input>
        </u-form-item>
        <u-form-item borderBottom customStyle="padding:40rpx 0 30rpx" @click="showSupportDate = true">
          <view class="form-label flex_l">技术支持时间</view>
          <u-input
            :readonly="true"
            placeholder="请选择技术支持时间"
            v-model="addForm.technicalSupportTime"
            border="none"
            suffixIcon="arrow-down"
            suffixIconStyle="color:#CDCDCD"
            clearable
            customStyle="padding: 0 30rpx 0 12rpx"></u-input>
        </u-form-item>
        <u-form-item prop="remark" customStyle="padding:40rpx 0 30rpx">
          <view class="form-label flex_l">
            <view class="label-tag"></view>
            备注原因
          </view>
          <u-textarea
            fontSize="26rpx"
            v-model="addForm.remark"
            placeholder="请输入备注原因"
            height="180"
            :count="true"
            maxlength="300"></u-textarea>
        </u-form-item>
      </u-form>
      <view class="save" @click="handleDowngrade">提交</view>
    </view>
    <!-- 技术支持时间 -->
    <u-datetime-picker
      v-if="showSupportDate"
      :show="showSupportDate"
      mode="datetime"
      v-model="addForm.technicalSupportTime"
      @cancel="showSupportDate = false"
      @confirm="pickSupportDate"></u-datetime-picker>
    <u-notify ref="uNotify"></u-notify>
    <u-toast ref="uToast"></u-toast>
    <u-modal
      :show="showModal"
      content="确认进行项目降级？"
      :showCancelButton="true"
      @cancel="this.showModal = false"
      @confirm="this.handleDownApi()"></u-modal>
  </view>
</template>
<script>
  import projectApi from '../../api/project'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    data() {
      return {
        height: '',
        paddingTop: '',
        showSupportDate: false, //技术支持时间
        addForm: {
          nboType: '', //项目及别
          technicalSupportName: '', //技术支持人员
          technicalSupportContent: null, //技术支持内容
          technicalSupportTime: '', //技术支持时间
          remark: '', //备注
          id: 0, //项目id
        },
        showModal: false,
        projectDetails: {},
        rules: {
          nboType: {
            type: 'string',
            required: true,
            message: '请选择项目级别',
            trigger: ['blur'],
          },
          // technicalSupportContent: {
          //   type: 'string',
          //   required: true,
          //   message: '请输入技术支持内容',
          //   trigger: ['blur'],
          // },
          remark: {
            type: 'string',
            required: true,
            message: '请输入备注内容',
            trigger: ['blur'],
          },
        },
      }
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    onLoad(option) {
      console.log(option.id) //打印出上个页面传递的参数。
      this.addForm.id = parseInt(option.id)
    },
    onShow() {
      this.getDetails()
    },
    methods: {
      async getDetails() {
        const [err, res] = await to(projectApi.getDetail({ id: this.addForm.id }))
        if (err) return
        if (res.code == 200) {
          this.projectDetails = res.data
          this.addForm = Object.assign(this.addForm, this.projectDetails)
          this.addForm.nboType = ''
          this.addForm.technicalSupportName = ''
          this.addForm.technicalSupportContent = ''
          this.addForm.technicalSupportTime = this.parseTime(new Date(), '{y}-{m}-{d} {h}:{i}')
          this.addForm.remark = ''
        }
      },
      // 时间
      async pickSupportDate(e) {
        this.showSupportDate = false
        const timeFormat = uni.$u.timeFormat
        let timeValue = await timeFormat(e.value, 'yyyy-mm-dd hh:MM')
        this.addForm.technicalSupportTime = timeValue
        console.log(timeValue)
      },
      handleDowngrade() {
        this.$refs.addForm
          .validate()
          .then(async () => {
            this.showModal = true
          })
          .catch((err) => {
            console.log(err)
            this.$refs.uNotify.show({
              top: this.height + this.paddingTop + 10,
              type: 'warning',
              message: err[0].message,
              duration: 1000 * 3,
            })
          })
      },
      async handleDownApi() {
        let params = this.addForm
        const [err, res] = await to(projectApi.downgrade(params))
        this.showModal = false
        if (err) return
        if (res && res.code == 200) {
          this.$refs.uToast.show({
            type: 'success',
            message: '提交成功',
            complete: () => {
              this.goBack()
            },
          })
        }
      },
      closeUser(user) {
        if (user) {
          console.log(user)
          this.addForm.userId = user.id
          this.addForm.userName = user.label
        }
      },
      goBack() {
        uni.navigateBack({
          //关闭当前页面，返回上一页面或多级页面。
          delta: 1,
        })
      },
    },
  }
</script>
<style>
  page {
    background: #f2f3f5;
  }
</style>
<style lang="scss" scoped>
  .home {
    padding-top: 188rpx;

    .nav {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 284rpx;
      background: #3e7ef8;
      .title {
        position: relative;
        text-align: center;
        font-size: 32rpx;
        font-weight: bold;
        color: #ffffff;
        .back {
          position: absolute;
          top: 0;
          bottom: 0;
          margin: auto;
          left: 70rpx;
          display: flex;
        }
      }
    }

    .main {
      position: absolute;
      width: 100%;
      height: calc(100vh - 188rpx);
      background: #ffffff;
      box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
      border-radius: 31rpx 31rpx 0 0;
      padding: 0 32rpx;
      overflow: auto;
      padding-bottom: 64rpx;
      .form-label {
        font-size: 32rpx;
        font-weight: bold;
        color: #323232;
        padding-bottom: 18rpx;
        .label-tag {
          width: 15rpx;
          height: 15rpx;
          background: #ff4d4f;
          border-radius: 50%;
          margin-right: 10rpx;
        }
      }
      .save {
        width: 569rpx;
        height: 92rpx;
        background: #3e7ef8;
        border-radius: 31rpx;
        margin: 116rpx auto 0;
        font-size: 32rpx;
        color: #ffffff;
        text-align: center;
        line-height: 92rpx;
      }
    }
  }
</style>
