<template xmlns="http://www.w3.org/1999/html">
  <div class="auto select-overspread form-horizontal auto">
    <div class="row workOrderInfo" >
      <div class="row">
        <blockquote class="bg-info">
          回访
        </blockquote>
      </div>
      <div class="row roee">
        <div class="col-sm-6 form-group form-input-group" >
          <label class="font_normal_body" style="width: 25%">回&ensp;访&ensp;员</label>
          <input  type="text" class="form-control" v-model="model.f_visitman" placeholder='回访员' >
        </div>
        <div class="col-sm-6 form-group form-input-group" >
          <label class="font_normal_body" style="width: 25%">回访时间</label>
          <datepicker  placeholder="回访时间"
                       :value.sync="model.f_visitdate"
                       :format="'yyyy-MM-dd HH:mm:ss'"
          ></datepicker>
        </div>
<!--        <div class="col-sm-6 form-group form-input-group">-->
<!--          <label class="font_normal_body" style="width: 25%">质量满意度</label>-->
<!--          <v-select :value.sync="model.f_qualitycore"-->
<!--                    :value-single="true"-->
<!--                    :options='qualitycase'-->
<!--                    placeholder='质量满意情况'-->
<!--                    close-on-select>-->
<!--          </v-select>-->
<!--        </div>-->
<!--        <div class="col-sm-6 form-group form-input-group">-->
<!--          <label class=" font_normal_body" style="width: 25%">服务满意度</label>-->
<!--          <v-select :value.sync="model.f_servicescore"-->
<!--                    v-model="model.f_servicescore"-->
<!--                    :value-single="true"-->
<!--                    :options='servicecase'-->
<!--                    placeholder='服务态度满意情况'-->
<!--                    close-on-select>-->
<!--          </v-select>-->
<!--        </div>-->
<!--        <div class="col-sm-6 form-group form-input-group">-->
<!--          <label class="font_normal_body" style="width: 25%">联系电话</label>-->
<!--          <input type="text"  v-model='model.f_phone' class="form-control"/>-->
<!--          <button class="button_search button_spacing" @click="callout(model.f_phone)">呼出</button>-->
<!--        </div>-->
        <div class="col-sm-6 form-group form-input-group">
          <label class="font_normal_body" style="width: 25%">地址</label>
          <input type="text"  :value='row.f_address' class="form-control" disabled/>
        </div>
        <div class="col-sm-12  form-input-group">
          <label class="font_normal_body" style="width: 12.5%">客户意见</label>
          <textarea name="name" rows="3" v-model="model.f_remarks" class="form-control ver-textarea"
                    style="width: 80%"></textarea>
        </div>
        <div class="col-sm-12  form-input-group" style="margin-top: 6px">
          <label class="font_normal_body" style="width: 12.5%">备注</label>
          <textarea name="name" rows="4" v-model="model.f_bz" class="form-control ver-textarea"
                    style="width: 80%"></textarea>
        </div>
        <div class="row button-range form-group  form-input-group">
          <button type="button" name="button"
                  class="button_search button_spacing" @click="saveVisit">提交</button>
          <button type="button" name="button" style="background-color: #5ac0d9;border-radius: 4px;"
                  class="button_spacing button_search" @click="clearVisit">取消</button>
        </div>
      </div>
    </div>
    <modal :show.sync="showcalloutResult" width="50%"  backdrop="false">
      <header slot="modal-header" class="modal-header">
        <center><h4 class="modal-title ">{{showTitle}}结果</h4></center>
      </header>
      <article slot="modal-body" class="modal-body" style="height: 100px;padding-top: 15px!important;">
        <div v-show="!calloutResult"><label>正在{{ showTitle }}，请稍后。。。。。。</label></div>
        <div v-show="calloutResult">
          <div class="row auto" v-show="calloutResult.area">
            <label>真实归属地:</label><span>{{calloutResult.area}}</span>
          </div>
          <div class="row auto" v-show="calloutResult.calloutNo">
            <label>真实呼出号码:</label><span>{{calloutResult.calloutNo}}</span>
          </div>
          <div class="row auto" v-show="calloutResult.err">
            <label>其他信息:</label><span>{{calloutResult.err}}</span>
          </div>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-success" @click='calloutConfirm()'>确认</button>
      </footer>
    </modal>
  </div>
</template>

