<template>
<div class="page-contain">
  <top-nav title="项目备案"
           :showQuery="false"
           :back-func="handleClose"></top-nav>
  <div class="main">
    <div class="containner mb10"
         :style="{marginTop: paddingTop ? (paddingTop+10)+'px' : '20px'}">
      <div class="left"
           style="align-items: center;display: flex;">
        <!-- <span class="fb mr10">项目星级</span>
        <van-rate v-model="baseInfo.star"
                  :size="20"
                  disabled
                  icon="star-on"
                  void-icon="star-off" />-->
      </div>
      <div class="right">
        <img v-if="baseInfo.projectStatus =='auditing'"
             src="@/assets/images/apploval.png">
        <img v-if="baseInfo.projectStatus =='filed'"
             src="@/assets/images/through.png">
      </div>
    </div>

    <div class="contain-wrap">
      <div class="ls-row">
        <div class="row-header title">
          <span class="icon iconfont icon-jichuxinxi"></span>
          <span>基础信息</span>
        </div>
      </div>
      <div class="ls-row">
        <span class="row-header">项目编码</span>
        <span class="row-content">{{ baseInfo.projectCode }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">客户类型</span>
        <span class="row-content">{{ baseInfo.customerTypeKey }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">客户名称</span>
        <span class="row-content">{{ baseInfo.customer }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">客户等级</span>
        <span class="row-content c008C">{{ baseInfo.customerGrade }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">代理商</span>
        <span class="row-content">{{ baseInfo.agentName }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">项目名称</span>
        <span class="row-content">{{ baseInfo.projectName }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">行业大类</span>
        <span class="row-content">{{ baseInfo.industryCategoryKey }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">行业子类</span>
        <span class="row-content">{{ baseInfo.industrySubclassKey }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">细分领域</span>
        <span class="row-content">{{ baseInfo.industrySegmentation }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">机型号</span>
        <span class="row-content">{{ baseInfo.brandModelType }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">产品状态</span>
        <span class="row-content">{{ baseInfo.productStatusKey }}</span>
      </div>
      <div class="ls-row">
        <span class="row-header">品牌</span>
        <span class="row-content">{{ baseInfo.brandName }}</span>
      </div>
      <div @click="extendBaseInfo"
           class="tc p20 fc8CEE">
        <span v-if="isExtendBase">收起</span>
        <span v-else>查看更多</span>
        <van-icon :name="isExtendBase?'arrow-up':'arrow-down' " />
      </div>
      <template v-if="isExtendBase">
        <div class="ls-row">
          <span class="row-header">销售区域</span>
          <span class="row-content">{{baseInfo.salesRegionsKey?baseInfo.salesRegionsKey:baseInfo.salesRegions}}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">项目编码</span>
          <span class="row-content">{{ baseInfo.projectCode }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">项目名称</span>
          <span class="row-content">{{ baseInfo.projectName }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">客户名称</span>
          <span class="row-content">{{ baseInfo.customer }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">代理商</span>
          <span class="row-content c008C">{{ baseInfo.agentName }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">细分领域</span>
          <span class="row-content">{{ baseInfo.industrySegmentation }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">机型号</span>
          <span class="row-content">{{ baseInfo.brandModelType }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">芯片平台</span>
          <span class="row-content">{{ baseInfo.platformKey }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">芯片型号</span>
          <span class="row-content">{{ baseInfo.chipModelKey }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">存储类型</span>
          <span class="row-content">{{ baseInfo.storageType }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">存储容量</span>
          <span class="row-content">{{ baseInfo.storageCapacity }}</span>
        </div>

        <div class="ls-row">
          <span class="row-header">月需求量</span>
          <span class="row-content">{{$common.getComdifyNumber(baseInfo.monthCycle)+ ' (pcs)'}}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">提供FCST周期</span>
          <span class="row-content">{{baseInfo.fcstCycleKey}}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">项目/产品经理</span>
          <span class="row-content">{{ baseInfo.managerName }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">立项时间</span>
          <span class="row-content">{{ baseInfo.projectStartDate }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">上市时间</span>
          <span class="row-content">{{ baseInfo.productLaunchDate }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">EOL时间</span>
          <span class="row-content">{{ baseInfo.projectEolDate }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">终端售价</span>
          <span class="row-content">{{ baseInfo.terminalPrice }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">销售人员</span>
          <span class="row-content">{{ baseInfo.salesName }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">导入项目关键要素</span>
          <span class="row-content">{{ baseInfo.projectMainInfoKey }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">项目描述</span>
          <span class="row-content">{{ baseInfo.remark }}</span>
        </div>
      </template>
    </div>

    <div class="contain-wrap">
      <div class="ls-row">
        <div class="row-header title">
          <span class="icon iconfont icon-jichuxinxi"></span>
          <span>竞品信息</span>
        </div>
      </div>
      <div v-for="(item, index) in competitiveList"
           :key="index"
           class="collapse-box">
        <div class="top">
          <div class="row title">
            <span class="fb">{{item.brandName}}</span>
            <div @click="extendCompeti"
                 class="fc8CEE">
              <span v-if="isExtendCompeti">收起</span>
              <span v-else>更多</span>
              <van-icon :name="isExtendCompeti?'arrow-up':'arrow-down' " />
            </div>
          </div>
        </div>
        <div v-show="isExtendCompeti"
             class="info-box">
          <div class="info-item">
            <span class="left">存储品牌</span>
            <span class="right">{{item.brandName}}</span>
          </div>
          <div class="info-item">
            <span class="left">存储类型</span>
            <span class="right">{{item.storageType}}</span>
          </div>
          <div class="info-item">
            <span class="left">存储型号</span>
            <span class="right">{{item.storageModelType}}</span>
          </div>
          <div class="info-item">
            <span class="left">采购价</span>
            <span class="right">{{item.purchasePrice}}</span>
          </div>
          <div class="info-item">
            <span class="left">份额占比</span>
            <span class="right">{{item.estimatedProportion}}%</span>
          </div>
          <div class="info-item">
            <span class="left">货源供应</span>
            <span class="right">{{item.sourceSupplyKey}}</span>
          </div>
        </div>
      </div>
    </div>
    <!-- 产品信息 -->
    <div class="contain-wrap">
      <div class="ls-row">
        <div class="row-header title">
          <span class="icon iconfont icon-jichuxinxi"></span>
          <span>产品信息</span>
        </div>
      </div>
      <template v-if="projectLineList.length">
        <div v-for="(item, index) in projectLineList"
             :key="index"
             class="collapse-box">
          <div class="top">
            <div class="row title">
              <span class="fb">{{item.lineCode}}</span>
              <div @click="extendProduct"
                   class="fc8CEE">
                <span v-if="isExtendProduct">收起</span>
                <span v-else>更多</span>
                <van-icon :name="isExtendProduct?'arrow-up':'arrow-down' " />
              </div>
            </div>
          </div>
          <div v-show="isExtendProduct"
               class="info-box">
            <div class="info-item">
              <span class="left">子行编码</span>
              <span class="right">{{item.lineCode}}</span>
            </div>
            <div class="info-item">
              <span class="left">导入品牌</span>
              <span class="right">{{item.storageType}}</span>
            </div>
            <div class="info-item">
              <span class="left">预计份额</span>
              <span class="right">{{item.estimatedProportion}}%</span>
            </div>
            <div class="info-item">
              <span class="left">PN</span>
              <span class="right">{{item.productPn}}</span>
            </div>
            <div class="info-item">
              <span class="left">容量</span>
              <span class="right">{{item.itemCapacity}}</span>
            </div>
            <div class="info-item">
              <span class="left">产品类型</span>
              <span class="right">{{item.projectCategory}}</span>
            </div>

            <div class="info-item">
              <span class="left">产品线</span>
              <span class="right">{{item.itemProductLine}}</span>
            </div>
            <div class="info-item">
              <span class="left">锁定FW</span>
              <span class="right">{{item.lockFw=='Y'?'是':'否'}}</span>
            </div>
            <div class="info-item">
              <span class="left">新替代料认证周期</span>
              <span class="right">{{item.newItemNumKey}}</span>
            </div>
            <div class="info-item">
              <span class="left">计划送样</span>
              <span class="right">{{item.sampleDeliveryTime}}</span>
            </div>
            <div class="info-item">
              <span class="left">计划小批</span>
              <span class="right">{{item.smallTrialTime}}</span>
            </div>
            <div class="info-item">
              <span class="left">计划量产</span>
              <span class="right">{{item.productionTime}}</span>
            </div>
            <div class="info-item">
              <span class="left">立项时间</span>
              <span class="right">{{item.projectStartDate}}</span>
            </div>
            <div class="info-item">
              <span class="left">上市时间</span>
              <span class="right">{{item.productLaunchDate}}</span>
            </div>
            <div class="info-item">
              <span class="left">EOL时间</span>
              <span class="right">{{item.projectEolDate}}</span>
            </div>
            <div class="info-item">
              <span class="left">终端售价</span>
              <span class="right">{{item.terminalPrice}}</span>
            </div>
            <div class="info-item">
              <span class="left">导入状态</span>
              <span class="right">{{item.importStatus}}</span>
            </div>
            <div class="info-item">
              <span class="left">月预估量</span>
              <span class="right">{{$common.getComdifyNumber(item.monthEstimates)}}</span>
            </div>
            <div class="info-item">
              <span class="left">预估单价</span>
              <span class="right">{{$common.getComdifyNumber(item.estimatePrice)}}</span>
            </div>
            <div class="info-item">
              <span class="left">月预估金额</span>
              <span class="right">{{$common.getComdifyNumber(item.monthEstimateAmount)}}</span>
            </div>
            <div class="info-item">
              <span class="left">项目进度</span>
              <span class="right">{{item.makeRemark}}</span>
            </div>
            <div class="info-item">
              <span class="left">后续计划</span>
              <span class="right">{{item.planRemark}}</span>
            </div>
            <div class="info-item">
              <span class="left">补充说明</span>
              <span class="right">{{item.remark}}</span>
            </div>
          </div>
        </div>
      </template>
      <van-empty v-else
                 description="暂无数据！" />
    </div>
    <project-apploval v-if="processId && !edit"
                      :showOther="false"
                      :processId="processId" />
    <div class="more-data">
      <div class="ls-row">
        <div class="row-header title">
          <span class="icon iconfont icon-iconfontgengduo"></span>
          <span>更多</span>
        </div>
      </div>

      <div class="contain">
        <div @click="handleJump('log')"
             class="data-item">
          <div>
            <span class="iconfont icon-shenpi"></span>
          </div>
          <span>操作日志</span>
        </div>
      </div>
    </div>
  </div>
</div>
</template>

<script>

import projectData from './components/project-data.vue'
import projectApploval from './components/project-apploval.vue'
import approveReback from '../../common/approveReback'
export default {
  name: 'project-record',
  components: {
    projectData,
    projectApploval
  },
  mixins: [approveReback],
  data () {
    return {
      isExtendBase: false,
      isExtendCompeti: false,
      isExtendProduct: false,

      projectId: '',
      baseInfo: {
        star: 0
      },
      competitiveList: [],
      projectLineList: [],
      dataList: [],
      paddingTop: Number(localStorage.getItem('paddingTop')),
      lastRoute: ['/projectList']
    }
  },
  created () {
    let $this = this
    parent.window.doSubmit = function (param) {
      if (!$this.isProccess) {
        $this.approve(param)
        return false
      } else {
        return true
      }
    }

    this.processId = this.$common.getUrlParams('processId')
    this.projectId = this.$common.getUrlParams('projectId')

    this.getbaseInfoById()
    this.getCompetitiById()
    this.getProjectLineById()

    this.edit = this.$common.getUrlParams('isEdit')
    if (this.edit) {
      this.$toast({ type: 'fail', message: '当前节点不支持移动端审批，请移至PC审批' })
    };
  },
  methods: {
    approve (param) {
      if (this.edit) {
        this.$toast({ type: 'fail', message: '当前节点不支持移动端审批，请移至PC审批' })
        return
      }
      if (param.actionName === '' || param.actionName == null) {
        this.$toast({ type: 'fail', message: '请选择处理动作！' })
        return
      }
      if (param.actionName === '驳回' && (param.commentView === '' || param.commentView == null)) {
        this.$toast({ type: 'fail', message: '驳回时，处理意见必填！' })
        return
      }

      param.moduleId = 3101
      this.$axios.post({
        domain: 'crmUrl',
        url: 'process.approve',
        data: param,
        requestType: 'body',
        isShow: true,
        success: function (res) {
          debugger
          if (res.errorCode === 200) {
            this.isProccess = true
            parent.FormToolBarAction.BTN_TRANSACT()
          } else {
            this.$toast({ type: 'fail', message: res.msg })
          }
        }.bind(this),
        error: function (err) {
          this.$toast({ type: 'fail', message: err, duration: 3000 })
        }.bind(this)
      })
    },
    // 根据项目id 获取 项目信息
    getbaseInfoById () {
      this.$axios.post({
        domain: 'crmUrl',
        url: 'project.getProject',
        data: { projectId: this.projectId },
        requestType: 'body',
        isShow: true,
        success: function (res) {
          if (res.errorCode === 200) {
            this.baseInfo = res.data || {}
          } else {
            this.$toast({ type: 'fail', message: res.msg })
          }
        }.bind(this),
        error: function (err) {
          this.$toast({ type: 'fail', message: err, duration: 3000 })
        }.bind(this)
      })
    },
    //  根据 项目id 查询竞品信息
    getCompetitiById () {
      this.$axios.post({
        domain: 'crmUrl',
        url: 'projectCompetitive.getCompetitives',
        data: { projectId: this.projectId },
        requestType: 'body',
        isShow: false,
        success: function (res) {
          if (res.errorCode === 200) {
            this.competitiveList = res.data || []
          } else {
            this.$toast({ type: 'fail', message: res.msg })
          }
        }.bind(this),
        error: function (err) {
          this.$toast({ type: 'fail', message: err, duration: 3000 })
        }.bind(this)
      })
    },
    // 通过项目ID 查询产品信息
    getProjectLineById () {
      this.$axios.post({
        domain: 'crmUrl',
        url: 'projectLine.getProjectLine',
        data: { projectId: this.projectId },
        requestType: 'body',
        isShow: false,
        success: function (res) {
          if (res.errorCode === 200) {
            this.projectLineList = res.data || []
          } else {
            this.$toast({ type: 'fail', message: res.msg })
          }
        }.bind(this),
        error: function (err) {
          this.$toast({ type: 'fail', message: err, duration: 3000 })
        }.bind(this)
      })
    },
    extendBaseInfo () {
      this.isExtendBase = !this.isExtendBase
    },
    extendCompeti () {
      this.isExtendCompeti = !this.isExtendCompeti
    },
    extendProduct () {
      this.isExtendProduct = !this.isExtendProduct
    },
    handleJump (flag) {
      if (flag === 'log') {
        if (this.projectId === '') {
          console.log('业务ID不能为空！')
          return false
        }
        this.$router.push({ name: 'operationlLog', params: { busId: this.projectId } })
      }
    }
  }
}
</script>

<style type="text/css" scoepd lang="scss">
.page-contain {
  padding-top: 82px;
  padding-bottom: 30px;

  .main{
    height: calc(100vh - 82px);
    overflow-y: auto;
    padding-bottom: 152px;
  }
  .containner {
    padding: 20px;
    background-color: #fff;
    display: flex;
    align-items: center;

    .left {
      flex: 1;
    }
    .right {
      img {
        width: 100px;
      }
    }
  }
  .contain-wrap {
    background-color: #fff;
    margin-bottom: 20px;
    padding-bottom: 20px;

    .text-content {
      padding: 20px;
      color: #666;
      text-indent: 2em;
    }
  }
  .collapse-box {
    margin: 20px;

    .top {
      padding: 0;
      .row {
        padding: 20px;
        border: none;
      }
    }
  }
  .project-apploval {
    margin: 20px 0 !important;
  }
}
.more-data {
  background-color: #fff;
  margin-bottom: 40px;

  .contain {
    display: flex;

    .data-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 26px;

      div:first-child {
        width: 108px;
        height: 108px;
        background: #4f94f3;
        border-radius: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 20px;

        .iconfont {
          font-size: 50px;
          color: #fff;
        }
      }
      div.bg57B9 {
        background-color: #57b986;
      }
    }
  }
}
</style>
