<!--
  @description:供货记录
  @Modifier:qk
  @routerPath:supplierDeclaration/supplier/supplYrecord
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <div>
      <section>
        <div style="margin-bottom:10px;">
          <el-button type="primary" @click="addSupplyRecord('')">
            添加供货记录
          </el-button>
        </div>
        <div>
          <el-table
            ref="smallTable"
            v-loading="loading"
            :data="tableData"
          >
            <el-table-column
              type="index"
              label="序号"
              width="60px"
              align="center"
            />
            <el-table-column
              prop="purchasingUnit"
              header-align="center"
              label="采购单位"
              min-width="200"
            />
            <el-table-column
              align="center"
              prop="partners"
              label="合同合作方"
              width="110"
            >
              <template slot-scope="scope">
                <span v-for="(item,index) in supplierPartnersList" v-if="scope.row.partners === item.typecode" :key="index">
                  {{ item.typename }}
                </span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="contractDate"
              label="签定日期"
              width="110"
            />
            <el-table-column
              header-align="center"
              label="合同金额(万元)"
              prop="contractAmount"
              align="right"
              min-width="110"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.contractAmount?moneyFormat(Number(scope.row.contractAmount)):scope.row.contractAmount }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="买方业务代表"
              prop="buyerRepresentative"
              header-align="center"
              width="110"
            />
            <el-table-column
              label="买方业务代表联系电话"
              prop="buyerLinker"
              align="center"
              width="150"
            />
            <el-table-column
              label="合同扫描"
              prop="contractAttr"
              header-align="center"
              min-width="160"
            >
              <template slot-scope="scope">
                <downloadFile :data="scope.row.supplyRecordFile" />
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              label="操作"
              align="center"
              width="160"
            >
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click.stop="addSupplyRecord(scope.row.id,scope.row.oldId)"
                >
                  [编辑]
                </el-link>
                <el-link
                  type="primary"
                  @click.stop="seeSupplyRecord(scope.row)"
                >
                  [查看]
                </el-link>
                <el-link
                  type="primary"
                  @click.stop="deleteSupplyRecord(scope.row)"
                >
                  [删除]
                </el-link>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <pagination :pagination-data="paginationData" @change="loadData" />
        </div>
        <!-- 审核意见 -->
        <inforaMtionAudit />
        <!-- 添加供货/编辑供货 -->
        <supplYrecords :data="dialogData" @supplYrecordsInfo="supplYrecordsInfo" />
        <!-- 查看供货 -->
        <supplYrecordDetail v-if="dialogDetailData.dialog" :data="dialogDetailData" />
      </section>
    </div>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 编辑申报材料 -->
          <template v-if="pageType==='declarationFirst'">
            <el-button @click="prevStep">
              上一步
            </el-button>
            <el-button :loading="confirmLoading" type="primary" @click="nextStep('form')">
              下一步
            </el-button>
          </template>
          <!-- 申报材料变更 -->
          <template v-if="pageType==='declarationChange'">
            <el-button :loading="confirmLoading" type="primary" @click="submitData('form')">
              提交
            </el-button>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* 接口*/
import { listSupplyRecordPages, removeSupplyRecord } from '@/api/supplier/supplierSupplyRecord'
// import { listChangeableSupplyRecordPages } from '@/api/supplier/supplierChange'
import { changeSupplierInfoSubmit } from '@/api/supplier/supplierChange.js'// 财务状态，供货记录，和资质证书变更提交
/* 公用方法*/
import { moneyFormat, filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
import { declareHegSupperGroupMixin } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperGroupMixin'// 供应商-字典
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 附件
import inforaMtionAudit from '../inforaMtionAudit/inforaMtionAudit-detail' // 审核意见组件
import pagination from '@comp/common/pagination/pagination'// 分页
import supplYrecords from './supplYrecord-dialog' // 添加供货
import supplYrecordDetail from './supplYrecordDetail-dialog' // 查看供货
export default {
  name: 'ProjectManagerTenderList',
  components: {
    downloadFile, // 附件
    pagination, // 分页
    supplYrecords, // 添加供货
    supplYrecordDetail, // 查看供货
    inforaMtionAudit
  },
  mixins: [ListMixin, declareHegSupperMixins, declareHegSupperGroupMixin],
  data() {
    return {
      moneyFormat: moneyFormat, // 转千分位
      pageType: this.$route.meta.type, // 当前页面所处状态 declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时
      searchForm: {
        departId: this.$route.query.departId// 机构id
      },
      confirmLoading: false, // Loading
      loading: false, // 列表Loading
      // 添加/编辑供货记录
      dialogData: {
        dialog: false,
        id: '', // 主键Id
        oldId: '' // 修改时用的Id
      },
      // 查看供货记录
      dialogDetailData: {
        dialog: false,
        id: '', // 主键Id
        oldId: '' // 修改时用的Id
      },
      tableData: []// 列表
    }
  },
  created() {
    this.loadData()// 获取数据
    this.getSupplyRecordDictionaries()// 获取字典信息
  },
  methods: {
    // 添加供货记录-初始化
    supplYrecordsInfo() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()// 获取数据
    },
    // 获取数据
    loadData() {
      this.loading = true
      const params = this.getQueryParams()// 查询条件
      listSupplyRecordPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
        this.tableData.forEach(item => {
          item.contractDate = this.$Moment(item.contractDate).format(this.momentDate)// 签订日期
          // 合同扫描件
          item.supplyRecordFile = {
            ...this.supplyRecordFile,
            bizId: item.id
          }
        })
      }).catch(() => {

      })
    },
    // 新增/编辑供货记录
    addSupplyRecord(id, oldId) {
      this.dialogData = {
        dialog: true,
        id: id, // 主键Id
        oldId: oldId // 修改时用的Id
      }
    },
    // 查看供货记录
    seeSupplyRecord(row) {
      this.dialogDetailData = {
        dialog: true,
        id: row.id, // 主键Id
        oldId: row.oldId // 修改时用的Id
      }
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 删除
    deleteSupplyRecord(row) {
      this.$confirm('确定删除记录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = [{
          id: row.id, // 项目id
          oldId: row.oldId
        }]
        removeSupplyRecord(data).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.loadData()
        })
      }).catch(() => {
      })
    },
    // 保存数据接口下一步
    saveData(type) {
      this.confirmLoading = true// btnLoding
      const pathData = {
        ...this.$route.query
      }
      if (type === 'next') { // 下一步
        this.$emit('stepPage', 'next', pathData)// 步骤条切换方法 next 下一步
      } else if (type === 'save') { // 保存
      }
      this.confirmLoading = false// btnLoding
    },
    // 申报材料变更-提交
    submitData() {
      this.$confirm('确认提交审核吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = this.searchForm
        changeSupplierInfoSubmit(data).then((response) => {
          if (response.header.ret === '0') {
            if (this.$route.meta.type === 'declarationChange') {
              this.$nextTick(() => {
                this.$emit('showStatuschage')// 传给父集组件参数-审核状态-审核图片展示
              })
            }
            this.saveData('save')
            this.$message({
              type: 'success',
              message: '提交成功'
            })
          } else {
            this.$message({
              type: 'warning',
              message: '提交失败'
            })
          }
        })
      }).catch(() => {
      })
    },
    // 上一步
    prevStep() {
    // route携带参数
      const pathData = {
        ...this.$route.query
      }
      this.$emit('stepPage', 'prev', pathData)// 步骤条切换方法 prev 上一步
    },
    // 暂存，进行下一步
    nextStep(formName) {
      this.saveData('next')// 下一步
    }
  }
}
</script>
<style lang="less" scoped>

</style>
