index.vue 9.78 KB
<template>
  <view class="wrap">
    <view class="choose-type-box">
      <view class="choose-type-item" :class="item.isNow ? 'itemActive' : ''" v-for=" (item, index) in typeList"
        :key="index" @click="handlerClick(item)">
        <!-- <view class="choose-type-item-top" :class="item.classStyle">
          <view class="choose-type-item-image" width="100%" height="100%">
            <image :src="item.image" shape="circle" mode="aspectFill">
            </image>
          </view>
          <view class="choose-type-item-text">
            <view class="choose-type-item-text-right">
              <view v-if="item.company" class="choose-type-item-text-right-company">
                {{ item.company }}
              </view>
              <view class="choose-type-item-text-right-label">
                {{ item.label }}
              </view>
            </view>
          </view>
        </view>
        <view class="choose-type-item-bottom">
          <view class="choose-type-item-bottom-button"
            :class="item.isNow ? 'choose-type-item-bottom-button-active' : ''">
            {{ item.isNow ? '当前身份' : '切换此身份' }}
            <up-icon name="checkmark-circle-fill" :color="item.isNow ? '#19a97c' : ''" size="28"></up-icon>
          </view>
        </view> -->
        <view class="choose-type-item-img">
          <image :src="item.imageUrl" mode="aspectFill"></image>
        </view>
      </view>
    </view>
    <view class="choose-user-bottom-button-box">
      <view class="choose-user-bottom-button-box-button" @click="submit(userType)">
        下一步
      </view>
    </view>
  </view>
</template>

<script setup>
import { updateUserInfo } from "@/apis/user.js";
import driverImage from "@/static/image/driver.png";
import handleImage from "@/static/image/handler.png";
import managerImage from "@/static/image/manager.png";
import companyPngUrl from '@/static/image/role/company.png';
import disposalPngUrl from '@/static/image/role/disposal.png';
import handlerPngUrl from '@/static/image/role/handler.png';
import userPngUrl from '@/static/image/role/user.png';
import userImage from "@/static/image/user.png";
import { useMainStore } from '@/stores/index.js';
import { setRequestToken } from '@/utils/request/request.js';
import { onLoad } from "@dcloudio/uni-app";
import { ref } from 'vue';
const userType = ref('')
const store = useMainStore();
const typeList = ref([{
  label: "用户",
  info: '下单清运',
  image: userImage,
  order: 999,
  classStyle: 'choose-type-item-top-back-sky',
  isNow: false,
  isExit: true,
  imageUrl: userPngUrl
}, {
  label: "运输企业负责人",
  info: '负责订单处理',
  company: '',
  image: managerImage,
  isExit: false,
  classStyle: 'choose-type-item-top-back-sun',
  order: 1,
  isNow: false,
  imageUrl: companyPngUrl
}, {
  label: "清运车辆驾驶员",
  info: '负责垃圾清运',
  company: '',
  image: driverImage,
  isExit: false,
  classStyle: 'choose-type-item-top-back-blue',
  order: 2,
  isNow: false,
  imageUrl: handlerPngUrl
}, {
  label: "处置场所负责人",
  info: '负责现场指导',
  company: '',
  image: handleImage,
  isExit: false,
  classStyle: 'choose-type-item-top-back-pink',
  order: 3,
  isNow: false,
  imageUrl: disposalPngUrl
}])
const unitInfo = ref([])
const handlerClick = (val) => {
  if (val.isExit) {
    val.isNow = true;
    userType.value = val.label;
    typeList.value.forEach((item) => {
      if (val.label !== item.label) {
        item.isNow = false
      }
    })
  } else {
    // 提示 当前账号未绑定,无法选中
    uni.showToast({
      title: '账号未绑定,无法选中',
      icon: 'none',
      duration: 1500
    })
  }
}
const submit = (userType) => {
  // 临时token的作用是在用户为选择完身份时判断 如果用户为选择身份则不会把在请求中携带token
  if (store.tempToken) {
    setRequestToken(store.tempToken)
  }
  updateUserInfo({ garUserType: userType }).then(res => {
    if (res.data.success) {
      if (store.tempToken) {
        store.token = store.tempToken
        store.tempToken = "";
      }
      store.userType = userType;
      store.userInfo = unitInfo.value[userType]
      
    
      
     // #ifdef H5
      if("处置场所负责人" == userType){
          uni.$u.route({
            type: "switchTab",
            url: `pages/order/index`,
        })
      }else{
        uni.setStorageSync("refreshFlag",true);
        uni.$u.route({
            type: "switchTab",
            url: `/pages/home/index`,
        })
      }
     
      // #endif
      // #ifdef MP-WEIXIN
      uni.setStorageSync("refreshFlag",true);
      uni.switchTab({
        url: `/pages/home/index`
      })
      // #endif
    }
  })

}
onLoad((options) => {
  // let loginInfo = JSON.parse(options)
  let loginInfo = JSON.parse(decodeURIComponent(options.ruleVos))
  for (let index = 0; index < loginInfo.length; index++) {
    const element = loginInfo[index];
    unitInfo.value[element.userType] = element
  }
  let order = 999;
  let index = 0;
  let company = "";
  // typeList优先级最高的设置isNow 为 true
  if (loginInfo.length > 1) {
    typeList.value.forEach((item, i) => {
      if (unitInfo.value[item.label]) {
        item.isExit = true;
        if (item.order < order) {
          order = item.order;
          index = i;
          company = unitInfo.value[item.label].transportCompanyName;
        }
      }
    })
    typeList.value[index].isNow = true
    typeList.value[index].company = company
    userType.value = typeList.value[index].label
  } else {
    typeList.value[index].isNow = true
    userType.value = typeList.value[index].label
  }
})
</script>

