<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-03-21 17:54:54
 * @Description: file content
 * @FilePath: \oms\pages\customer\transfer.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="transferObj" :rules="rules" ref="addForm" label-width="0">
        <u-form-item prop="salesName" borderBottom customStyle="padding:40rpx 0 30rpx" @click="$refs.user.open()">
          <view class="form-label flex_l">
            <view class="label-tag"></view>
            接收对象
          </view>
          <u-input
            v-model="transferObj.salesName"
            disabled
            disabledColor="#ffffff"
            placeholder="请选择接收对象"
            border="none"></u-input>
          <u-icon slot="right" name="arrow-right"></u-icon>
        </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-checkbox-group disabled v-model="transferObj.about" placement="row" customStyle="padding: 0 30rpx 0 12rpx">
            <u-checkbox label="客户" name="客户"></u-checkbox>
          </u-checkbox-group>
        </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="transferObj.remark"
            placeholder="请输入转移原因"
            height="180"
            :count="true"
            maxlength="300"></u-textarea>
        </u-form-item>
      </u-form>
      <view class="save" @click="handleAdd">保存</view>
    </view>
    <u-notify ref="uNotify"></u-notify>
    <u-toast ref="uToast"></u-toast>
    <select-user ref="user" :query-params="{ roles: ['SalesEngineer','ProductLineManager'] }" @close="closeUser($event)"></select-user>
  </view>
</template>
<script>
  import customerApi from '../../api/customer'
  import SelectUser from '../../components/SelectUser'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    components: { SelectUser },
    data() {
      return {
        height: '',
        paddingTop: '',
        transferObj: {
          remark: '',
          salesId: null, //接受的销售id、name
          salesName: '', //接受的销售id、name
          ids: [], //客户id
          about: ['客户'],
        },
        rules: {
          salesName: {
            type: 'string',
            required: true,
            message: '请选择转移对象',
            trigger: ['blur'],
          },
          remark: {
            type: 'string',
            required: true,
            message: '请输入转移原因',
            trigger: ['blur', 'change'],
          },
        },
      }
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    onLoad(option) {
      this.transferObj.ids = [parseInt(option.id)]
    },
    onShow() {},
    methods: {
      handleAdd() {
        this.$refs.addForm
          .validate()
          .then(async () => {
            let params = this.transferObj
            const [err, res] = await to(customerApi.transfer(params))
            if (err) return
            if (res && res.code == 200) {
              this.$refs.uToast.show({
                type: 'success',
                message: '转移成功',
                complete: () => {
                  this.goBack()
                },
              })
            }
          })
          .catch((err) => {
            this.$refs.uNotify.show({
              top: this.height + this.paddingTop + 10,
              type: 'warning',
              message: err[0].message,
              duration: 1000 * 3,
            })
          })
      },
      closeUser(user) {
        if (user) {
          this.transferObj.salesId = user.id
          this.transferObj.salesName = 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>
