<template>
  <div class="auto select-overspread form-horizontal auto">
    <div class="row">
      <blockquote class="bg-info">
        安检单回访
      </blockquote>
    </div>
    <div class="row">
      <div class="col-sm-6 form-group form-fix-width">
        <label class="control-label">回访员</label>
        <input type="text" readonly v-model='model.f_visitman' class="form-control"/>
      </div>
      <div class="col-sm-6 form-group form-fix-width">
        <label class=" control-label">回访时间</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-fix-width">
        <label class=" control-label">质量满意度</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-fix-width">
        <label class=" control-label">服务满意度</label>
        <v-select :value.sync="model.f_servicescore"
                  :value-single="true"
                  :options='servicecase'
                  placeholder='服务态度满意情况'
                  close-on-select>
        </v-select>
      </div>
      <div class="col-sm-6 form-group form-fix-width">
        <label class=" control-label">是否穿工装</label>
        <v-select :value.sync="model.f_is_workclothes"
                  :value-single="true"
                  :options='isNoOptions'
                  placeholder='是否穿工装'
                  close-on-select>
        </v-select>
      </div>
      <div class="col-sm-6 form-group form-fix-width">
        <label class=" control-label">是否收费</label>
        <v-select :value.sync="model.f_is_getmoney"
                  :value-single="true"
                  :options='isNoOptions'
                  placeholder='是否收费'
                  close-on-select>
        </v-select>
      </div>
      <div class="col-sm-12 form-group form-fix-width">
        <label class="control-label" style="width:300px">是否讲解过安全用气注意事项</label>
        <v-select :value.sync="model.f_is_speaksafe"
                  :value-single="true"
                  :options='isNoOptions'
                  placeholder='是否讲解过安全用气注意事项'
                  close-on-select>
        </v-select>
      </div>
      <div class="col-sm-6 form-group form-fix-width">
        <label class="control-label">客户名称</label>
        <input type="text" readonly  v-model='model.f_user_name' class="form-control"/>
      </div>
      <div class="col-sm-4 form-group form-fix-width">
        <label class="control-label">联系电话</label>
        <input type="text"   v-model='model.f_phone' class="form-control"/>
      </div>
      <div class="col-sm-2 form-group form-fix-width" style="padding: 5px;">
        <button class="btn btn-primary" @click="callout(model.f_phone)">呼出</button>
      </div>
      <div class="col-sm-6 form-group form-fix-width">
        <label class="control-label">接听状态</label>
        <v-select :value.sync="model.f_answer_status"
                  :value-single="true"
                  :options='answerStatusOptions'
                  placeholder='请选择接听状态'
                  close-on-select>
        </v-select>
      </div>

    </div>

    <div class="row">
      <div class="col-sm-12 form-group form-fix-width">
        <label class="control-label">客户意见</label>
        <textarea  rows="2" class="ver-textarea" class="form-control" v-model='model.f_remarks'></textarea>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-12 form-group form-fix-width">
        <label class="control-label">备注</label>
        <textarea  rows="2" class="ver-textarea" class="form-control" v-model='model.f_bz'></textarea>
      </div>
    </div>
    <div class="row">
      <button type="button"  class="btn btn-info btn-ln fr"   @click="clearVisit">取消</button>
      <button type="button"  class="btn btn-danger btn-ln fr" @click="saveVisit">提交</button>
    </div>
  </div>
</template>

