<template>
    <div class="inventoryReview">
      <ul class="detailUl">
        <li class="detailLi">
          <span class="liName">
            <span style="color: red;margin-right: 5rpx">*</span>
            企业名称
          </span>
          <div class="inputBox">
            <input v-model="form.qymc" disabled class="myIpt">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            <span style="color: red;margin-right: 5rpx">*</span>
            统一社会信用代码
          </span>
          <div class="inputBox">
            <input v-model="form.shxydm" disabled class="myIpt">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            注册资金（万元）
          </span>
          <div class="inputBox">
            <input v-model="form.zczj" disabled class="myIpt">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            币种
          </span>
          <div class="inputBox" @tap="showArea('币种')">
            <input placeholder="" v-model="form.currencyStr" disabled class="myIpt">
            <van-icon name="arrow" />
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            注册时间
          </span>
          <div class="inputBox" @tap="showTime">
<!--            <input placeholder="" v-model="form.zcsj" disabled class="myIpt">-->
            <span class="myIpt">{{ form.zcsj }} </span>
            <van-icon name="arrow" />
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            法定代表人
          </span>
          <input class="myIpt" value="256" disabled style="padding-right: 30rpx" v-model="form.fddbr">
        </li>
        <li class="detailLi">
          <span class="liName">
            法人电话
          </span>
          <div class="inputBox">
            <input disabled class="myIpt" v-model="form.legalPersonPhone">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            法人邮箱
          </span>
          <div class="inputBox">
            <input disabled class="myIpt" v-model="form.frEmail">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
            企业联系人
          </span>
          <div class="inputBox">
            <input disabled class="myIpt" v-model="form.qylxr">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
            联系人手机
          </span>
          <div class="inputBox">
            <input disabled class="myIpt" v-model="form.lxdh">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
            联系人邮箱
          </span>
          <div class="inputBox">
            <input disabled class="myIpt" v-model="form.email">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
            财务负责人
          </span>
          <div class="inputBox">
            <input disabled class="myIpt" v-model="form.cwfzr">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
            负责人电话
          </span>
          <div class="inputBox">
            <input  disabled class="myIpt" v-model="form.cwfzrdh">
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            注册地址
          </span>
          <div class="moreLineBox">
            {{ form.zcdz }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            经营地址
          </span>
          <div class="moreLineBox">
            {{ form.jydz }}
          </div>
        </li>
        <li class="detailLi2" >
          <div class="titleBox" >
            <span class="liName">经营范围</span>
          </div>
          <van-field
              :value="form.jyfw"
              autosize
              type="textarea"
              class="myField"
              readonly
          />
        </li>
        <li class="detailLi2" >
          <div class="titleBox" style="margin-bottom: 24rpx">
            <span class="liName">
            <span style="color: red;margin-right: 5rpx">*</span>
              营业执照
            </span>
          </div>
          <van-uploader
              :max-count="9"
              @delete="deleteRYXXZP"
              @after-read="uploadRYXXZP"
              :show-upload="true"
              :file-list="fileList"
          />
        </li>
        <li class="detailLi2" >
          <div class="titleBox" >
            <span class="liName">荣誉信息</span>
          </div>
          <van-field
              autosize
              type="textarea"
              class="myField"
              style="margin-bottom: 24rpx"
              readonly
          />
          <van-uploader
              :max-count="6"
              @delete="deleteRYXXZP1"
              :file-list="fileList1"
              @after-read="uploadRYXXZP1"
              :show-upload="true"
          />
          <span style="color: #B3B3B3;font-size: 28rpx">（只能上传jpg/png格式，限制上传6张）</span>
        </li>
        <li class="detailLi2" >
          <div class="titleBox" style="margin-bottom: 24rpx">
            <span class="liName">
              法人身份证
             <span style="color: #B3B3B3;font-size: 28rpx">（只能上传jpg/png格式，限制上传6张）</span>
            </span>
          </div>
          <van-uploader
              :max-count="6"
              @delete="deleteRYXXZP2"
              :file-list="fileList2"
              @after-read="uploadRYXXZP2"
              :show-upload="true"
          />
        </li>
        <li class="detailLi2" style="position:relative;">
          <div class="titleBox" >
            <span class="liName">主营业务</span>
          </div>
          <van-field
              :value="form.business"
              autosize
              type="textarea"
              class="myField"
              readonly
          />
        </li>
        <li class="detailLi">
          <span class="liName">
            全年研发投入（万元）
          </span>
          <div class="moreLineBox">
            {{ form.rdInvestment || ''}}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            全年技改投入（万元）
          </span>
          <div class="moreLineBox">
            {{ form.jgInvestment || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            发明专利（件）
          </span>
          <div class="moreLineBox">
            {{ form.inventionPatent || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
             软件著作（件）
          </span>
          <div class="moreLineBox">
            {{ form.softwareWorks || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
             实用新型专利（件）
          </span>
          <div class="moreLineBox">
            {{ form.utilityModel || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
              集成电路布图设计专有权（件）
          </span>
          <div class="moreLineBox">
            {{ form.integratedCircuit || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
              四技合同金额-开发（万元）
          </span>
          <div class="moreLineBox">
            {{ form.fourOpennessAmount || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
             四技合同金额-转让（万元）
          </span>
          <div class="moreLineBox">
            {{ form.fourTransferenceAmount || '' }}
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
             四技合同金额-服务（万元）
          </span>
          <div class="moreLineBox">
            {{ form.fourServiceAmount || '' }}
          </div>
        </li>
        <li class="detailLi" style="border-bottom: none">
          <span class="liName">
              四技合同金额-咨询（万元）
          </span>
          <div class="moreLineBox">
            {{ form.fourConsultAmount || '' }}
          </div>
        </li>
      </ul>
      <ul class="detailUl">
        <li class="detailLi2">
          <span class="liName">
            <span style="color: red;margin-right: 5rpx">*</span>
            入驻类型
          </span>
          <van-radio-group :value="settleInType" @change="onChange">
            <van-radio
                :name="item.value"
                checked-color="#976CEB"
                v-for="item in settleInTypeList"
                :key="item.value"
            >{{ item.label }}</van-radio
            >
          </van-radio-group>
        </li>
        <li class="detailLi">
          <span class="liName">
            招商经理
          </span>
          <div class="inputBox">
            <input placeholder="" v-model="form.investmentManagerName" disabled class="myIpt">
            <van-icon name="arrow" />
          </div>
        </li>
        <li class="detailLi">
          <span class="liName">
            关联企业
          </span>
          <div class="inputBox" style="border-bottom: none">
            <input placeholder="" v-model="form.associationCompanyName" disabled class="myIpt">
            <van-icon name="arrow" />
          </div>
        </li>
      </ul>
      <ul class="detailUl">
        <li class="detailTitle">审核结果</li>
        <li class="detailLi">
          <span class="liName">
            <span style="color: red;margin-right: 5rpx">*</span>
            处理结果
          </span>
          <van-radio-group :value="radio2" @change="onChange2">
            <van-radio name="1">通过</van-radio>
            <van-radio name="2">不通过</van-radio>
          </van-radio-group>
        </li>
        <li class="detailLi2" style="position:relative;border-bottom: none">
          <div class="titleBox" >
            <span class="liName">处理意见</span>
          </div>
          <van-field
              @change="onChange3"
              :value="form.handleOpinions"
              autosize
              type="textarea"
              class="myField"
          />
        </li>
      </ul>
      <div class="buttonBox">
        <button class="btn zcBtn" @click="cancel">取消</button>
        <button class="btn tjBtn" @click="confirmSubmit()">提交审核</button>
      </div>
      <van-popup
          :show="show"
          position="bottom"
          custom-style="height: 50%;"
      >
        <van-picker v-show="popType==='币种'" :columns="currencyList" show-toolbar @cancel="show=false" @confirm="onConfirm" value-key="label"/>
      </van-popup>
      <van-popup
          :show="timeShow"
          position="bottom"
          custom-style="height: 50%;"
      >
        <van-datetime-picker
            type="date"
            :value="currentDate"
            :formatter="formatter"
            @cancel="timeShow=false"
            @confirm="selectTime"
        />
      </van-popup>
    </div>
</template>

<script>
import { getUserLocalStorageInfo,getByCodes,companyExamineGetById,companyExamineExamine,getAllBaseCompany } from "@/js_sdk/http";

export default {
  name: "inventoryReview",
  onLoad(options){
    console.log('options:',options)
    this.id = options.id
    this.proveType = options.proveType
    this.getById()
    this.getByCodes()
    this.getCompanyList()
  },
  data(){
    return{
      dc_key: ['MNP_BUILDING_TYPE', 'CURRENCY'],
      form:{
      },
      radio: '',
      radio2: '',
      id: '',
      proveType: '',
      fileList: [],
      fileList1: [],
      fileList2: [],
      settleInType:'',
      settleInTypeList: [],
      dic_SelectList: [],
      currencyList: [],
      show:false,
      popType:'',
      timeShow: '',
      currentDate: new Date().getTime(),
      companyOptions: []
    }
  },
  methods:{
    getById(){
      const data = {
        id: this.id
      }
      companyExamineGetById(data).then(res=>{
        if(res){
          this.form = res
          this.form.currencyStr = this.form.currency == null ? ' ' : this.getDicType("bizhong", this.form.currency)
          this.settleInType = res.settleInType
          if (res.yyzzfbzp) {
            res.yyzzfbzp.split(',').forEach(id=>{
              this.fileList.push({
                imgUrl: "/FileController/download/" + id,
                id: id,
                url:
                    this.$constant.BASE_URI +
                    "/FileController/download/" +
                    id,
                isImage: true,
              });
            })
          }
          if (res.ryxxzp) {
            res.ryxxzp.split(',').forEach(id=>{
              this.fileList1.push({
                imgUrl: "/FileController/download/" + id,
                id: id,
                url:
                    this.$constant.BASE_URI +
                    "/FileController/download/" +
                    id,
                isImage: true,
              });
            })
          }
          if (res.frsfzh) {
            res.frsfzh.split(',').forEach(id=>{
              this.fileList2.push({
                imgUrl: "/FileController/download/" + id,
                id: id,
                url:
                    this.$constant.BASE_URI +
                    "/FileController/download/" +
                    id,
                isImage: true,
              });
            })
          }
        }
      })
    },
    async getByCodes() {
      let data = await getByCodes(JSON.stringify(this.dc_key));
      this.dic_SelectList = this.$common.handleDicList(data);
      this.settleInTypeList = this.dic_SelectList.MNP_BUILDING_TYPE
      this.currencyList = this.dic_SelectList.CURRENCY

    },
    getDicType(type, value) {
      if (type == "bizhong" && this.dic_SelectList.CURRENCY) {
        let CURRENCY = this.dic_SelectList.CURRENCY;
        let index = CURRENCY.findIndex((e) => e.value == value);
        return CURRENCY[index].label;
      }
    },
    onChange(event) {
      this.form.settleInType = event.detail
    },
    onChange2(event) {
      console.log(event)
      this.form.state = event.detail
    },
    onChange3(event) {
      console.log(event)
      this.form.handleOpinions = event.detail
    },
    deleteRYXXZP(event) {
      this.fileList.splice(event.detail.index, 1);
      this.$forceUpdate();
    },
    uploadRYXXZP(event) {
      console.log(event)
      let that = this;
      const { file } = event.detail;
      uni.uploadFile({
        url: that.$constant.BASE_URI + "/wx/fileController/upload",
        filePath: file.url,
        name: "file",
        formData: { user: "test" },
        success(res) {
          // 上传完成需要更新 fileList
          let data = JSON.parse(res.data);
          that.fileList.push({
            id: data.data[0],
          });
        },
        fail(res) {},
      });
    },
    deleteRYXXZP1(event) {
      this.fileList1.splice(event.detail.index, 1);
      this.$forceUpdate();
    },
    uploadRYXXZP1(event) {
      console.log(event)
      let that = this;
      const { file } = event.detail;
      uni.uploadFile({
        url: that.$constant.BASE_URI + "/wx/fileController/upload",
        filePath: file.url,
        name: "file",
        formData: { user: "test" },
        success(res) {
          // 上传完成需要更新 fileList
          let data = JSON.parse(res.data);
          that.fileList1.push({
            id: data.data[0],
          });
        },
        fail(res) {},
      });
    },
    deleteRYXXZP2(event) {
      this.fileList2.splice(event.detail.index, 1);
      this.$forceUpdate();
    },
    uploadRYXXZP2(event) {
      console.log(event)
      let that = this;
      const { file } = event.detail;
      uni.uploadFile({
        url: that.$constant.BASE_URI + "/wx/fileController/upload",
        filePath: file.url,
        name: "file",
        formData: { user: "test" },
        success(res) {
          // 上传完成需要更新 fileList
          let data = JSON.parse(res.data);
          that.fileList2.push({
            id: data.data[0],
          });
        },
        fail(res) {},
      });
    },
    cancel(){
      uni.navigateBack({})
    },
    confirmSubmit(){
      const _this = this
      // 通过才校验
      if(_this.form.state == '1'){
        if (!_this.form.qymc){
          this.$showToast('请输入企业名称')
          return
        }
        if (!_this.form.shxydm){
          this.$showToast('请输入统一社会信用代码')
          return
        }
        if (!_this.form.qylxr){
          this.$showToast('请输入企业联系人')
          return
        }
        if (!_this.form.lxdh){
          this.$showToast('请输入联系人手机')
          return
        }
        if (!_this.form.email){
          this.$showToast('请输入联系人邮箱')
          return
        }
        if (!_this.form.cwfzr){
          this.$showToast('请输入财务负责人')
          return
        }
        if (!_this.form.cwfzrdh){
          this.$showToast('请输入财务负责人电话')
          return
        }
        if (!_this.form.yyzzfbzp){
          this.$showToast('请上传营业执照')
          return
        }
        if (!_this.form.settleInType){
          this.$showToast('请选择入驻类型')
          return
        }
        if (!_this.form.state){
          this.$showToast('请选择处理结果')
          return
        }
      }
      if (this.fileList.length > 0){
        let yyzzfbzp = []
        this.fileList.forEach(e=>{
          yyzzfbzp.push(e.id)
        })
        this.form.yyzzfbzp = yyzzfbzp.toString()
      }

      if (this.fileList1.length > 0){
        let ryxxzp = []
        this.fileList1.forEach(e=>{
          ryxxzp.push(e.id)
        })
        this.form.ryxxzp = ryxxzp.toString()
      }

      if (this.fileList2.length > 0){
        let qylbbq = []
        this.fileList2.forEach(e=>{
          qylbbq.push(e.id)
        })
        this.form.qylbbq = qylbbq.toString()
      }
      const data = {
        id: _this.id,
        state: _this.form.state,
        proveType: _this.proveType,
        handleOpinions: _this.form.handleOpinions,
        examineUserId: getUserLocalStorageInfo().userId,
      }
      companyExamineExamine(data).then(res=>{
        if(res.code == '200'){
          this.$showToast("审核成功");
          this.cancel()
        }else {
          this.$showToast(res.msg);
        }
      })

    },
    showArea(e){
      this.popType = e
      this.show = true
    },
    onConfirm(e){
      console.log(e)
      switch (this.popType) {
        case "币种":
          this.form.currency = e.detail.value.label
          break;
      }
      this.show = false
    },
    showTime(){
      this.timeShow = true
    },
    // 时间戳转换方法
    timestampToDate(timestamp) {
      const date = new Date(timestamp); // 如果timestamp是字符串，确保它是整数：parseInt(timestamp)
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      const seconds = date.getSeconds().toString().padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    // 时间选择单位
    formatter(type, val) {
      if (type === 'year') {
        return `${val}年`;
      } else if (type === 'month') {
        return `${val}月`;
      } else if (type === 'day') {
        return `${val}日`;
      } else if (type === 'hour') {
        return `${val}时`;
      } else if (type === 'minute') {
        return `${val}分`;
      }
      return val;
    },
    selectTime(e) {
      const dateString = this.timestampToDate(e.detail);
      this.form.zcsj = dateString
      this.timeShow = false
      // this.getRoomTime(this.startTime)
    },
    getCompanyList(){
      getAllBaseCompany({}).then(res=>{
        this.companyOptions = res
      })
    }
  }
}
</script>

<style lang="scss">
.inventoryReview{
    .detailUl{
      margin-top: 20rpx;
      background: white;
      padding: 24rpx 32rpx;
      .liName{
        font-size: 32rpx;
        color: rgba(51, 51, 51, 1);
        white-space: nowrap;
        .callNumber{
          color: rgba(24, 23, 42, 1);
          font-size: 36rpx;
          font-weight: 600;
        }
        .callName{
          color: rgba(102, 102, 102, 1);
          font-size: 28rpx;
        }
      }
      .phoneIcon{
        width: 64rpx;
        height: 64rpx;
      }
      .detailLi{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 32rpx 0;
        border-bottom: 2rpx solid #E6E6E6;
        .liInfo{
          display: inline-block;
          text-align: right;
          max-width: 428rpx;
          color: rgba(102, 102, 102, 1);
          font-size: 32rpx;
          line-height: 38rpx;
          overflow: hidden;
          word-wrap: break-word;
        }
        .inputBox{
          display: flex;
          align-items: center;
        }
        .moreLineBox{
          word-wrap: break-word;
          max-width: 422rpx;
          color: rgba(102, 102, 102, 1);
        }
        .myIpt{
          text-align: right;
          margin-right: 20rpx;
          color: rgba(102, 102, 102, 1);
          min-width: 422rpx;
        }
      }
      .detailLi2{
        display: flex;
        flex-direction: column;
        padding: 32rpx 0;
        border-bottom: 2rpx solid #E6E6E6;
        .detailLi2BoxTop{
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
          margin: 12rpx 0;
          .checkItem{
            width: 128rpx;
            height: 64rpx;
            font-size: 28rpx;
            color: #666666;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #F5F7FA;
            border-radius: 8rpx;
            margin: 12rpx 0;
          }
          .checked{
            background: #0365F9;
            color: white;
          }
        }
        .locationBox{
          position: absolute;
          right: 24rpx;
          top: 100rpx;
        }
        .van-cell {
          background: #F5F7FA !important;
          border-radius: 8rpx;
          font-size: 28rpx;
          margin-top: 16rpx;
        }
        .van-radio-group{
          display: flex;
          flex-wrap: wrap;
          margin-top: 24rpx;
          gap: 24rpx;
          color: rgba(102, 102, 102, 1);
          font-size: 4vw;
        }
      }
    }
  .buttonBox{
    display: flex;
    justify-content: center;
    .btn{
      width: 240rpx;
      height: 80rpx;
      display: flex;
      border-radius: 8rpx;
      align-items: center;
      justify-content: center;
      margin: 48rpx 16rpx 150rpx 16rpx;
      color: white;
      letter-spacing: 2rpx;
      text-indent: 2rpx;
      &::after{
        border: none;
      }
    }
    .zcBtn{
      background: rgba(0, 0, 0, 0.05);
      color: rgba(3, 101, 249, 1);
    }
    .tjBtn{
      background: #0365F9;
    }
  }
}
</style>
