<template>
  <view class="project-add cc-page-wrap">
    <project-add ref="projectAdd" :operateType="operateType" :projectId="projectId" />

    <view class="cc-card form-card" style="margin-top: 16px;">
      <view class="form-title">审核信息</view>
      <view class="form-item">
        <text class="form-label">审批人</text>
        <view class="form-content">
          <input v-model="checkForm.checkPerson" class="form-input" placeholder="请输入审批人" />
        </view>
      </view>
      <view class="form-item">
        <text class="form-label">审批时间</text>
        <view class="form-content">
          <input v-model="checkForm.checkTime" class="form-input" placeholder="请输入审批时间" />
        </view>
      </view>
      <view class="form-item">
        <text class="form-label">审批意见</text>
        <view class="form-content">
          <textarea v-model="checkForm.checkOpinion" class="form-input" placeholder="请输入审批意见" rows="3"></textarea>
        </view>
      </view>
    </view>

    <!-- <view v-if="operateType!=='see' && operateType!=='examineSee'" class="cc-operation-row operation-row">
      <view v-if="operateType==='edit'" class="buttons-group">
        <view class="button default-button" @click="handleSaveProject()">保存</view>
      </view>
      <view v-else-if="operateType==='add'" class="buttons-group">
        <view class="button primary-button" @click="handleSaveProject()">上报</view>
        <view class="button default-button" @click="handleSaveProjectDraft()">暂存</view>
      </view>
      <view v-else-if="operateType==='examine'" class="buttons-group">
        <view class="button primary-button" @click="handleSubmitCheck()">确定</view>
        <view class="button default-button" @click="handleCancelCheck()">取消</view>
      </view>
    </view> -->

    <view v-if="operateType=='edit'" class="cc-operation-row operation-row">
      <view class="buttons-group">
        <view class="button primary-button" @click="handleSubmitCheck()">确定</view>
        <view class="button default-button" @click="handleCancelCheck()">取消</view>
      </view>
    </view>

    <!-- 省市区选项 -->
    <cityPicker :column="column" :default-value="defaultValue" :mask-close-able="maskCloseAble" @confirm="confirm" @cancel="cancel" :visible="visible"/>
  </view>
</template>