<style lang="scss" scoped>
.wrap {
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  // padding: 20rpx;
  background-color: $u-info-light;
  background-color: white;
  padding-top: 100rpx;

  .choose-type-box {
    width: 750rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    padding: 20rpx 70rpx;

    .choose-type-item {
      width: 100%;
      height: 200rpx;
      // box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
      margin-bottom: 40rpx;
      // border-radius: 15rpx 15rpx 0rpx 0rpx;


      // .choose-type-item-top-back-blue {
      //   background: linear-gradient(135deg, #a1c4fd, #c2e9fb) !important;
      // }

      // .choose-type-item-top-back-pink {
      //   background: linear-gradient(135deg, #c7e9fb, #a6defa, #80d4f9, #5bc9f8, #35bef7) !important;
      // }

      // .choose-type-item-top-back-sun {
      //   background: linear-gradient(135deg, #f6d365, #fda085) !important;
      // }

      // .choose-type-item-top-back-sky {
      //   background: linear-gradient(135deg, #c2ef8c, #83e455) !important;
      // }

      // .choose-type-item-top {
      //   height: 235rpx;
      //   display: flex;
      //   align-items: center;
      //   box-sizing: border-box;
      //   padding: 30rpx;
      //   border-radius: 15rpx 15rpx 5rpx 5rpx;
      //   box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);

      //   .choose-type-item-image {
      //     width: 160rpx;
      //     height: 180rpx;
      //     border-radius: 50%;
      //     display: flex;
      //     align-items: center;
      //     justify-content: flex-start;
      //     margin-right: 50rpx;

      //     image {
      //       width: 100%;
      //       height: 100%;
      //       background-size: 100% 100%;
      //     }
      //   }

      //   .choose-type-item-text {
      //     width: 100%;
      //     height: 100%;

      //     .choose-type-item-text-right {
      //       width: 100%;
      //       height: 100%;
      //       display: flex;
      //       flex-direction: column;
      //       align-items: flex-start;
      //       justify-content: space-around;
      //       color: white;

      //       .choose-type-item-text-right-company {
      //         font-weight: bolder;
      //         font-size: 32rpx;
      //       }

      //       .choose-type-item-text-right-label {
      //         font-size: 30rpx;
      //         padding: 8rpx 15rpx;
      //         border-radius: 5rpx;
      //         color: $u-info-dark;
      //         font-weight: 600;
      //         margin-bottom: 10rpx;
      //         background: #ffffffad;
      //         border: 3rpx solid white;
      //       }
      //     }
      //   }

      // }

      // .choose-type-item-bottom {
      //   width: 100%;
      //   height: 35rpx;
      //   box-sizing: border-box;
      //   display: flex;
      //   align-items: center;
      //   justify-content: flex-end;
      //   background: #ffffff;

      //   .choose-type-item-bottom-button {
      //     font-size: 25rpx;
      //     color: #999999;
      //     display: flex;
      //   }

      //   .choose-type-item-bottom-button-active {
      //     color: #19a97c !important;
      //   }
      // }

      .choose-type-item-img {
        width: 100%;
        height: 100%;

        image {
          width: 100%;
          height: 100%;
          background-size: 100% 100%;
        }

      }


    }

    .itemActive {
      animation: overScroll 0.2s forwards ease-in-out;
    }

    @keyframes overScroll {

      100% {
        width: 110%;
        height: 210rpx;
        filter: drop-shadow(10px 10px 10px rgba(0, 0, 0, .5));
      }
    }

  }

  .choose-user-bottom-button-box {
    margin-top: 80rpx;
    width: 100%;
    height: 80rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;

    .choose-user-bottom-button-box-button {
      width: 80%;
      height: 100%;
      background: #23d283;
      border-radius: 30rpx;
      color: white;
      font-size: 30rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      @include handleClick;
    }
  }
}
</style>