<template>
  <view class="min-height bg-gray-light p-20">
    <view v-for="(item, index) in list" :key="index" class="card my-20 flex justify-between items-center"
          @click="selectData(item)">
      <text>{{ item.name }}</text>
      <uv-icon name="arrow-right"/>
    </view>
    <uv-popup ref="addPopup" mode="bottom" round="15" closeable>
      <view class="p-30">
        <text class="text-30">材料补充</text>
        <view class="mt-30">
          <uv-cell title="劳动合同第一页" :value="form.contactFirstPage ? '已上传' : '点击上劳动合同第一页'"
                   is-link
                   @click="uploadContactFirstPage">
          </uv-cell>
          <uv-cell title="劳动合同期限页" :value="form.contactExpirePage ? '已上传' : '点击上传劳动合同期限页'"
                   is-link
                   @click="uploadContactExpirePage">
          </uv-cell>
          <uv-cell title="劳动合同盖章页三页"
                   :value="form.contactSignPage ? '已上传' : '点击上传劳动合同盖章页三页'"
                   is-link
                   @click="uploadContactSignPage">
          </uv-cell>
          <uv-cell title="社保证明"
                   :value="form.socialSecurity ? '已上传' : '点击上传社保证明'"
                   is-link
                   @click="uploadSocialSecurity">
          </uv-cell>
          <view class="mt-30">
            <uv-button type="primary" shape="circle" @click="save" :disabled="disabled">保存</uv-button>
          </view>
        </view>
      </view>
    </uv-popup>
  </view>
</template>

<script setup>
import {ref} from 'vue'
import {onLoad} from "@dcloudio/uni-app";
import {signUpPeopleSelfListReq, signUpSelfUpdateReq, signUpUpdateReq} from "@/api/signUp";
import {$toast, chooseImg} from "@/utils";

const form = ref({})
const list = ref([])
const getList = async (ids) => {
  const {data} = await signUpPeopleSelfListReq({ids})
  list.value = data
}

const addPopup = ref()
const selectData = item => {
  form.value = item
  addPopup.value.open()
}

const disabled = ref(false)
const save = async () => {
  disabled.value = true
  await signUpSelfUpdateReq(form.value)
  disabled.value = false
  addPopup.value.close()
  $toast('保存成功')
}

const uploadContactFirstPage = async () => {
  const res = await chooseImg(1)
  form.value.contactFirstPage = res[0]
}

const uploadContactExpirePage = async () => {
  const res = await chooseImg(1)
  form.value.contactExpirePage = res[0]
}

const uploadContactSignPage = async () => {
  const res = await chooseImg(1)
  form.value.contactSignPage = res[0]
}

const uploadSocialSecurity = async () => {
  const res = await chooseImg(1)
  form.value.socialSecurity = res[0]
}

onLoad(({ids}) => {
  getList(ids)
})
</script>