<!--
 * @Author: chris
 * @Date: 2026-01-06 17:17:48
 * @LastEditors: chris
 * @LastEditTime: 2026-01-19 15:52:08
-->
<template>
  <view class="changePassword-page">
    <wd-form ref="form" :model="model">
      <wd-cell-group border>
        <!-- <wd-input
          v-model="form.oldPwd"
          label="旧密码"
          label-width="100px"
          prop="oldPwd"
          show-password
          clearable
          placeholder="请输入旧密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        /> -->
        <wd-input
          v-model="form.newPwd"
          label="新密码"
          label-width="100px"
          prop="newPwd"
          show-password
          clearable
          placeholder="请输入新密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
      </wd-cell-group>
      <view class="footer">
        <wd-button type="primary" size="large" block @click="handleSubmit">
          提交
        </wd-button>
      </view>
    </wd-form>
  </view>
</template>

<script setup>
import { resetPassword } from '@/api/user'

const form = ref({
  // oldPwd: '',
  newPwd: '',
})

function handleSubmit() {
  // form.value.oldPwd = form.value.oldPwd.trim()
  resetPassword({
    userId: uni.getStorageSync('userId'),
    password: form.value.newPwd,
  }).then((res) => {
    if (res.code === 200) {
      uni.showToast({
        title: '密码重置成功',
        icon: 'success',
      })
      uni.navigateBack()
    }
    form.value.newPwd = form.value.newPwd.trim()
  })
}
</script>

<style lang="scss" scoped>
.changePassword-page {
  padding: 20rpx;

  .footer {
    margin-top: 40rpx;
  }
}
</style>
