<template>
  <!-- 合同管理 -->
  <div class="items bgc" id="bid3">
    <!-- 标题 -->
    <div class="title">
      <span class="icon"></span>
      <span class="text">合同管理</span>
    </div>
    <!-- 详情 -->
    <div class="table-border">
      <el-table
        :data="data"
        height="230"
        border
        style="width: 100%"
        :header-cell-style="{background: '#f2f2f2', color: '#000'}"
        @row-click="handleRowDBClick"
      >
        <el-table-column type="index" label="序号" width="60" align="center">
        </el-table-column>
        <el-table-column
          prop="contract.name"
          label="合同名称"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row}">
            <a class="a-link">{{ row.contract.name }}</a>
          </template>
        </el-table-column>
        <!-- <el-table-column
            prop="contract.contractNumber"
            label="合同编号"
            align="center"
            :show-overflow-tooltip="true"
            >
          </el-table-column> -->
        <ht-table-column
          prop="contract.typeValue"
          label="合同类型"
          align="center"
          width="200"
          :show-overflow-tooltip="true"
        >
          <!-- <template v-slot="{row}">
            {{ getDictName('htgl-htlb', row.contract.type) }}
          </template> -->
        </ht-table-column>
        <el-table-column
          prop="contract.contractAmount"
          label="合同金额(万元)"
          align="center"
          width="160"
          :show-overflow-tooltip="true"
        >
          <!-- <template v-slot="{row}">
            {{ row.contract && row.contract.contractAmount &&  moneyFormatter(parseInt(row.contract.contractAmount / 10000) )}}
        </template> -->
        </el-table-column>
        <el-table-column
          prop="contract.establishmentRemarks"
          label="备注"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <div class="page-footer">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageResult.page"
          :page-sizes="[5, 10, 20, 30, 50]"
          :page-size="pageResult.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageResult.total"
        >
        </el-pagination>
      </div>
      <el-dialog
        title="合同管理-详情"
        :visible.sync="dialogVisible"
        width="1000px"
      >
        <table align="center">
          <tr>
            <td class="bgColor" style="width: 130px">合同名称</td>
            <td>
              <el-tooltip
                :content="form.contract && form.contract.name"
                placement="top"
              >
                <p class="descStyle">
                  {{ form.contract && form.contract.name }}
                </p>
              </el-tooltip>
            </td>
            <td class="bgColor" style="width: 130px">合同编号</td>
            <td style="width: 260px">
              {{ form.contract && form.contract.contractNumber }}
            </td>
          </tr>
          <tr>
            <td class="bgColor">签订日期</td>
            <td>{{ form.contract && form.contract.contractDate }}</td>
            <td class="bgColor">合同金额(万元)</td>
            <td>{{ form.contract && form.contract.contractAmount }}</td>
          </tr>
          <tr>
            <td class="bgColor">甲方单位</td>
            <!-- <td>{{ form.contract && form.contract.firstParty }}</td> -->
            <td>
              <el-tooltip
                :content="form.contract && form.contract.firstParty"
                placement="top"
              >
                <p class="descStyle">
                  {{ form.contract && form.contract.firstParty }}
                </p>
              </el-tooltip>
            </td>
            <td class="bgColor">乙方单位</td>
            <!-- <td>{{ form.contract && form.contract.secondParty }}</td> -->
            <td>
              <el-tooltip
                :content="form.contract && form.contract.secondParty"
                placement="top"
              >
                <p class="descStyle">
                  {{ form.contract && form.contract.secondParty }}
                </p>
              </el-tooltip>
            </td>
          </tr>
          <tr>
            <td class="bgColor">丙方单位</td>
            <!-- <td>{{ form.contract && form.contract.thirdParty }}</td> -->
            <td>
              <el-tooltip
                :content="form.contract && form.contract.thirdParty"
                placement="top"
              >
                <p class="descStyle">
                  {{ form.contract && form.contract.thirdParty }}
                </p>
              </el-tooltip>
            </td>
            <td class="bgColor"></td>
            <td></td>
          </tr>
          <!-- <tr>
            <td class="bgColor">附件信息</td>
            <td colspan="3">
              <el-link
                type="primary"
                @click="handleLook(form.contract && form.contract.accessoryInfo)"
                v-if="
                  form.contract && form.contract.accessoryInfo && form.contract && form.contract.accessoryInfo.length > 0
                "
              >查看附件({{ form.contract && form.contract.accessoryInfo.length }}个)</el-link>
              <span v-else></span>
            </td>
          </tr> -->
          <tr>
            <td class="bgColor">备注</td>
            <td colspan="3">{{ form.contract && form.contract.remarks }}</td>
          </tr>
        </table>
        <dialog-accessory
          ref="accessory"
          :accessoryInfo="form.contract && form.contract.accessoryInfo"
        />
        <div class="flexEnd">
          <div class="end">
            <!-- <span>项目名称：{{form.project && form.project.projectName}}</span> -->
            <span>{{ form.project && form.project.projectManager }}</span>
            <span>{{ form.project && form.project.commencementTime }}</span>
            <el-link type="primary" @click="handlePayInfo(form.contract.id)"
              >支付管理信息查询</el-link
            >
          </div>
        </div>
      </el-dialog>
      <!-- <dialog-accessory ref="accessory" /> -->
      <el-dialog
        title="支付管理信息-详情"
        :visible.sync="dialogVisiblePayList"
        width="1000px"
      >
        <div class="table-border">
          <el-table
            :data="dataPayList"
            height="230"
            border
            style="width: 100%"
            :header-cell-style="{background: '#f2f2f2', color: '#000'}"
            @row-dblclick="handleRowDBClickPayList"
          >
            <el-table-column
              type="index"
              label="序号"
              width="60"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="projectInfo.projectName"
              label="项目名称"
              :show-overflow-tooltip="true"
              min-width="150"
              align="center"
            >
            </el-table-column>
            <ht-table-column
              prop="contract.purpose"
              label="用途"
              align="center"
              :show-overflow-tooltip="true"
              :filters="getDictData('jdgl-yt')"
            >
              <template v-slot="{row}">
                <div>{{ getDictName('jdgl-yt', row.contract.purpose) }}</div>
              </template>
            </ht-table-column>
            <el-table-column
              prop="contract.registerDate"
              label="审批日期"
              align="center"
              width="130"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <!-- <el-table-column
              prop="contract.name"
              label="合同名称"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column> -->
            <!-- <el-table-column
            prop="contract.contractNumber"
            label="合同编号"
            align="center"
            :show-overflow-tooltip="true"
            >
          </el-table-column> -->
            <!-- <ht-table-column
              prop="contract.type"
              label="合同类型"
              align="center"
              width="200"
              :show-overflow-tooltip="true"
            >
              <template v-slot="{row}">
                {{ getDictName('htgl-htlb', row.contract.type) }}
              </template>
            </ht-table-column> -->
            <!-- <el-table-column
              prop="contract.contractAmount"
              label="合同金额(元)"
              align="center"
              width="160"
              :show-overflow-tooltip="true"
            >
            </el-table-column> -->
            <el-table-column
              prop="contract.totalInvestment"
              label="总投资金额(元)"
              align="center"
              width="150"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              prop="contract.payeeAmountTotal"
              label="本次拨款额(元)"
              align="center"
              width="150"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              prop="contract.amountAppropriated"
              label="已拨款额(元)"
              align="center"
              width="150"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              prop="contract.remarks"
              label="备注"
              align="center"
              width="120"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <!-- <el-table-column
              prop="contract.establishmentRemarks"
              label="备注"
              align="center"
              width="100"
              :show-overflow-tooltip="true"
            >
            </el-table-column> -->
          </el-table>
          <div class="page-footer">
            <el-pagination
              @size-change="handleSizeChange2"
              @current-change="handleCurrentChange2"
              :current-page="pageResult2.page"
              :page-sizes="[5, 10, 20, 30, 50]"
              :page-size="pageResult2.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="pageResult2.total"
            >
            </el-pagination>
          </div>
        </div>
      </el-dialog>
      <el-dialog
        title="详情"
        :visible.sync="dialogVisiblePayInfo"
        width="1000px"
      >
        <table align="center">
          <tr>
            <td class="bgColor" style="width: 100px">合同名称</td>
            <td>{{ formPayInfo.contract && formPayInfo.contract.name }}</td>
            <td class="bgColor" style="width: 100px">部室(子公司)</td>
            <td>{{ formPayInfo.contract && formPayInfo.contract.dept }}</td>
          </tr>
          <tr>
            <td class="bgColor">审批日期</td>
            <td>
              {{ formPayInfo.contract && formPayInfo.contract.registerDate }}
            </td>
            <td class="bgColor">用途</td>
            <td>
              {{
                getDictName(
                  'jdgl-yt',
                  formPayInfo.contract && formPayInfo.contract.purpose
                )
              }}
            </td>
          </tr>
          <tr>
            <td class="bgColor">总投资额(万元)</td>
            <td>
              {{ formPayInfo.contract && formPayInfo.contract.totalInvestment }}
            </td>
            <td class="bgColor">已拨款额(元)</td>
            <td>
              {{
                formPayInfo.contract && formPayInfo.contract.amountAppropriated
              }}
            </td>
          </tr>
          <tr>
            <td class="bgColor">票据号码</td>
            <td>
              {{
                formPayInfo.contract && formPayInfo.contract.settlementBillNum
              }}
            </td>
            <td class="bgColor">本次拨款额(元)</td>
            <td>
              {{
                formPayInfo.contract && formPayInfo.contract.payeeAmountTotal
              }}
            </td>
          </tr>
          <tr>
            <td class="bgColor">项目进度情况及已完成工作量</td>
            <td>
              {{ formPayInfo.contract && formPayInfo.contract.measurementData }}
            </td>
            <td class="bgColor">收款单位</td>
            <td>
              {{
                formPayInfo.contract && formPayInfo.contract.registerPersonName
              }}
            </td>
          </tr>
          <tr>
            <td class="bgColor">账号</td>
            <td>
              {{ formPayInfo.contract && formPayInfo.contract.handlerPerson }}
            </td>
            <td class="bgColor">开户行</td>
            <td>
              {{
                formPayInfo.contract && formPayInfo.contract.registerPersonId
              }}
            </td>
          </tr>
          <tr>
            <td class="bgColor">备注</td>
            <td>{{ formPayInfo.contract && formPayInfo.contract.remarks }}</td>
          </tr>
          <!-- <tr>
            <td class="bgColor">附件信息</td>
            <td colspan="3">
              <el-link
                type="primary"
                @click="handleLook(formPayInfo.contract && formPayInfo.contract.accessoryInfo)"
                v-if="
                  formPayInfo.contract && formPayInfo.contract.accessoryInfo && formPayInfo.contract && formPayInfo.contract.accessoryInfo.length > 0
                "
              >查看附件({{ formPayInfo.contract && formPayInfo.contract.accessoryInfo.length }}个)</el-link>
              <span v-else>无</span>
            </td>
          </tr> -->
          <tr>
            <td class="bgColor">备注</td>
            <td colspan="3">
              {{ formPayInfo.contract && formPayInfo.contract.remarks }}
            </td>
          </tr>
        </table>
        <dialog-accessory
          ref="accessory"
          :accessoryInfo="
            formPayInfo.contract && formPayInfo.contract.accessoryInfo
          "
        />
        <div class="flexEnd">
          <div class="end">
            <!-- <span>项目名称：{{formPayInfo.project && formPayInfo.project.projectName}}</span> -->
            <span>{{
              formPayInfo.project && formPayInfo.project.projectManager
            }}</span>
            <span>{{
              formPayInfo.project && formPayInfo.project.commencementTime
            }}</span>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import dialogAccessory from '../dialog/dialogAccessory.vue'
