<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <div class="tab-header webtop">
        <div>{{ viewTitle }}</div>
        <div>
          <el-button type="danger" size="small" @click="openRevoke()">撤回</el-button>
        </div>
      </div>
      <div class="">
        <el-form ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
          <el-row style="border-top: 1px solid #e0e3eb">
            <el-col :span="8">
              <div class="span-sty">申请部门</div>
              <el-form-item><span class="addinputInfo">{{ formobj.deptName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">申请人</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createByName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">申请日期</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createTime }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">开票名称</div>
              <el-form-item><span class="addinputInfo">{{ formobj.invoiceName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">开票类型</div>
              <el-form-item><span class="addinputInfo">{{ formobj.invoiceValue }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">开票金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.invoiceMoney }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">备注</div>
              <el-form-item><span class="addinputInfo">{{ formobj.remarks }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">附件</div>
              <el-form-item><el-image class="addinputInfo" style="width: 150px;height: 150px" v-for="(item, index) in formobj.fileList" :key="index" :src="item" :preview-src-list="formobj.fileList" /></el-form-item>
            </el-col>
          </el-row>
          <div class="title">开票索赔单列表</div>
          <el-table :key="tableKey" :data="formobj.detailList" :index="index" border style="width: 100%" :cell-style="cellStyle">
            <el-table-column fixed width="60" label="序号" type="index" :index="index + 1" align="center"/>
            <el-table-column prop="claimBillNo" label="索赔单号" align="center" width="170" />
            <el-table-column prop="repairBillNo" label="维修工单号" align="center" width="170" />
            <el-table-column prop="vehMark" label="车牌号" align="center" width="100" />
            <el-table-column prop="vinNo" label="车架号" align="center" width="100" />
            <el-table-column prop="claimHourAmount" label="索赔工时费" align="center" width="120" />
            <el-table-column prop="claimGoodsAmount" label="索赔材料费" align="center" width="120" />
            <el-table-column prop="claimOutAmount" label="外出费" align="center" width="120" />
            <el-table-column prop="claimSubsidyAmount" label="厂家补助" align="center" width="120" />
            <el-table-column prop="claimRescueAmount" label="施救费" align="center" width="120" />
            <el-table-column prop="claimOtherAmount" label="其他费用" align="center" width="120" />
            <el-table-column prop="remarks" label="备注" align="center" min-width="200" />
          </el-table>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import req from '@/api/operation/claimbilling'

export default {
  name: 'ClaimBillingYiBan',
  data() {
    return {
      viewTitle: '',
      viewState: 1,
      tableKey: 1,
      index: 0,
      formobj: {
        billNo: '',
        createByName: '',
        createBySid: '',
        deptName: '',
        deptSid: '',
        createOrgSid: '',
        createTime: '',
        detailList: [],
        fileList: [],
        invoiceKey: '',
        invoiceMoney: '',
        invoiceName: '',
        invoiceSid: '',
        invoiceValue: '',
        nodeState: '',
        procDefId: '',
        procInstId: '',
        remarks: '',
        sid: '',
        taskDefKey: '',
        taskId: '',
        useOrgName: '',
        useOrgSid: ''
      },
      rules: {},
      // 环节所需参数
      linkByParameter: {
        businessSid: '',
        comment: '',
        instanceId: '',
        taskId: '',
        orgSidPath: '',
        taskDefKey: '',
        userSid: ''
      }
    }
  },
  created() {
    console.log('url:' + window.location.href)
    var one = window.location.href.indexOf('&data') + 6
    const data = window.location.href.substr(one) // url解码unescape()已从web中移除,尽量不使用
    const obj = JSON.parse(decodeURIComponent(data))
    console.log('iframe页面获取的obj:', obj)
    // 点击（同意、终止、驳回、驳回）操作时所需的参数
    this.linkByParameter.businessSid = obj.businessSid
    this.linkByParameter.instanceId = obj.instanceId
    this.linkByParameter.taskId = obj.taskId
    this.linkByParameter.taskDefKey = obj.taskDefKey
    this.linkByParameter.userSid = window.sessionStorage.getItem('userSid')
    // 加载表单数据
    this.showInfo(obj.businessSid)
  },
  mounted() {
    window.parent.postMessage({
      cmd: 'returnHeight',
      params: {
        // 告诉父级页面，子页面的弹框高度。
        code: 2,
        data: 400 + 'px'
      }
    }, '*')
  },
  methods: {
    showInfo(sid) {
      this.viewTitle = '索赔单开票详情'
      req.fetchDetailsBySid({ sid: sid }).then((res) => {
        if (res.success) {
          this.formobj = res.data
          if (this.formobj.fileList.length > 0) {
            const aa = []
            this.formobj.fileList.forEach((e) => {
              aa.push(e.url)
            })
            this.formobj.fileList = aa
          }
        }
      })
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      // 定义样式变量
      let cell = ''
      if (!row.isUnanimous) {
        cell = 'background: #ff6961;'
        return cell
      }
    },
    /** 确认撤回任务 */
    openRevoke() {
      this.$confirm('是否确认执行撤回操作', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleRevoke()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消撤回'
        })
      })
    },
    /** 撤回任务 */
    handleRevoke() {
      req.revokeProcess(this.linkByParameter).then((response) => {
        if (response.success) {
          this.$notify({
            title: '提示',
            message: '执行成功',
            type: 'success',
            duration: 2000
          })
          this.nodeDialogVisible = false
          // 子页面向父级页面传递值
          window.parent.postMessage({
            cmd: 'returnHeight',
            params: {
              // 操作成功，告诉父级页面关闭弹框
              code: 1
            }
          }, '*')
        }
      })
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 130px !important;
}
.addinputInfo {
  margin-left: 120px !important;
}
</style>
