<template>
  <el-dialog
    title="查看"
    width="70%"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <div style="margin-left: 20px;margin-right: 20px">
      <e-desc title="基本信息" column="3">
        <e-desc-item label="沟通编码">{{dataForm.coCode}}</e-desc-item>
        <e-desc-item label="客户名称">{{dataForm.customerName}}</e-desc-item>
        <e-desc-item label="联系人">{{dataForm.bizManagerName}}</e-desc-item>
        <e-desc-item label="沟通类别">{{dataForm.coType}}</e-desc-item>
        <e-desc-item label="备注说明" span="2">{{dataForm.notes}}</e-desc-item>
      </e-desc>
      <e-desc title="订单产品明细">
        <el-table
          :data="cusRCommProductVOS"
          border
          style="width: 100%;">
          <el-table-column
            label="序号"
            type="index"
            width="50"
            align="center">
          </el-table-column>
          <el-table-column
            prop="productName"
            header-align="center"
            align="center"
            label="产品名称">
          </el-table-column>
          <el-table-column
            prop="cnt"
            header-align="center"
            align="center"
            label="数量">
          </el-table-column>
          <el-table-column
            prop="price"
            header-align="center"
            align="center"
            label="含税单价">
          </el-table-column>
          <el-table-column
            prop="amount"
            header-align="center"
            align="center"
            label="含税总价">
            <template slot-scope="scope">
              <span>{{ (scope.row.cnt*scope.row.price).toFixed(2) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="rate"
            header-align="center"
            align="center"
            label="税率">
            <template slot-scope="scope">
              <span>
                {{scope.row.rate}} %
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="notes"
            header-align="center"
            align="center"
            label="备注">
          </el-table-column>
        </el-table>
      </e-desc>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">返回</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import EDesc from '../common/e-desc'
  import EDescItem from '../common/e-desc-item'
  import { getCoDetail } from '@/api/cus'
  export default {
    name: 'communicate-detail',
    components: {
      EDesc, EDescItem
    },
    data () {
      return {
        visible: false,
        id: 0,
        dataForm: {},
        cusRCommProductVOS: [],
        fileList: []
      }
    },
    methods: {
      async init (id) {
        this.visible = true
        this.id = id || 0
        this.cusRCommProductVOS = []
        this.getDetails()
      },
      getDetails () {
        getCoDetail(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
            // 附件显示
            this.fileList = []
            data.data.attachList.forEach((item) => {
              this.fileList.push({
                name: item.fileName,
                url: item.url,
                id: item.url
              })
            })
            if (data.data.cusRCommProductVOS) {
              data.data.cusRCommProductVOS.forEach((item) => {
                this.cusRCommProductVOS.push({
                  cnt: item.cnt,
                  price: item.price,
                  productId: item.productId,
                  rate: item.rate,
                  productName: item.productName,
                  notes: item.notes
                })
              })
            }
          }
        })
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
.title{
  padding: 10px 0 ;
}
</style>