<script>
  import { HttpResetClass } from 'vue-client'
  import * as Util from '../Util'
  import wxcon from '../../stores/wxconfig'
  export default {
    title: '回访单',
    props: {
      contextxianshi:null,
      row:Object,
      phone:'',
      idwavfile:'',
      outltime:'',
      showcalloutResult:false,
      calloutResult:null,
      showTitle:'呼出',
      userip:'000.000.000.000'

    },
    data () {
      return {

        model:{
          f_again_revisit: '是',
          f_visitman:'',
          f_visitdate:this.getNowFormatDate(),
          f_qualitycore:'满意',
          f_servicescore:'满意',
          f_phone:'',
          f_remarks:'',
          f_type:'回访',
          f_record_sound:'',
          f_bz:''
        },
        idwavfile:'',
        loginUser: this.$login.f,
        aChannel:0,
        aModule:1,
        qualitycase: this.$appdata.getParam('质量满意情况'),
        servicecase: this.$appdata.getParam('服务态度满意情况')
      }
    },
    methods: {
      calloutConfirm(){
        this.calloutResult=null
        this.showcalloutResult=false
      },
      //获取当前时间
      getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var hour = date.getHours();
        var min = date.getMinutes();
        var second = date.getSeconds();
        if (month >= 1 && month <= 9) {
          month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
          strDate = "0" + strDate;
        }
        if (hour >= 0 && hour <= 9) {
          hour = "0" + hour;
        }
        if (min >= 0 && min <= 9) {
          min = "0" + min;
        }
        if (second >= 0 && second <= 9) {
          second = "0" + second;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
          + " " + hour + seperator2 + min
          + seperator2 + second;
        return currentdate;
      },
      // 提交
      saveVisit () {
        let sql = `update t_devices_items set f_is_visit = '是',f_visitdate='${this.model.f_visitdate}',f_visitman='${this.model.f_visitman}',f_remarks='${this.model.f_remarks}',f_bz='${this.model.f_bz}',f_qualitycore='${this.model.f_qualitycore}',f_servicescore='${this.model.f_servicescore}' where id = '${this.row.f_defect_id}' `
        let http = new HttpResetClass()
        http.load('POST', 'rs/logic/runSQL', {data: {sql: sql}},
          {resolveMsg: null, rejectMsg: null}).then(resp=>{
          this.$showMessage('提交完成')
          this.$emit('visitback','nodo')
        }).catch(error=>{
          this.$showMessage('提交失败')
        })
      },
      // 取消
      clearVisit () {
        this.$emit('show-obj',{})
      },
      callout(telnum){
        if(telnum){
          let http = new HttpResetClass()
          try{
            http.load('POST', wxcon.voiceUrl, {
              aId: this.$login.f.id,
              aChannel: this.aChannel,
              aModule: this.aModule,
              aBzType:"callout",
              bzExtra: telnum,
              bzId: telnum,
              aName: this.$login.f.name,
              RoleId:this.$login.f.rolesnames,
              sendTime:Util.toStandardTimeString()
            }, {resolveMsg: null, rejectMsg: null}).then((req) => {
              this.calloutResult = req.data.calloutResult
              if (req.data.desc === '呼出失败') {
                this.$showAlert(`呼出${telnum}失败`, 'danger', 0)
              }else{
                this.showcalloutResult=true
                this.showTitle='呼出'
                // 返回录音ID 存在回访数据里
                this.model.f_record_sound = req.data.RecordsID
              }
            })
          }catch(e){
            this.$showAlert(`${e.data},呼出失败`, 'danger', 0)
            this.callContent = '呼出失败'
          }
        }else{
          this.$showAlert(`无电话号码`, 'danger', 0)
          this.callContent = '呼出失败'
        }
      },
    },
    watch: {
      'phone'(val){
        this.model.f_phone = val
      }
    },
    ready(){
      let sql = 'tel_singleTable_OrderBy'
      let condition = {
        items: 'tongdao,mokuai',
        tablename: 'T_IPTONGDAO',
        condition: `loginip = '${this.userip}'`,
        orderitem: 'id'
      }
      //tag
      let http = new HttpResetClass()
      http.load('POST', `rs/logic/tel_getOneData`,  {data: {sql: sql, params: condition}},  {resolveMsg: null, rejectMsg: null}).then((req) => {
        this.aChannel = parseInt(req.data.tongdao)
        this.aModule = parseInt(req.data.mokuai)
      })
      this.model.f_visitman = this.$login.f.name
      this.model.f_phone = this.phone
      this.model.f_bz = this.row ? this.row.f_remarks:''
    }
  }
</script>
<style scoped lang="less">
.workOrderInfo{
  .roee {
    div {
      margin-top: 10px;
      padding-right: 3px;
    }
    label {
      display: inline-block;
      height: 100%;
      min-width: 100px;
      text-align: justify;
      text-align-last: justify;
    }
  }
}
</style>

