<template>
  <div class="app-container">
    <div>
      <div class="tab-header webtop">
        <div>经销商详情</div>
        <div>
          <el-button type="primary" size="small" @click="openAgree('同意')">同 意</el-button>
          <el-button type="danger" size="small" @click="openReject('驳回')">驳 回</el-button>
          <el-button type="danger" size="small" @click="openStop('终止')">终 止</el-button>
        </div>
      </div>
      <div class="">
        <el-form ref="dataForm" :model="temp" label-position="right" class="formadd" :rules="rules">
          <div class="title">基本信息</div>
          <el-row style="border-top: 1px solid #DFE6EC">
            <el-col :span="4" class="tleftb">
              <span>所属经销商</span>
            </el-col>
            <el-col :span="20">
              <el-form-item>
                <span>{{ temp.pDistributorName }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>经销商名称</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.disName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>统一社会信用代码</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.registNum }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>注册地址</span>
            </el-col>
            <el-col :span="20">
              <el-form-item>
                <span>{{ temp.registDetailAddress }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>实际经营地址</span>
            </el-col>
            <el-col :span="20">
              <el-form-item>
                <span>{{ temp.managementDetailAddressProvince + temp.managementDetailAddressCity + temp.managementDetailAddressCounty + temp.managementDetailAddress }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>成立日期</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.setUpTime }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>开始合作时间</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.startCoopDate }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>是否担保</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.isGuarantee }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>实际控制人</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.legalName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>身份证号码</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.legalIdCard }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>手机号码</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.legalMobile }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>企业联系人</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.contract }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>手机号码</span>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <span>{{ temp.mobile }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb"/>
            <el-col :span="4"/>
          </el-row>
          <div class="title">开票信息</div>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>单位名称</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                {{ temp.disName }}
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>税号</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.registNum }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>地址</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.registDetailAddress }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>联系电话</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.invoPhone }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="tleftb">
              <span>开户行</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.invoBank }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="tleftb">
              <span>银行账号</span>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span>{{ temp.invoBankNum }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="title">人员列表</div>
          <el-table :key="tableKey" v-loading="listLoading" :data="temp.perList" :index="index" border style="width: 100%">
            <el-table-column fixed width="80px" label="序号" type="index" :index="index + 1" align="center"/>
            <el-table-column label="姓名" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="身份" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.identityValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="手机号码" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.mobile }}</span>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.remarks }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="title">附件清单</div>
          <div class="headline">
            <div style="margin-left: 5px;font-weight: bold">营业执照</div>
          </div>
          <el-table :key="businessLicenseKey" :data="temp.yyzzList" border style="width: 100%">
            <el-table-column label="文件名" align="center">
              <template slot-scope="scope">
                <span class="bluezi" @click="handLook(scope.row)">{{ scope.row.fileName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="文件类型" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.fileType }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传人" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传时间" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.createTime }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="headline">
            <div style="margin-left: 5px;font-weight: bold">道路运输许可证</div>
          </div>
          <el-table :key="roadTransportKey" :data="temp.dlysxkzList" border style="width: 100%">
            <el-table-column label="文件名" align="center">
              <template slot-scope="scope">
                <span class="bluezi" @click="handLook(scope.row)">{{ scope.row.fileName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="文件类型" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.fileType }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传人" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传时间" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.createTime }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="headline">
            <div style="margin-left: 5px;font-weight: bold">法人身份证</div>
          </div>
          <el-table :key="corporateIdentityCardKey" :data="temp.frsfzList" border style="width: 100%">
            <el-table-column label="文件名" align="center">
              <template slot-scope="scope">
                <span class="bluezi" @click="handLook(scope.row)">{{ scope.row.fileName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="文件类型" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.fileType }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传人" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传时间" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.createTime }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="headline">
            <div style="margin-left: 5px;font-weight: bold">其他资料</div>
          </div>
          <el-table :key="otherDetailsKey" :data="temp.qtzlList" border style="width: 100%">
            <el-table-column label="文件名" align="center">
              <template slot-scope="scope">
                <span class="bluezi" @click="handLook(scope.row)">{{ scope.row.fileName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="文件类型" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.fileType }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传人" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="上传时间" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.createTime }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </div>
    </div>
    <el-dialog :visible="dialogVisible" append-to-body :before-close="handColse">
      <img width="100%" :src="dialogImageUrl" alt=""/>
    </el-dialog>
    <!-- 选择待办人 的弹出框-->
    <el-dialog title="填写审批意见" :visible.sync="nodeDialogVisible" width="80%">
      <el-form class="formadd" >
        <el-row v-show="currentLink" style="border-top: 1px solid #e0e3eb">
          <el-col :span="4" class="tleftb">
            <span>当前环节:</span>
          </el-col>
          <el-col :span="20">
            <el-form-item><span>{{ current.taskName }}->{{ nextNode.name }}</span></el-form-item>
          </el-col>
        </el-row>
        <el-row :class="{rowClass:!currentLink}">
          <el-col :span="4" class="tleftb">
            <span>意见:</span>
          </el-col>
          <el-col :span="20">
            <el-form-item><el-input size="small" v-model="dialogList.comment" placeholder="审批意见" class="addinputw" type="textarea" :autosize="{ minRows: 1, maxRows: 10}" clearable ></el-input></el-form-item>
          </el-col>
        </el-row>
        <div style="text-align:center;margin-top: 20px;">
          <el-button type="primary" size="mini" @click="reject">确 定</el-button>
          <el-button type="info " size="mini" @click="nodeDialogVisible = false">取 消</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { details, complete, breakProcess, reject, getPreviousNodesForReject, getNextNodesForSubmit } from '@/api/jichuxinxi/baseaffiliatcompany'

export default {
  name: 'JingXiaoShangDaiBan',
  data() {
    return {
      dialogVisible: false,
      dialogImageUrl: '',
      tableKey: 0,
      businessLicenseKey: 1,
      roadTransportKey: 2,
      corporateIdentityCardKey: 3,
      otherDetailsKey: 4,
      index: 0,
      FormLoading: false,
      listLoading: false,
      temp: {
        cityCode: '',
        contract: '',
        createOrg: '',
        createOrgName: '',
        disLevelKey: '',
        disLevelValue: '',
        disName: '',
        dlysxkzList: [],
        frsfzList: [],
        invoBank: '',
        invoBankNum: '',
        invoPhone: '',
        isGuarantee: '',
        legalIdCard: '',
        legalMobile: '',
        legalName: '',
        managementAddressCode: '',
        managementDetailAddress: '',
        managementDetailAddressCity: '',
        managementDetailAddressCounty: '',
        managementDetailAddressProvince: '',
        mobile: '',
        orgSidPath: '',
        pDistributorName: '',
        pDistributorSid: '',
        pdisName: '',
        perList: [],
        provinceCode: '',
        qtzlList: [],
        registDetailAddress: '',
        registNum: '',
        setUpTime: '',
        sid: '',
        startCoopDate: '',
        useOrg: '',
        useOrgName: '',
        userSid: '',
        yyzzList: []
      }, // 查看实体
      rules: {},
      operation: '', // 点击操作按钮
      dialogList: {
        comment: ''
      },
      startTask: true,
      current: {
        taskDefKey: '',
        taskName: '' // 当前环节名称
      },
      nextNode: {}, // 下一环节
      nodeDialogVisible: false,
      currentLink: true,
      // 环节所需参数
      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.orgSidPath = window.sessionStorage.getItem('orgSidPath')
    this.linkByParameter.userSid = window.sessionStorage.getItem('userSid')
    this.current.taskDefKey = obj.taskDefKey
    this.current.taskName = obj.taskName
    // 加载表单数据
    this.showInfo(obj.businessSid)
  },
  mounted() {
    window.parent.postMessage({
      cmd: 'returnHeight',
      params: {
        // 告诉父级页面，子页面的弹框高度。
        code: 2,
        data: 500 + 'px'
      }
    }, '*')
  },
  methods: {
    handLook(row) {
      console.log('查看图片', row)
      this.dialogVisible = true
      this.dialogImageUrl = row.filePath
      console.log('查看图片', this.dialogImageUrl)
    },
    handColse() {
      this.dialogVisible = false
    },
    showInfo(sids) {
      details(sids).then((response) => {
        if (response.success) {
          this.temp = response.data
        }
      })
    },
    // 同意
    openAgree(val) {
      this.operation = val
      this.currentLink = true
      this.dialogList.comment = '同意'
      getNextNodesForSubmit({ taskDefKey: this.current.taskDefKey, businessSid: this.linkByParameter.businessSid }).then((resp) => {
        if (resp.success) {
          var arr = resp.data
          this.nextNode = arr[0]
          this.nodeDialogVisible = true
        }
        this.submitdisabled = false
      })
    },
    // 驳回
    openReject(val) {
      this.operation = val
      this.currentLink = true
      this.dialogList.comment = ''
      getPreviousNodesForReject({ taskDefKey: this.current.taskDefKey, businessSid: this.linkByParameter.businessSid }).then((resp) => {
        if (resp.success) {
          var arr = resp.data
          this.nextNode = arr[0]
          this.nodeDialogVisible = true
        }
        this.submitdisabled = false
      })
    },
    // 终止
    openStop(val) {
      this.operation = val
      this.currentLink = false
      this.dialogList.comment = ''
      this.nodeDialogVisible = true
    },
    reject() {
      if (this.operation === '同意') {
        this.handleAgree()
      } else if (this.operation === '驳回') {
        if (this.dialogList.comment === '') {
          this.$message({ showClose: true, type: 'error', message: '请填写审批意见' })
        } else {
          this.handleReject()
        }
      } else if (this.operation === '终止') {
        if (this.dialogList.comment === '') {
          this.$message({ showClose: true, type: 'error', message: '请填写审批意见' })
        } else {
          this.handleStop()
        }
      }
    },
    /** 同意任务 */
    handleAgree() {
      this.linkByParameter.comment = this.dialogList.comment
      complete(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
            }
          }, '*')
        }
      })
    },
    /** 驳回任务 */
    handleReject() {
      this.linkByParameter.comment = this.dialogList.comment
      reject(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
            }
          }, '*')
        }
      })
    },
    /** 终止任务 */
    handleStop() {
      this.linkByParameter.comment = this.dialogList.comment
      breakProcess(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>
.headline{
  height: 40px;
  padding: 10px;
  font-weight: bold;
  background-color: #ffffff;
  border: 1px solid #DFE6EC;
}
.rowClass{
  border-top: 1px solid #E0E3EB;
}
</style>