export default {
  name: 'contract',
  components: {
    dialogAccessory,
  },
  data() {
    return {
      data: [], //表格数据
      dataPayList: [],
      pageResult: {
        page: 1,
        pageSize: 10,
        total: 0,
      },
      pageResult2: {
        page: 1,
        pageSize: 10,
        total: 0,
      },
      form: {},
      formPayInfo: {},
      dialogVisible: false,
      dialogTitle: '添加',
      dialogVisiblePayList: false,
      dialogVisiblePayInfo: false,
      payId: '',
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    handlePayInfo(id) {
      this.payId = id
      this.dialogVisiblePayList = true
      this.loadData2()
    },
    //附件
    handleLook(obj) {
      this.$refs.accessory.open(obj)
    },
    handleSizeChange(val) {
      this.pageResult.pageSize = val
      this.loadData()
    },
    handleSizeChange2(val) {
      this.pageResult2.pageSize = val
      this.loadData2()
    },
    handleCurrentChange(val) {
      this.pageResult.page = val
      this.loadData()
    },
    handleCurrentChange2(val) {
      this.pageResult2.page = val
      this.loadData2()
    },
    handleRowDBClick(data) {
      this.dialogVisible = true
      data.contract.accessoryInfo = data.accessoryInfo
      this.form = data
    },
    handleRowDBClickPayList(data) {
      this.dialogVisiblePayInfo = true
      data.contract.accessoryInfo = data.accessoryInfo
      this.formPayInfo = data
    },
    loadData() {
      let param = {
        pageBean: {
          ...this.pageResult,
        },
        querys: [
          {
            group: 'advance',
            opener: 'LIKE',
            property: 'pm.ID_',
            relation: 'AND',
            value: this.$route.params.id,
          },
        ],
        sorter: [{direction: 'DESC', property: 'bc.contract_date_'}],
      }
      this.$http.post('${cqxy}/biz/contract/v1/page', param).then(
        (resp) => {
          let response = resp.data.value
          this.data = response.rows.map((item) => {
            if (
              item.contract.contractAmount == '' ||
              !item.contract.contractAmount
            ) {
              item.contract.contractAmount = '/'
            } else {
              item.contract.contractAmount = (
                item.contract.contractAmount / 10000
              ).toFixed(2)
            }
            return item
          })
          this.pageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total,
          }
        },
        (error) => {
          reject(error)
        }
      )
    },
    loadData2() {
      let param = {
        pageBean: {
          ...this.pageResult2,
        },
        querys: [
          {
            group: 'advance',
            opener: 'LIKE',
            property: 'pm.ID_',
            relation: 'AND',
            value: this.$route.params.id,
          },
          {
            group: 'advance',
            opener: 'LIKE',
            property: 'bpm.CONTRACT_ID_',
            relation: 'AND',
            value: this.payId,
          },
        ],
        sorter: [{direction: 'DESC', property: 'registerDate'}],
      }
      this.$http
        .post('${cqxy}/biz/processManagement/progressManage/v1/page', param)
        .then(
          (resp) => {
            let response = resp.data.value
            this.dataPayList = response.rows
            this.pageResult2 = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total,
            }
          },
          (error) => {
            reject(error)
          }
        )
    },
  },
}
</script>
<style lang="scss" scoped>
@import '../css/projectCommon.scss';
/deep/ .el-main .content {
  padding: 0 !important;
}
.page-footer {
  height: 30px;
  padding-top: 10px;
  float: right;
}
/deep/ .el-dialog__body {
  padding-top: 10px;
}
.table-border {
  height: 515px;
}
/deep/ .el-table {
  height: calc(100% - 40px) !important;
}
</style>