<script>
import ProjectAdd from '@/components/project-add/project-add.vue'
export default {
  components: {
    ProjectAdd
  },
  data() {
    return {
      form: {
        id: null,
        isKeyProject: null,
        isPierceProject: null,
        isMajor: null,
        projectName: '',
        unitLeader: null,
        projectLegalPerson: '',
        projectLegalUnit: null,
        projectLegalPhone: '',

        projectSuperintendent: '',
        projectSuperintendentPhone: null,
        projectUnitLegal: '',
        projectUnitLegalPhone: '',

        engineeringGrade: '',
        engineeringPurposes: '',
        workCategory: null,
        constructionAddress: '',
        constructionMode: '',
        constructionNature: null,
        constructionContent: '',
        adcd: '',
        basin: null,
        projectType: '',
        // fundingSource: null,

        centralArrangedFunds: '',
        centralArrangedFundsRate: '',
        provincialFunding: '',
        provincialFundingRate: '',
        cityLevelFunds: '',
        cityLevelFundsRate: '',
        countyLevelFunds: '',
        countyLevelFundsRate: '',
        townshipInvestments: '',
        townshipInvestmentsRate: '',

        isMajorProject: '',
        investmentSubject: null,
        constructionPhase: null,
        fundingNumber: null,
        proCode: '',
        proNo: null,
        createUid: null,
        createTime: null,
        updateUid: null,
        updateTime: null,
        owerDept: null,
        pointLatitudeLongitudeList: null,
        lineLatitudeLongitudeList: null,
        allLatitudeLongitudeList: null,
        projectKinds: '',
      },
      projectTypes: ['建筑', 'IT', '教育', '制造业'], // 可根据实际项目类型进行扩展
      projectKindsOptions: [],
      engineeringGradeOptions: [],
      // 工程用途字典
      engineeringPurposesOptions: [],
      // 建设模式字典
      constructionModeOptions: [],
      // 建设性质字典
      constructionNatureOptions: [],
      isMajorProjectOptions: [],
      operateType: '',
      projectId: '',
      checkForm: {
        checkPerson: '',
        checkTime: '',
        checkOpinion: ''
      },

      // 省市区选项属性
      visible: false,
      maskCloseAble: true,
      str: '',
      defaultValue: '420103',
      column: 3,
    };
  },

  created () {
    this.projectId = this.$route.query.id
    this.operateType = this.$route.query.operateType
    if (this.operateType === 'view') {
      uni.setNavigationBarTitle({
        title: '查看申请'
      })
    } else if (this.operateType === 'edit') {
      uni.setNavigationBarTitle({
        title: '审批项目'
      })
    }
    this.getDicts("type_of_project").then((response) => {
      this.projectKindsOptions = response.data;
    })
    this.getDicts("engineering_grade").then((response) => {
      this.engineeringGradeOptions = response.data;
    })
    this.getDicts("project_purposes").then((response) => {
      this.engineeringPurposesOptions = response.data;
    })
    this.getDicts("Construction_mode").then((response) => {
      this.constructionModeOptions = response.data;
    })
    this.getDicts("CONSTRUCTION_NATURE").then((response) => {
      this.constructionNatureOptions = response.data;
    })
    this.getDicts("whether").then((response) => {
      this.isMajorProjectOptions = response.data;
    })
  },

  mounted() {
    // 在这里进行组件初始化的操作
    this.operateType = this.$route.query.operateType
    // uni.setNavigationBarTitle({
    //   title: 'xxxjiu'
    // })
  },

  methods: {
    // 处理选择行政区划的变化
    onRegionChange(e) {
      this.form.region = e.detail.value;
    },
    // 提交表单
    submitForm() {
      // 在这里处理表单提交的逻辑
      console.log("提交的表单数据：", this.form);
      // 你可以进行数据校验，提交到后端等操作
    },
    // 展开省市区选项
    handleOpenSelect() {
      this.visible = true
    },
    cancel () {
      this.visible = false
    },
    confirm (val) {
      console.log(val)
      this.str = JSON.stringify(val)
      this.form.area = val.name
      this.visible = false
    },

    // 判断必填项是否填写
    judgeAttrWrite() {
      // const requiredFields = ['projectName', 'adcd', 'proCode', 'projectKinds', 'projectLegalPerson', 'projectSuperintendent', 'projectLegalPhone', 'projectUnitLegal', 'projectUnitLegalPhone', 'projectType', 'engineeringGrade', 'engineeringPurposes', 'constructionAddress', 'constructionMode', 'constructionContent', 'centralArrangedFunds', 'centralArrangedFundsRate', 'provincialFunding', 'provincialFundingRate', 'cityLevelFunds', 'cityLevelFundsRate', 'countyLevelFunds', 'cityLevelFundsRate', 'townshipInvestments', 'townshipInvestmentsRate', 'isMajorProject'];
      // const isValid = requiredFields.every(field => Boolean(this.myObject[field]));

      // if (!isValid) {
      //   return false
      // } else {
      //   return true
      // }
    },

    // 新增项目
    handleSaveProject() {
      // if (!this.judgeAttrWrite()) {
      //   return
      // }
      // uni.showLoading({
      //   title: '加载中...',
      //   mask: true
      // })
      // projectAddApi(this.form).then(res => {
      //   uni.showToast({
      //     title: `操作成功`,
      //     icon: 'none'
      //   })
      //   uni.navigateTo({
      //     url: `/pages/project/list`
      //   });
      // })
      // 通过ref调用子组件的方法
      this.$refs.projectAdd.handleProjectAdd();
    },
    handleSaveProjectDraft() {
      uni.showToast({
        title: `新增项目草稿成功`,
        icon: 'none'
      });
      console.log(this.form)
    },
    handleSubmitCheck() {
      uni.showToast({
        title: `提交审核成功`,
        icon: 'none'
      });
    },
    handleCancelCheck() {
      uni.navigateBack()
    }
  }
};
</script>

<style lang="scss" scoped>
.project-add {
  padding: 16px 20px 96px 20px;
  .form-card {
    margin-bottom: 0;
  }
  // .form-card {
  //   background-color: white;
  //   padding: 20px;
  //   border-radius: 10px;
  //   box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  //   .form-title {
  //     font-size: 18px;
  //     padding-bottom: 16px;
  //   }
  //   .form-item {
  //     .form-label {
  //       font-size: 14px;
  //       color: #595959;
  //       margin-bottom: 6px;
  //       display: block;
  //     }
  //     margin-bottom: 20px;
  //     .form-content {
  //       position: relative;
  //       padding-bottom: 16px;
  //       border-bottom: 1px solid #f0f0f0;
  //       .form-input {
  //         width: 100%;
  //         height: 30px;
  //         border-radius: 5px;
  //         font-size: 14px;
  //         color: #333;
  //       }
  //       .form-select {
  //         position: absolute;
  //         bottom: 4px;
  //         right: 0;
  //         color: #00B39D;
  //       }
  //     }
  //   }
  // }
}



</style>
