<template>
  <view class="page-wrapper global-wrapper bgF2">
    <JHeaderTitle title="编辑代理商信息" bgColor="#f2f2f2" />
    <JMainCard pd="0" wrapPd="30rpx">
      <JInput
        v-model:value="agentInfo.agentName"
        name="代理商全称"
        place="请输入代理商全称"
        :rules="{ name: 'agentName', rule: 'REG_NotNUll' }"
        :isBorder="true"
      ></JInput>
      <JInput
        v-model:value="agentInfo.agentShortName"
        name="代理商简称"
        place="请输入代理商简称"
        :rules="{ name: 'agentShortName', rule: 'REG_NotNUll' }"
      ></JInput>
    </JMainCard>
    <JMainCard wrapPd="0 30rpx" pd="0">
      <JInput
        v-model:value="agentInfo.contactName"
        name="联系人姓名"
        place="请输入联系人姓名"
        :rules="{ name: 'contactName', rule: 'REG_NotNUll' }"
        :isBorder="true"
      ></JInput>
      <JInput
        v-model:value="agentInfo.contactTel"
        name="联系人手机号"
        place="请输入联系人手机号"
        :rules="{ name: 'contactTel', rule: 'REG_NotNUll' }"
      ></JInput>
      <JInput v-model:value="agentInfo.contactEmail" name="联系人邮箱" place="请输入联系人邮箱"></JInput>
    </JMainCard>
    <JMainCard pd="0" wrapPd="30rpx">
      <JInput v-model:value="agentInfo.remark" name="备注" place="请输入备注" :isBorder="true"></JInput>
    </JMainCard>

    <JButton size="max" pd="30rpx" @HandleTouch="saveAgent" pdTop="0">保存</JButton>
  </view>
</template>

<script setup>
import { ref, reactive, nextTick } from "vue"
import { onShow, onLoad } from "@dcloudio/uni-app"
import JHeaderTitle from "@/components/newComponents/JHeaderTitle/JHeaderTitle"
import JMainCard from "@/components/newComponents/JMainCard/JMainCard"
import JInput from "@/components/newComponents/JInput/JInput"
import JButton from "@/components/newComponents/JButton/JButton"
import { $editAgent, $findAgent } from "@/http/apiManager.js"
import { validateArray } from "@/hooks/rules" //校验函数

onLoad((options) => {
  if (options.agentNo) return getInfo(options.agentNo)
})
const agentInfo = ref({})
const getInfo = (val) => {
  $findAgent(val).then(({ bizData }) => {
    agentInfo.value = bizData
  })
}
const saveAgent = () => {
  if (validateArray(agentInfo.value)) {
    $editAgent(agentInfo.value.agentNo, agentInfo.value).then((res) => {
      uni.showToast({
        title: "保存成功",
        icon: "success",
      })
      uni.navigateBack()
    })
  }
}
</script>

<style lang="scss" scoped>
.page-wrapper {
  .place-text {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    font-size: 33rpx;
    color: #a6a6a6;
    image {
      width: 40rpx;
      height: 40rpx;
      transform: translateX(20rpx);
    }
  }
  .selected-text {
    color: #000;
  }
}
.team-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  image {
    width: 40rpx;
    height: 40rpx;
  }
  view {
    display: flex;
    align-items: center;
    image {
      width: 93rpx;
      height: 93rpx;
      margin-right: 15rpx;
    }
    view {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      font-size: 33rpx;
      font-weight: 700;
      text {
        margin-top: 10rpx;
        font-size: 25rpx;
        font-weight: 500;
        color: #8c8c8c;
      }
    }
  }
}
</style>