<script>
  import { HttpResetClass } from 'vue-client'
  import * as Util from '../Util'
  import wxcon from '../../stores/wxconfig'
  export default {
    title: '回访单',
    props: {
      show: false,
      row:Object,
      phone:'',
      outltime:''
    },
    data () {
      return {
        model:{
          f_visitman:'',
          f_visitdate:this.getNowFormatDate(),
          f_qualitycore:'',
          f_servicescore:'',
          f_phone:'',
          f_filiale_id:this.$login.f.orgid,
          f_user_name: '',
          f_remarks:'',
          f_type:'回访',
          f_record_sound:'',
          f_is_speaksafe:'',
          f_is_getmoney:'',
          f_is_workclothes:'',
          f_answer_status:''
        },
        loginUser: this.$login.f,
        aChannel:0,
        qualitycase: [{label:"无", value: ""},...this.$appdata.getParam('质量满意情况')],
        servicecase: [{label:"无", value: ""},...this.$appdata.getParam('服务态度满意情况')],
        isNoOptions:[{label:"否", value: "否"},{label:"是", value: "是"}],
        answerStatusOptions:[]
      }
    },
    methods: {
      //获取当前时间
      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 service
        console.log("保存回访信息")
        if (this.outltime){
          this.model.f_type='呼损'
          service={}
        }else{
          service={
            f_userinfo_id:this.row.f_userinfoid,
            f_user_name:this.row.f_user_name,
            f_address:this.row.f_address,
            id:this.row.f_paper_id,
            f_rvisit_source:'安检回访',

          }
        }
        let data = {model: this.model,
          // service: this.row,
          service: service,
          loginUser: {
            name: this.loginUser.name,
            ename: this.loginUser.ename,
            id: this.loginUser.id,
            f_orgpathstr:this.loginUser.orgpathstr
          },
          // 呼损用（查询条件  时间）
          outltime:this.outltime
        }
        // 获得数据发送地址
        let url = 'af-telephone/rs/logic/telvisit'
        return this.$resetpost(url, data).then((data) => {
          this.id = JSON.parse(data.data.id).id
          // 清除对象数据
          this.model = Object.assign({}, {
            f_qualitycore:'',
            f_servicescore:'',
            f_phone:'',
            f_filiale_id:this.$login.f.orgid,
            f_bz:'',
            f_remarks:'',
            f_type:'回访',
            f_visitdate:this.getNowFormatDate(),
            f_record_sound:'',
            f_is_speaksafe:'',
            f_is_getmoney:'',
            f_is_workclothes:'',
            f_answer_status:''
          })
          this.show=false
        })
      },
      // 取消
      clearVisit () {
        this.show=false
      },
      callout(telnum){
        if(!this.$aChannel){
          this.$showMessage("请先在语音客服页面登录")
          return
        }
        if(telnum){
          console.log("999",this.$aChannel)
          new HttpResetClass().load('POST',`/bridge/callctrl?caller=${this.$aChannel}&callee=${telnum}&authtype=no&opt=CLICK_TO_DIAL&backid=true`,{},{resolveMsg:null,rejectMsg:null}).then(res=>{
            if(res.data === 200){
              this.$showMessage('正在呼出')
              this.model.f_record_sound = res.data
            }else if (res.data === 400){
              this.$showMessage('参数错误，或opt参数缺失')
            }else if (res.data === 402){
              this.$showMessage('授权限制')
            }else if (res.data === 486){
              this.$showMessage('目标分机忙或网关线路忙')
            }else if (res.data === 403){
              this.$showMessage('黑名单号码，禁止拨打')
            }else if (res.data === 502){
              this.$showMessage('指定的网关账号类型错误，不是出群网关，网关账号离线')
            }else if (res.data === 500){
              this.$showMessage('系统错误')
            }else if (res.data === 606){
              this.$showMessage('opt参数填写错误')
            }
          })
        }else{
          console.log("无呼出电话")
        }
      },
    },
    watch: {
      'show' () {
        console.log("show改变")
        this.$emit('show-obj', {showVisit: this.show})
      },
      'row' () {
        console.log("row改变")
        this.show=row;
        this.$emit('show-obj', {showVisit: this.show})
      },
      'phone'(val){
        this.model.f_user_phone = val
      }
    },
    ready(){
      console.log(this.row)
      this.answerStatusOptions = this.$appdata.getParam('工单回访接听状态')
      let sql = 'safe_singleTable_OrderBy'
      let condition = {
        items: 'tongdao',
        tablename: 'T_IPTONGDAO',
        condition: `loginip = '${this.loginUser.loginip}'`,
        orderitem: 'id'
      }
      console.log('IP地址：', this.loginUser.loginip)
      let http = new HttpResetClass()
      http.load('POST', `/af-telephone/rs/logic/tel_getOneData`,  {data: {sql: sql, params: condition}},  {resolveMsg: null, rejectMsg: null}).then((req) => {
        this.aChannel = parseInt(req.data.tongdao);
        console.log('tongdao：', this.aChannel)
      })
      this.model.f_visitman = this.$login.f.name
      this.model.f_phone = this.row.f_user_phone
      this.model.f_user_name = this.row.f_user_name
    }
  }
</script>>

