<template>
  <el-dialog :title="title" v-if="visible" :visible.sync="visible">
    <el-card>
      <div class="table-title">{{tableData.no}}</div>
      <el-row :span="18" :offset="3">
        <el-table
          :data="items2"
          :header-cell-style="{background:'#e0f3ff',color:'#5f95b7'}"
          border
          stripe
          highlight-current-row="true"
          style="width: 100%"
        >
          <el-table-column align="center" prop="createAt" label="询价时间"></el-table-column>
          <el-table-column align="center" prop="quoteEndAt" label="截止时间"></el-table-column>
          <el-table-column align="center" prop="address" label="发送方式">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.byEmail==1" >邮件</el-tag>
              <el-tag v-if="scope.row.bySms==1">短信</el-tag>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
    </el-card>
    <el-card>
      <div style>报价/询价人数：{{count}}人</div>
      <el-table
        :data="items"
        :header-cell-style="{background:'#e0f3ff',color:'#5f95b7'}"
        border
        stripe
        highlight-current-row="true"
        style="width: 100%"
      >
        <el-table-column align="center" prop="counterpartyName" label="报价银行"></el-table-column>
        <el-table-column align="center" prop="realName" label="报价联络人"></el-table-column>
        <el-table-column align="center" prop="address" label="是否已报价">
          <template  slot-scope="scope">
            <el-tag v-if="scope.row.status==1" type="success">已报价</el-tag>
            <el-tag v-if="scope.row.status==2">暂不参与</el-tag>
            <el-tag v-if="scope.row.status==0" type="danger">未报价</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="email" label="邮件">
          <template slot-scope="scope">
            <span v-html="scope.row.email"></span>

            <br>
            <el-button type="text" v-if="model.status!=1" @click="doSend(scope.row,1)">发送邮件</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="mobile" label="手机号">

          <template slot-scope="scope">
            <span v-html="scope.row.mobile"></span>
            <br>
            <!-- <el-button type="text" @click="doSend(scope.row,12)">发送短信</el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <span slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      <el-button @click="visible = false">关闭</el-button> -->
    </span>
  </el-dialog>
</template>

<script>
// import moment from 'moment';
// //import util from '@/util'
export default {
  data() {
    return {
      items: [],
      title:"查看",
      visible: false,
      model: {},
      tableData: {},
      items2: [],
    };
  },
  computed: {
    count() {
      let a = 0;
      this.items.forEach(element => {
        if (element.status != 0) {
          a++;
        }
      });
      return a + "/" + this.items.length;
    }
  },
  created() {},
  methods: {
    init(priceInquiryRow, type) {
      priceInquiryRow = priceInquiryRow||{};
      let priceinquiryId = priceInquiryRow.priceinquiryId;
      let status = priceInquiryRow.status;
      if(!priceinquiryId){
        console.error("invalid priceinquiryId");
        return;
      }
      this.visible = true;
      this.tabActive = "userInfo";
      let self = this;
      if (this.$refs["form"]) {
        this.$refs["form"].resetFields();
      }

      if (type == 1 || type == 2 || type == 3) {
        this.model.priceInquiryId = priceinquiryId;
        this.model.status = status;
        if (type == 2) {
          //如果是审核进来   type就==2
          this.disabled = true;
          this.formAction = 2;
          this.btn = "审核";
          this.title = "审核";
        } else if (type == 1) {
          self.formAction = 1;
          this.title = "编辑";
        } else {
          this.disabled = true;
          this.formAction = 3;
          this.btn = "确定";
          this.title = "查看";
        }
        let model = self.model;
        var obj = {
          url: this.$url.priceInquiry.getById,
          data: {
            priceinquiryId: priceinquiryId
          }
        };
        this.common.httpPost(obj, success);
        function success(data) {

          self.tableData = JSON.parse(JSON.stringify(data));
          self.items2 = [];
          self.items2.push(JSON.parse(JSON.stringify(data)));
          self.items = data.priceInquiryTos;
        }
      } else {
        self.formAction = 0;
      }
    },
    doSend(row,type){
      let self = this;
      let urls = '';
      if(type==1){
        if(self.tableData.messageEmailConfigId){
          urls = this.$url.priceInquiry.sendPriceEmail
        }else{
          urls = this.$url.priceInquiry.sendEmail
        }

      }else{
        urls = this.$url.priceInquiry.sendSms
      }
      var obj = {
        url: urls,
        data: {
          priceinquiryId:this.model.priceInquiryId,
          counterpartyContactId:row.counterpartycontactId,
        }};
      this.common.httpPost(obj, success);
      function success(data) {
         self.$message({
           message:"已发送",
           type:"success"
         })
      }

    },
    doSearch(value) {
      this.form.page = value;

      let self = this;
      var obj = {
        url: "/activiti/getMadelByPage",
        data: this.form
      };
      this.common.httpPost(obj, success);
      function success(data) {
        self.list = data.data.rows;
        self.total = data.data.total;
      }
    }
  }
};
</script>
