<template>
  <div class="" v-if="showview">
    <show-back-reason :selectdata="show_data"></show-back-reason>
    <service-view v-ref:serviceview :data="show_data"></service-view>
  </div>
</template>
<script>
import {HttpResetClass} from 'vue-client'
import {isEmpty} from '../../../Util'
import Vue from "vue";

// Date格式化
Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "H+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    "S": this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

export default {
  title: '报建流程业务控制层',
  props: ['selectdata'],
  data () {
    return {
      data: null, // 数据库数据，json配置文件数据的数据集合
      json_datas: null, // Json配置文件集合
      showview: false, // 控制显示service-view组件
      show_data: null, // 给view层显示的数据
      area: {}, // 小区详细
      config: {}
    }
  },
  ready () {
    this.refurbish()
  },
  methods: {
    // 组件初始化操作
    async refurbish() {
      this.json_datas = Vue.prototype.$workflow_vue
      let sum = 0
      let jsonData = {}
      if (!this.json_datas || !this.json_datas.activitys || this.json_datas.activitys.length === 0) {
        this.$showMessage("网络故障，请刷新页面")
        return
      }
      this.json_datas.activitys.forEach(item => {
        if (this.selectdata.defname === item.title) {
          jsonData = item  // 拿到当前节点的json配置信息
          sum++ // 节点名一样的个数
        }
      })

      if (sum === 0) {
        this.$showMessage(`没有在JSON配置文件中找到活动名为:(${this.selectdata.defname})的节点配置`)
        return
      }
      if (sum > 1) {
        this.$showMessage(`在JSON配置文件中找到活动名为:(${this.selectdata.defname})的节点配置:${sum}个`)
        return
      }
      this.selectdata = Object.assign({}, this.selectdata, jsonData)

      // fields 字段填充值
      for (const item of this.selectdata.fields) {
        if (!item.value) {
          item.value = null
        }

        if (!item.value && (item.default || item.default === 0) && item.type !== 'datepicker') {
          if (item.eval) {
            item.value = eval(item.default)
          } else {
            item.value = item.default
          }
        }

        if (this.selectdata[item.field]) {
          // 将json字符串格式化赋值给value
          if (String(this.selectdata[item.field]).startsWith("{")) {
            item.value = JSON.parse(this.selectdata[item.field])
          } else {
            item.value = this.selectdata[item.field]
          }
        }
        if (this.selectdata[item.field] === 0) {
          item.value = 0
        }

        // datepicker
        if (item.type === 'datepicker' && !item.value && item.default) {
          item.value = new Date().Format(`${item.format ? item.format : 'yyyy-MM-dd HH:mm:ss'}`)
        }

        // 如果配置类型为select,优先从参数列表获取options
        if (item.type === 'select' || item.type === 'checkbox') {
          if (item.param) {
            let temp = this.$appdata.getParam(item.label)

            if (temp && temp.length > 0) {
              item.options = temp
            }

            if (item.paramLabel) {
              temp = this.$appdata.getParam(item.paramLabel)
              if (temp && temp.length > 0) {
                item.options = temp
              }
            }
          }
        }
        if (item.ready) {
          item.options = await this[item.ready]()
        }
        if (item.type === 'checkbox') {
          if (this.selectdata[item.field]) {
            item.value = JSON.parse(this.selectdata[item.field])
          } else {
            item.value = []
          }
        }
        if(this.selectdata.state === '结束'){
          item.readonly = true
          item.disabled = true
          console.log('当前defname'+this.selectdata.defname+'当前title'+this.selectdata.title)
        }
        this.selectdata[item.field] = item.value
      }

      // 控制组件
      if (this.selectdata.components) {
        this.selectdata.components.forEach(item => {
          if (!item.mark) {
            item.mark = 0
          }
          if(this.selectdata.state === '结束'){
          item.mark = 1
        }
        })
      }

      // 初始化onetomany
      if (this.selectdata.onetomany) {
        for (const item of this.selectdata.onetomany) {
          let res = null
          if (item.queryEvent) {
            res = this[item.queryEvent]()
          } else {
            let data = {
              tablename: item.tables[0],
              condition: `f_process_id='${this.selectdata.f_process_id}'`
            }
            let http = new HttpResetClass()
            res = await http.load(
              'POST',
              'rs/sql/applySingleTable',
              {data: data},
              {resolveMsg: null, rejectMsg: 'onetomany查询失败'}
            )
          }
          item.rows = res.data
          // 初始化onetomany中的fields
          for (const field of item.fields) {
            if (!field.value) {
              if (field.value !== 0) {
                field.value = null
              }
            }

            if (field.default || field.default === 0) {
              field.value = field.default
            }

            // datepicker
            if (field.type === 'datepicker' && !field.value && field.default) {
              field.value = new Date().Format(`${field.format ? field.format : 'yyyy-MM-dd HH:mm:ss'}`)
            }

            if (field.type === 'select') {

              let temp = this.$appdata.getParam(field.label)

              if (temp && temp.length > 0) {
                field.options = temp
              }

              if (field.paramLabel) {
                temp = this.$appdata.getParam(field.paramLabel)
                if (temp && temp.length > 0) {
                  item.options = temp
                }
              }
            }
          }
        }
      }

      // 初始化 buttons_fields
      for (const item of this.selectdata.buttons) {
        if (item.button_name === '下发' || item.button_name === '转派') {

          let data = {
            source: item.source,
            userid: this.$login.f.id
          }
          if (item.sourceMethod) {
            data.source = this[item.sourceMethod]()
          }
          if (!data.source) {
            this.$showMessage("请配置获取人员表达式")
            return
          }
          let http = new HttpResetClass()
          let res = await http.load(
            'POST',
            'rs/search',
            {data: data},
            {resolveMsg: null, rejectMsg: '下发人员查询失败！！！'}
          )
          let options = res.data.map(source => {
            return {
              "label": source.name,
              "value": source.id
            }
          })
          if (item.button_fields.length !== 1) {
            this.$showMessage("下发有且只能有一个字段！！！")
            return
          }
          item.button_fields[0].options = options
        }
        if (item.button_fields) {
          item.button_fields.forEach(x => {
            // 如果配置类型为select,优先从参数列表获取options
            if (x.type === 'select') {

              if (x.param) {
                let temp = this.$appdata.getParam(x.label)

                if (temp && temp.length > 0) {
                  x.options = temp
                }

                if (x.paramLabel) {
                  temp = this.$appdata.getParam(x.paramLabel)
                  if (temp && temp.length > 0) {
                    x.options = temp
                  }
                }
              }

            }
          })
        }
        if(this.selectdata.state === '结束'){
          item.hidden = true
        }
      }

      if (this.selectdata.f_apply_nature === '散户' && this.selectdata.defname === '现场勘察') {
        for (const item of this.selectdata.fields) {
          if (item.label.includes('安装户数')) {
            item.readonly = true
          }
        }
      }
      // 消除双向绑定，避免子组件（显示层）数据更改，父组件（控制层）也更改
      let  temp = JSON.parse(JSON.stringify(this.selectdata))
      this.show_data = temp
      if ((this.selectdata.f_apply_type =='非民用报建' || this.selectdata.f_apply_type =='民用报建' || this.selectdata.f_apply_type =='设备变更')&&this.selectdata.defname === '报装缴费'){
        let num = Number(this.$appdata.getSingleValue('税率'))
        let f_due_money =Number(this.selectdata.f_due_money)
        let tem = ( f_due_money - (f_due_money/(1+num)).toFixed(2)).toFixed(2)
        this.show_data.f_budget_money = tem
        this.setLabelValue('税额',tem)
      }
      if ((this.selectdata.f_apply_type =='非民用报建' || this.selectdata.f_apply_type =='民用报建' || this.selectdata.f_apply_type =='设备变更')&&this.selectdata.defname === '收费标准'){
        let str = '项目名称：天然气安装工程；项目地址：'+ this.show_data.f_address
        this.show_data.f_paper_remarks = str
        this.setLabelValue('发票备注',str)
      }
      if (this.show_data.f_apply_type === '改线业务' && this.show_data.defname === '报建受理'){
        let str = '项目名称：天然气整改工程；项目地址：'+ this.show_data.f_address
        this.show_data.f_paper_remarks = str
        this.setLabelValue('发票备注',str)
      }
      this.$nextTick(() => {
        this.showview = true
      })

    },
    // 金额转大写
    smalltoBIG(n) {
      let fraction = ['角', '分'];
      let digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
      let unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']];
      let head = n < 0 ? '欠' : '';
      n = Math.abs(n);

      let s = '';

      for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
      }
      s = s || '整';
      n = Math.floor(n);

      for (var i = 0; i < unit[0].length && n > 0; i++) {
        let p = '';
        for (var j = 0; j < unit[1].length && n > 0; j++) {
          p = digit[n % 10] + unit[1][j] + p;
          n = Math.floor(n / 10);
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
      }
      return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整')
    },
    getLableValue(label) {
      for (const item of this.show_data.fields) {
        if (item.label === label && item.type !== 'number') {
          return item.value || ''
        }
        if (item.label === label && item.type === 'number') {
          return item.value || 0
        }
      }
    },
    getLableOptions(label) {
      for (const item of this.show_data.fields) {
        if (item.label === label) {
          return item.options
        }
      }
    },
    setLabelValue(label, value) {
      for (const item of this.show_data.fields) {
        if (item.label === label) {
          item.value = value
          this.show_data[item.field] = value
        }
      }
    },
    setLabelOptions(label, options) {
      for (const item of this.show_data.fields) {
        if (item.label === label) {
          item.options = options
        }
      }
    },
    showLabels(...labels) {
      for (const item of this.show_data.fields) {
        if (labels.includes(item.label)) {
          item.hidden = false
        }
      }
    },
    hideLabels(...labels) {
      for (const item of this.show_data.fields) {
        if (labels.includes(item.label)) {
          item.hidden = true
        }
      }
    },
    showButtons(...buttons) {
      for (const item of this.show_data.buttons) {
        if (buttons.includes(item.button_name)) {
          item.hidden = false
        }
      }
    },
    hideButtons(...buttons) {
      for (const item of this.show_data.buttons) {
        if (buttons.includes(item.button_name)) {
          item.hidden = true
        }
      }
    },
    requiredLabels(...labels) {
      for (const item of this.show_data.fields) {
        if (labels.includes(item.label)) {
          item.required = true
        }
      }
    },
    electiveLabels(...labels) {
      for (const item of this.show_data.fields) {
        if (labels.includes(item.label)) {
          item.required = false
        }
      }
    },
    readonlyLabels(...labels) {
      for (const item of this.show_data.fields) {
        if (labels.includes(item.label)) {
          item.readonly = true
          item.disabled = true
        }
      }
    },
    readwriteLabels(...labels) {
      for (const item of this.show_data.fields) {
        if (labels.includes(item.label)) {
          item.readonly = false
          item.disabled = false
        }
      }
    },
    disabledButtons(...buttons) {
      for (const item of this.show_data.buttons) {
        if (buttons.includes(item.button_name)) {
          item.disabled = true
        }
      }
    },
    enableButtons(...buttons) {
      for (const item of this.show_data.buttons) {
        if (buttons.includes(item.button_name)) {
          item.disabled = false
        }
      }
    },
    showComponents(...titles) {
      for (const item of this.show_data.components) {
        if (titles.includes(item.title) && item.device === 'pc') {
          item.hidden = false
        }
      }
    },
    hideComponents(...titles) {
      for (const item of this.show_data.components) {
        if (titles.includes(item.title) && item.device === 'pc') {
          item.hidden = true
        }
      }
    },
    async checkDuplicate(index) {
      let http = new HttpResetClass()
      let data = {
        tablename: 't_apply',
        condition: `${this.show_data.fields[index].field} = '${this.show_data.fields[index].value}'`
      }
      let res = await http.load('POST', 'rs/sql/applySingleTable', {data: data}, {
        resolveMsg: null,
        rejectMsg: `${this.show_data.fields[index].label}查询失败`
      })
      if (res.data.length > 0) {
        this.show_data.fields[index].value = null
        this.$showMessage(`${this.show_data.fields[index].label}已存在！！！`)
      }
    },
    // 获取片区
    async getSliceArea () {
      let data = {
        source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
        userid: this.$login.f.id
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '片区查询失败！！！'}
      )

      return res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      })
    },
    // 获取区县
    async getPcd () {
      let data = {
        tablename: 't_pcd',
        condition: `f_filialeid = '${this.$login.f.orgid}'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '区县查询失败！！！'}
      )

      return res.data.map(item => {
        return {
          label: item.f_pcd,
          value: item.f_pcd
        }
      })
    },
    // 缴费前置
    chargeBefore () {
      if ((this.show_data.f_apply_type === '民用报建' && this.show_data.f_apply_nature === '小区') || this.show_data.f_apply_type === '非民用报建') {
        return
      }
      if (this.show_data.f_house_type === '旧报建导入'){
        return
      }
      if (Number(this.show_data.f_due_money) > Number(this.show_data.f_cumulative_payment_money) || Number(this.show_data.f_surplus_money) > 0) {
        this.$showMessage('费用未结清！！！')
        throw null
      }
    },
    // 缴费流程退回前置
    async backBefore() {
      let data = {
        tablename: 't_apply',
        condition: `f_process_id = '${this.selectdata.f_process_id}'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      if (res.data.length > 0 && res.data[0].f_surplus_money !== res.data[0].f_due_money) {
        this.$showMessage('用户已缴费，无法退回！！！')
      }
    },
    // 获取设计人员
    async getDesignerPeople () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($设计人员$).getChildren()',
        userid: this.$login.f.id
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        'rs/search',
        {data: data},
        {resolveMsg: null, rejectMsg: '设计人员查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      })
    },
    //现场勘察
    async prospectingBefore() {
        let data = {
          tablename: 't_files',
          condition: `f_blobid = '${this.selectdata.f_process_id}' and defname = '现场勘察' and fremarks = '报装手机签字文件'`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: null}
        )
        if (res.data.length <= 0) {
          this.$showMessage('现场勘察未签字，无法提交！！！')
          throw '现场勘察未签字，无法提交！'
        }
    },
    //报建受理下发，对基本信息进行校验
    checkSpaces(){
    let name=this.getLableValue('用户名称')
      //如果用户名称中包含空格，提示用户名称中不能包含空格
      if(name.indexOf(' ')>=0){
        this.$showMessage('用户名称中不能包含空格！！！')
        throw '用户名称中不能包含空格！！！'
      }
    let  Contact=  this.getLableValue('联系人')
      if(Contact.indexOf(' ')>=0){
        this.$showMessage('联系人中不能包含空格！！！')
        throw '联系人中不能包含空格！！！'
      }
    let phone= this.getLableValue('用户电话')
      if(phone.indexOf(' ')>=0){
        this.$showMessage('用户电话中不能包含空格！！！')
        throw '用户电话中不能包含空格！！！'
      }
    let ifnumber= this.getLableValue('证件号码')
      if(ifnumber.indexOf(' ')>=0){
        this.$showMessage('证件号码中不能包含空格！！！')
        throw '证件号码中不能包含空格！！！'
      }
    },
    //合同签订提交
    async contractSigningBefore() {
      let http = new HttpResetClass()
      let data = {
        tablename: 't_contract',
        condition: `f_process_id = '${this.selectdata.f_process_id}' and f_sign_state <> '签订完成'`
      }
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      if(res.data.length<=0){
        let data = {
          tablename: 't_files',
          condition: `f_blobid = '${this.selectdata.f_process_id}' and defname = '${this.selectdata.defname}' and fusetype = '纸质合同'`
        }
        let res = await http.load(
          'POST',
          `rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: null}
        )
        if (res.data.length <= 0) {
          this.$showMessage('纸质合同未上传，无法提交！')
          throw '纸质合同未上传，无法提交！'
        }
      }
      if (res.data.length > 0) {
        let data = {
          tablename: 't_files',
          condition: `f_blobid = '${this.selectdata.f_process_id}' and defname = '${this.selectdata.defname}' and fusetype = '纸质合同'`
        }
        let res = await http.load(
          'POST',
          `rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: null}
        )
        if (res.data.length <= 0) {
          this.$showMessage('合同未签订完成且纸质合同未上传，无法提交！！！')
          throw '合同未签订完成且纸质合同未上传，无法提交！！！'
        }
      }
    },
    async otherAuthentication() {
      console.log("当前数据", this.selectdata)
      this.$showMessage(`请确认是否进行重新认证，确认前请保证身份信息正确！！！`, ['confirm']).then(async (res) => {
          if (res === 'confirm') {
            let http = new HttpResetClass()
            let data = {
              apply: this.selectdata
            }
            let result = await http.load(
              'POST',
              'rs/logic/anotherLegalize',
              {data: data},
              {
                resolveMsg: '重新发起实名认证成功!',
                rejectMsg: '重新发起实名认证失败!'
              }).then((res)=>{
                if(res.data === 200){
                  this.$dispatch('loadPage')
                }
            })
          }
      })
      throw '重新发起实名认证！！！'
    },
    async otherSigned() {
      console.log("当前数据", this.selectdata)
      this.$showMessage(`请确认是否进行重新发送签署短信！！！`, ['confirm']).then(async (res) => {
          if (res === 'confirm') {
            let http = new HttpResetClass()
            let data = {
              apply: this.selectdata
            }
            let result = await http.load(
              'POST',
              'rs/logic/anotherMAS',
              {data: data},
              {
                resolveMsg: '重新发送签署短信成功!',
                rejectMsg: '重新发送签署短信失败!'
              }).then((res)=>{
                if(res.data === 200){
                  this.$dispatch('loadPage')
                }
            })
          }
      })
      throw '重新发送签署短信！！！'
    },
    // 施工前置
    async constructionBefore () {
      await this.userSignBefore()
      if (this.show_data.f_apply_nature !== '分户挂表') {
        let http = new HttpResetClass()
        let data = {
          condition: `ui.f_process_id = '${this.show_data.f_process_id}' and f_meternumber is null and f_gasbrand_id is not null `
        }
        let res = await http.load(
          'POST',
          'rs/sql/countApplyUserinfo',
          {data: data},
          {
            resolveMsg: null,
            rejectMsg: '安装明细查询失败！！！'
          })
        if (res.data[0].num > 0) {
          this.$showMessage(`还有${res.data[0].num}户未安装，无法提交`)
          throw `还有${res.data[0].num}户未安装，无法提交`
        }
      }
    },
    async userSignBefore() {
      let http = new HttpResetClass()
      let data = {
        tablename: 't_files',
        condition: `f_blobid = '${this.selectdata.f_process_id}' and defname = '${this.selectdata.defname}' and fremarks = '报装手机签字文件'`
      }
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      if (res.data.length <= 0) {
        this.$showMessage('用户未签字，无法提交！！！')
        throw '用户未签字，无法提交！'
      }
    },
    addressInitialization () {
      this.$getConfig(this, 'UserAddress')

      let f_address_type = this.show_data.f_address_type

      for (const item of this.show_data.fields) {
        if (f_address_type === '民用市区') {
          if (item.label === '区/县' || item.label === '街道/乡镇' || item.label === '集收单位' || item.label === '门牌号') {
            item.hidden = false
            item.required = true
          }
          if (item.label === '楼号/组' || item.label === '单元/排' || item.label === '楼层') {
            item.hidden = false
            item.required = false
          }
          if (item.label === '地址') {
            item.readonly = true
          }
        }
        if (f_address_type === '民用乡镇') {
          if (item.label === '区/县' || item.label === '街道/乡镇' || item.label === '集收单位' || item.label === '门牌号') {
            item.hidden = false
            item.required = true
          }
          if (item.label === '楼号/组' || item.label === '单元/排' || item.label === '楼层') {
            item.hidden = false
            item.required = false
          }
          if (item.label === '楼层') {
            item.hidden = true
            item.required = false
          }
          if (item.label === '地址') {
            item.readonly = true
          }
        }
        if (f_address_type === '特殊地址') {
          if (item.label === '区/县' || item.label === '街道/乡镇') {
            item.hidden = false
            item.required = true
          }
          if (item.label === '集收单位') {
            item.hidden = false
            item.required = false
          }
          if (item.label === '楼号/组' || item.label === '单元/排' || item.label === '楼层' || item.label === '门牌号') {
            item.hidden = true
            item.required = false
          }
          if (item.label === '地址') {
            item.readonly = false
          }
        }

        if (this.show_data.f_apply_source === '线下发起' && item.label === '预约地址') {
          item.hidden = true
        }
      }
    },
    async streetChange () {
      if (isEmpty(this.show_data.f_street)) {
        return
      }

      let data = {
        tablename: 't_area',
        condition: `f_filialeid = '${this.$login.f.orgid}' and f_street = '${this.show_data.f_street}'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '集收单位查询失败！！！'}
      )

      this.setLabelOptions('集收单位', res.data.map(item => {
        return {
          label: item.f_residential_area,
          value: item.f_residential_area
        }
      }))
    },
    async pcdChange () {
      if (isEmpty(this.show_data.f_pcd)) {
        return
      }

      let data = {
        tablename: 't_street',
        condition: `f_filialeid = '${this.$login.f.orgid}' and f_pcd = '${this.show_data.f_pcd}'`
      }
      let f_address_type = this.getLableValue('地址类型')

      if (f_address_type === '民用市区') {
        data.condition = `f_filialeid = '${this.$login.f.orgid}' and f_pcd = '${this.show_data.f_pcd}' and f_iscity = '市区'`
      }
      if (f_address_type === '民用乡镇') {
        data.condition = `f_filialeid = '${this.$login.f.orgid}' and f_pcd = '${this.show_data.f_pcd}' and f_iscity = '乡镇'`
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '街道/乡镇查询失败！！！'}
      )

      this.setLabelOptions('街道/乡镇', res.data.map(item => {
        return {
          label: item.f_street,
          value: item.f_street
        }
      }))
    },
    //查询现场负责人
    async getConstructionWorker(){
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($建设单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '现场负责人查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
    },
    //获取下发人（当前操作人所属部门下的所有人）
    getSource () {
      return  'this.getParentByType($organization$).getChildByName($'+ this.$login.f.f_department_name + '$).getChildren()'
    },
    async getUserName() {
      if(this.selectdata.f_construction_unit_id){
        let data = {
          tablename: 't_user',
          condition: `id='${this.selectdata.f_construction_unit_id}'`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: null}
        )
        return res.data.map(item => {
          return {
            label: item.name,
            value: item.id
          }
        })
      }
      return
    },
    // 安装单位签字人
    async getConstructionUnitId () {
      let data = {
        source: '',
        userid: this.$login.f.id
      }
      data.source = 'this.getParentByType($organization$).getChildByName($'+ this.$login.f.f_department_name + '$).getChildren()'
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '安装单位施工班组查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
    },
    // 安装单位负责人
    async getConstructionUnit () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($工程施工队$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '安装单位负责人查询失败！！！'}
      )
      console.log("显示返回值",res)
      let constructionUnit = res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
      constructionUnit = constructionUnit.sort((a,b) => a.value - b.value)
      console.log("显示返回值1",constructionUnit)
      return constructionUnit
    },
    // 管线施工单位
    async getGuanXianBuildUnit () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($工程施工队$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '安装单位负责人查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      })
    },
    // 建设单位
    async getConstructOperator () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($建设单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '建设单位人员查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
    },
    // 监理单位
    async getSupervisorOperator () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($监理单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '监理单位人员查询失败！！！'}
      )
      for (const item of this.selectdata.fields) {
        if (item.label === '监理单位') {
          item.value = res.data[0].id
          this.selectdata[item.field] = res.data[0].id
        }
      }
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
    },
    // 管线监理单位
    async getSupervisorName () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($监理单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '监理单位人员查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      })
    },

    // 监理现场负责人
    async getSupervisorOperatorId () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($监理班组$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '监理单位人员查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
    },
    // 土建单位
    async getEngineeringOperator () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($土建单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '土建单位人员查询失败！！！'}
      )
      let result = res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
      result.push({label:'用户自理',value:'用户自理'})
      result.push({label:'无',value:'无'})
      return result
    },
    // 管线土建单位
    async getEngineeringName () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($土建单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '土建单位人员查询失败！！！'}
      )
      let result = res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      })
      result.push({label:'用户自理',value:'用户自理'})
      result.push({label:'无',value:'无'})
      return result
    },
    // 检测单位
    async getCheckOperator () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($检测单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '检测单位人员查询失败！！！'}
      )

      let result = res.data.map(item => {
        return {
          label: item.name,
          value: item.id
        }
      })
      result.push({label:'无',value:'无'})
      return result
    },
    // 管线检测单位
    async getCheckName () {
      let data = {
        source: 'this.getParentByType($organization$).getChildByName($检测单位$).getChildren()',
        userid: this.$login.f.id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/search`,
        {data: data},
        {resolveMsg: null, rejectMsg: '检测单位人员查询失败！！！'}
      )

      let result = res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      })
      result.push({label:'无',value:'无'})
      return result
    },
    // 获取气表品牌
    async getMeterBrand () {
      let data = {
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getMeterBrand`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气表品牌查询失败！！！'}
      )

      return res.data
    },
    async stopApply () {
      console.log('终止报建！！！！！')
      if (this.show_data.defname === '报建受理') {
        this.show_data.f_stop_reason = this.show_data.f_accept_result
      }
      if (this.show_data.defname === '现场勘察') {
        this.show_data.f_stop_reason = this.show_data.f_prospecting_result
      }

      let data = {
        apply: this.show_data,
        user: this.$login.f
      }

      let res = await this.$resetpost(
        `rs/logic/stopApply`,
        {data: data},
        {resolveMsg: null, rejectMsg: '终止报建失败！！！'}
      )

      this.$dispatch('loadPage')

      throw '终止报建！！！'
    },
    // 获取小区
    async getResidentialArea () {
      let data = {
        tablename: 't_area_address',
        condition: `f_filiale like '%${"榆林."+this.$login.f.orgs}%' and f_area_status = '启用'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '小区查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.f_residential_area,
          value: item.id
        }
      })
    },
    //获取燃气公司内部签署人
    async getContractSignatory () {
      let data = {
        condition: `asj.f_type = '内部' and asj.f_subject_type = '企业' and asj.f_state = '有效' and asj.f_auth_state = '审核通过' and asg.f_state = '有效' and asg.f_sign_state = '签章成功'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getAuthSubjectList`,
        {data: data},
        {resolveMsg: null, rejectMsg: '签署人查询失败！！！'}
      )
      return res.data.map(item => {
        return {
          label: item.f_subject_name,
          value: `${item.id}`
        }
      })
    },
    async setContractSignatory () {
      let data = {
        condition: `asj.f_type = '内部' and asj.f_subject_type = '企业' and asj.f_state = '有效' and asj.f_auth_state = '审核通过' and asg.f_state = '有效' and asg.f_sign_state = '签章成功'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getAuthSubjectList`,
        {data: data},
        {resolveMsg: null, rejectMsg: '签署人查询失败！！！'}
      )
      this.setLabelOptions('签署人',res.data.map(item => {
        return {
          label: item.f_subject_name,
          value: `${item.id}`
        }
      }))
      this.setLabelValue('签署人',res.data[0].id)
    },
    // 地址拼接
    addressSplicing () {
      let f_area = this.getLableValue('区/县') ? this.getLableValue('区/县') + '-' : ''
      let f_slice_area = this.getLableValue('片区') ? this.getLableValue('片区') + '-' : ''
      let f_street = this.getLableValue('街道') || ''
      let f_address_detail = this.getLableValue('详细地址') || ''

      let f_address = f_area + f_slice_area + f_street + f_address_detail
      this.setLabelValue("地址", f_address)
    },
    // 小区地址拼接
    areaAddressSplicing () {
      let f_area = this.area.f_area || ''
      let f_slice_area = this.area.f_slice_area || ''
      let f_street = this.area.f_street || ''
      let f_residential_area = this.area.f_residential_area || ''

      let f_address = f_area + f_slice_area + f_street + f_residential_area
      this.setLabelValue("地址", f_address)
    },
    //分户挂表生成安检单
    async getChecklist() {
      let http = new HttpResetClass()
      let data = {
        f_process_id: this.selectdata.f_process_id,
        f_userinfo_id: this.selectdata.f_userinfo_id,
        user: this.$login.f.user
      }
      let res = await http.load(
        'POST',
        `rs/logic/getChecklist`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
    },
    // 生成合同编号（已作废）
    async getContractNumber() {
      const nowDate = new Date()
      let year = nowDate.getFullYear()
      let nature = ''
      if (this.show_data.f_apply_type === '民用报建') {
        nature = 'J'
      } else if (this.show_data.f_apply_type === '非民用报建') {
        nature = 'F'
      }
      let shiGong = 'S'
      let gongQi = 'G'

      let lastyYear = year - 1
      let http = new HttpResetClass()
      let data = {
        user: this.$login.f.user,
        startDate: year + '-01-01 00:00:00',
        endDate: year + '-12-31 23:59:59'
      }
      let res = await http.load(
        'POST',
        `rs/sql/getContractCount`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      let count = res.data[0].count + 1


      let shiGongContractNumber = year + nature + shiGong + '-' + count
      let gongQiContractNumber = year + nature + gongQi + '-' + count
      if (!this.getLableValue('委托合同编号')){
        this.setLabelValue('委托合同编号',shiGongContractNumber)
        this.setLabelValue('供气合同编号',gongQiContractNumber)
      }
    },
    //获取气价列表
    async getPrice (index) {
      if (isEmpty(this.show_data.f_gas_nature) || isEmpty(this.show_data.f_price_type)) {
        return
      }

      if (index) {
        this.setLabelValue('气价名称', null)
      }

      if (this.show_data.f_price_type === '混合气价') {
        this.showLabels('比率')
      } else {
        this.setLabelValue('比率', null)
        this.hideLabels('比率')
      }

      let data = {
        condition: `sp.f_filiale like '%${"榆林."+this.$login.f.orgs}%' and sp.f_price_type = '${this.show_data.f_price_type}' and f_gasproperties = '${this.show_data.f_gas_nature}'`
      }

      if (this.show_data.f_apply_type === '民用报建') {
        data.condition += `and f_user_type = '民用'`
      }
      if (this.show_data.f_apply_type === '非民用报建') {
        data.condition += `and f_user_type = '非民用'`
      }


      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applyGetPrice`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气价查询失败！！！'}
      )
      let priceLoptions = res.data.map(item => {
        return {
          label: item.f_price_name,
          value: `${item.id}`
        }
      })
      this.setLabelOptions('气价名称', priceLoptions)
    },
    // 单价失去焦点
    async priceChange () {
      if (isEmpty(this.show_data.f_price)) {
        return
      }
      let data = {
        operator: '*',
        num1: this.show_data.f_price,
        num2: this.show_data.f_install_count
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/logic/compute`,
        {data: data},
        {resolveMsg: null, rejectMsg: '工程材料费计算失败！！！'}
      )

      this.setLabelValue('工程材料费', res.data)
    },
    //工商户验证表具类型是否需选择
    async meterBrandCheck() {
      let data = {
        f_process_id: this.show_data.f_process_id,
        orgid:this.$login.f.orgid
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/meterCheck`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      if (res.data[0].num > 0){
        this.$showMessage(`还有${res.data[0].num}处未选择表具，请选择后提交！`)
        throw null
      }
    },
    // 安装户数
    async installCountCheck() {
      let data = {
        tablename: 't_userinfo',
        condition: `f_process_id = '${this.show_data.f_process_id}' and f_user_state != '销户'`,
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '用户数量查询失败'}
      )
      this.setLabelValue('安装户数',res.data.length)
    },
      // 户内出单日期
    getOutdoorsTime () {
      for (const item of this.selectdata.fields) {
        console.log('是否进入')
        if (item.label === '户内出单日期') {
          item.value = this.selectdata.f_release_date
          this.selectdata[item.field] = item.value
          console.log('当前出单时间',item.value)
        }else if(item.label === '庭院出单日期'){
          item.value = this.selectdata.f_release_date
          this.selectdata[item.field] = item.value
        }else if(item.label === '出单日期'){
          item.value = this.selectdata.f_release_date
          this.selectdata[item.field] = item.value
        }
      }
    },
    //获取缴费日期
    async getChargeDate() {
      let data = {
        tablename: 'activityins',
        condition: `processid = '${this.selectdata.f_process_id}' and defname = '报装缴费'`,
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      if (res.data[0]) {
        for (const item of this.selectdata.fields) {
          if (item.label === '缴费日期') {
            item.value = res.data[0].finishtime
            this.selectdata[item.field] = item.value
          }
        }
      }
    },
    //获取工程施工时各部门当前签字环节
    async getSingAct() {
      let data = {
        f_process_id: this.selectdata.f_process_id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getSingAct`,
        {data: data},
        {resolveMsg: null, rejectMsg: '签字状态查询失败！！！'}
      )
      if (res.data.length > 0) {
        for (const item of this.selectdata.fields) {
          if (item.label === '签字所在环节') {
            item.value = res.data[0].defname
            this.selectdata[item.field] = item.value
          }
        }
      }
    },
    //获取土建的乙方
    getYiFang() {
      return [{label: '榆林榆川天然气', value: '榆林榆川天然气'},
        {label: this.selectdata.f_user_name, value: this.selectdata.f_user_name},
        {label: '无', value: '无'}]
    },
    getGaiXianType () {
      return [{label: "隐患整改", value: "隐患整改"},
        {label: "改造工程", value: "改造工程"},
        {label: "改线工程", value: "改线工程"},
        {label: "老旧小区", value: "老旧小区"}]
    },
    async checkIsUser() {
      let data = {
        items: 'count(*) num' ,
        tablename: 't_userinfo',
        condition: `f_process_id = '${this.show_data.f_process_id}' and f_user_state <> '销户'`
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '是否存在用户！！！'}
      )
      if (res.data[0].num <= 0){
        this.$showMessage(`未添加设备，请添加后提交！`)
        throw null
      }
    },
    async repair() {
      let data = {
        f_process_id: this.show_data.f_process_id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/logic/updateRepair`,
        {data: data},
        {resolveMsg: null, rejectMsg: '维修工单状态修改！！！'}
      )
      this.$dispatch('loadPage')
    },
    changeDispatch(value){
      if (value === '维修安检中心'){
        this.hideLabels('现场项目负责人', '安装单位', '安装单位现场负责人', '建设单位', '监理单位', '土建单位', '检测单位', '户内出单日期', '户内回单日期'
          , '户内施工备注', '庭院出单日期', '庭院回单日期', '庭院施工备注', '是否发起签字', '签字是否完成', '签字所在环节')
        this.hideButtons('签字')
        this.electiveLabels('现场项目负责人', '安装单位', '建设单位', '监理单位', '土建单位', '检测单位', '户内出单日期', '户内回单日期'
          , '户内施工备注', '庭院出单日期', '庭院回单日期', '庭院施工备注', '是否发起签字', '签字是否完成', '签字所在环节')
      }
      if (value === '施工工队'){
        this.showLabels('现场项目负责人', '安装单位', '安装单位现场负责人','建设单位', '监理单位', '土建单位', '检测单位', '户内出单日期', '户内回单日期'
          , '户内施工备注', '庭院出单日期', '庭院回单日期', '庭院施工备注', '是否发起签字', '签字是否完成', '签字所在环节')
        this.requiredLabels('现场项目负责人', '安装单位', '安装单位现场负责人','建设单位', '监理单位', '土建单位', '检测单位', '现场项目负责人', '是否发起签字', '签字是否完成', '签字所在环节')
      }
    },
    //拆除流程核对气量提交
    async gasCheckBefore() {
      let http = new HttpResetClass()
      let data = {
        tablename: 't_files',
        condition: `f_blobid = '${this.selectdata.f_process_id}' and defname = '${this.selectdata.defname}' and fusetype = '气量核对单'`
      }
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: null}
      )
      if (res.data.length <= 0) {
        this.$showMessage('气量核对单未上传，无法提交！！！')
        throw '气量核对单未上传，无法提交！'
      }
    },
  },
  events: {
    // 强制开关阀
    async 'onOffValve' () {
      let data = {
        condition: `ui.f_userinfo_id = '${this.show_data.f_userinfo_id}'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getApplyUserinfo`,
        {data: data},
        {resolveMsg: null, rejectMsg: '档案获取失败！！！'}
      )

      let userinfo = res.data[0]

      if (this.show_data.button.button_name !== '退出强制状态') {
        data = {
          condition: `t_userfiles.f_meternumber = '${userinfo.f_meternumber}'`,
          contentData: {
            isOpen: this.show_data.button.button_name === '强制开阀' ? 1 : 0
          },
          inputtor: this.$login.f.name,
          instructTitle: this.show_data.button.button_name === '强制开阀' ? '开阀' : '关阀',
          instructType: '阀门控制',
          meterBrandName: userinfo.f_alias
        }
        res = await http.load(
          'POST',
          `rs/logic/saveInstruct`,
          {data: data},
          {resolveMsg: null, rejectMsg: `${this.show_data.button.button_name}失败！！！`}
        )
      }

      data = {
        f_user_id: userinfo.f_user_id,
        f_userinfo_id: userinfo.f_userinfo_id,
        record: {
          f_filiale: "榆林."+this.$login.f.orgs,
          f_instruct_meta_data: this.show_data.button.button_name === '退出强制状态' ? '退出强制阀控' : '进入强制阀控',
          f_instruct_title: this.show_data.button.button_name === '退出强制状态' ? '退出强制阀控' : '进入强制阀控',
          f_instruct_type: '阀门控制',
          f_meternumber: userinfo.f_meternumber,
          f_operator: this.$login.f.name,
          f_outlets: userinfo.f_outlets,
          f_reason: this.show_data.button.f_reason,
          f_user_id: userinfo.f_user_id,
          f_userinfo_id: userinfo.f_userinfo_id
        },
        state: this.show_data.button.button_name === '退出强制状态' ? 0 : 1
      }

      res = await http.load(
        'POST',
        `rs/logic/updateNetWorkValve`,
        {data: data},
        {resolveMsg: '执行成功！！！', rejectMsg: `执行失败！！！`}
      )

    },
    // 修改用户档案
    async 'updateUserinfoState' () {
      let data = {
        f_userinfo_id: this.show_data.f_userinfo_id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/logic/updateUserinfoState`,
        {data: data},
        {resolveMsg: '该用户档案已为正常档案，可进行开关阀操作！！！', rejectMsg: '档案状态修改失败！！！'}
      )

      this.showButtons('强制开阀','强制关阀')
      this.hideButtons('转正式档案')
    },
    // 选择用户
    async 'selectUserinfo' (row) {
      this.setLabelValue('用户编号', row.f_userinfo_id)
      this.setLabelValue('用户名称', row.f_user_name)
      this.setLabelValue('用户电话', row.f_user_phone)
      this.setLabelValue('证件类型', row.f_credentials)
      this.setLabelValue('证件号码', row.f_idnumber)
      this.setLabelValue('地址', row.f_address)
      this.setLabelValue('定位地址', row.f_location_address)
      this.setLabelValue('购货单位识别号', row.f_taxpayer_id)
      this.setLabelValue('购货单位名称', row.f_paper_name)
      this.setLabelValue('购货单位开户行及银行账号', row.f_paper_account)
      this.setLabelValue('购货单位地址电话', row.f_address_phone)
      this.setLabelValue('联系人', row.f_petitionuser)
      this.setLabelValue('区/县', row.f_area)
      this.setLabelValue('片区', row.f_slice_area)
      this.setLabelValue('街道', row.f_street)
      if (row.f_address_detail){
        this.setLabelValue('详细地址', row.f_address_detail)
      }
      if (this.show_data.f_apply_type === '改线业务'){
        this.setLabelValue('工程名称', row.f_user_name)
        this.setLabelValue('联系电话', row.f_user_phone)
      }
      this.show_data.f_address_detail = row.f_address_detail
      this.show_data.f_residential_area = row.f_residential_area
      this.show_data.unit = row.unit
      this.show_data.f_building = row.f_building
      this.show_data.f_floor = row.f_floor
      this.show_data.f_taxpayer_id = row.f_taxpayer_id   //购货单位识别号
      this.show_data.f_address_phone = row.f_address_phone //购货单位地址电话
      this.show_data.f_paper_name = row.f_paper_name //购货单位名称
      this.show_data.f_paper_account = row.f_paper_account
      this.show_data.f_userinfo_id = row.f_userinfo_id
      console.log("当前数据",this.show_data)
      if (this.show_data.f_apply_type === '设备拆除'){
        let data = {
          userinfo: row,
          apply: this.show_data,
          loginUser: this.$login.f
        }
        let res = await this.$resetpost(
          `rs/logic/addChaiChuUser`,
          {data: data},
          {resolveMsg: '添加拆除用户成功！！！', rejectMsg: '添加拆除用户失败！！！'}
        )
        this.$dispatch('breakControl', this.show_data)
      }
    },
    async 'priceReadEvent' (index) {
      await this.setContractSignatory()
      // await this.getContractNumber()
      await this.getPrice(index)
      await this.priceChange()
    },
    async 'getPrice' (index) {
      if (isEmpty(this.show_data.f_gas_nature) || isEmpty(this.show_data.f_price_type)) {
        return
      }

      if (index) {
        this.setLabelValue('气价名称', null)
      }

      if (this.show_data.f_price_type === '混合气价') {
        this.showLabels('比率')
      } else {
        this.setLabelValue('比率', null)
        this.hideLabels('比率')
      }

      let data = {
        condition: `sp.f_filiale  like '%${"榆林."+this.$login.f.orgs}%' and sp.f_price_type = '${this.show_data.f_price_type}' and f_gasproperties = '${this.show_data.f_gas_nature}'`
      }

      if (this.show_data.f_apply_type === '民用报建') {
        data.condition += `and f_user_type = '民用'`
      }
      if (this.show_data.f_apply_type === '非民用报建') {
        data.condition += `and f_user_type = '非民用'`
      }


      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applyGetPrice`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气价查询失败！！！'}
      )

      let priceLoptions = res.data.map(item => {
        return {
          label: item.f_price_name,
          value: `${item.id}`
        }
      })
      this.setLabelOptions('气价名称',priceLoptions)
    },
    // 街道失去焦点
    async changStreet () {
      if (isEmpty(this.show_data.f_street)) {
        return
      }
      this.addressSplicing()
    },

    'changAddressDetail'(){
      if (isEmpty(this.show_data.f_address_detail)) {
        return
      }
      this.addressSplicing()
    },
    async 'changAddress'(){
      if (isEmpty(this.show_data.f_address_detail)) {
        return
      }
      if (this.show_data.f_residential_area_id) {
        let data = {
          tablename: 't_area_address',
          condition: `id = '${this.show_data.f_residential_area_id}'`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: '小区查询失败！！！'}
        )

        this.area = res.data[0]
      }
      this.areaAddressSplicing()
      let f_address = this.show_data.f_address + this.show_data.f_address_detail
      this.setLabelValue("地址", f_address)
    },
    // 片区失去焦点
    async 'changSliceArea' () {
      if (isEmpty(this.show_data.f_area) || isEmpty(this.show_data.f_slice_area)) {
        return
      }

      let data = {
        items: 'f_street label,f_street value',
        tablename: 't_area_address',
        condition: `f_area = '${this.show_data.f_area}' and f_slice_area = '${this.show_data.f_slice_area}'`,
        groupitem: 'f_street'
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '签字状态查询失败！！！'}
      )
      this.setLabelOptions('街道', res.data)

      this.addressSplicing()
    },
    // 区县失去焦点
    'changeArea' () {
      if (isEmpty(this.show_data.f_area)) {
        return
      }
      this.setLabelValue('片区', null)
      this.setLabelValue('街道', null)
      this.setLabelOptions('片区', this.$appdata.getParam(`${this.show_data.f_area}片区`))
      this.setLabelOptions('街道', [])

      this.addressSplicing()
    },
    // 开启签字
    async 'startSignActivity' () {
      this.hideButtons('签字')
      if(this.show_data.f_apply_type !== '管线建设'){
        await this.constructionBefore()
      }
      let data = {
        apply: this.show_data,
        user: this.$login.f
      }

      let res = await this.$resetpost(
        `rs/logic/startSignActivity`,
        {data: data},
        {resolveMsg: '签字流程已发起！！！', rejectMsg: '签字发起失败！！！'}
      )

      this.$dispatch('breakControl', this.show_data)
    },
    // 工程施工初始化
    async 'buildReadyEvent' () {
      // this.changeDispatch(this.getLableValue('派工类型'))
      if(this.getLableValue('是否发起签字') === '是') {
        this.hideButtons('签字')
      }
      let http = new HttpResetClass()
      if (isEmpty(this.show_data.f_meter_brand)) {
        return
      }else {
        if (this.show_data.f_meter_brand === 'null') {
          this.setLabelOptions('气表型号', [{label: '无', value: 'null'}])
          return
        }
        let data = {
          f_gasbrand_id: this.show_data.f_meter_brand
        }
        let res = await http.load(
          'POST',
          `rs/sql/getGasModel`,
          {data: data},
          {resolveMsg: null, rejectMsg: '气表型号查询失败！！！'}
        )
        this.setLabelOptions('气表型号', res.data)
      }

      if (this.show_data.f_apply_type === '分户挂表') {
        let data = {
          condition: `ui.f_userinfo_id = '${this.show_data.f_userinfo_id}'`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `rs/sql/getApplyUserinfo`,
          {data: data},
          {resolveMsg: null, rejectMsg: '档案状态获取失败！！！'}
        )
        console.log("f_meter_classif11y",res.data[0].f_meter_classify)
        if (!res.data[0].f_meter_brand.includes('物联网表')) {
          return
        }
        console.log("f_user_state11",res.data[0].f_user_state)
        if (res.data[0].f_user_state === '正常') {
          this.showButtons('退出强制状态','强制关阀')
          this.hideButtons('转正式档案')
        } else {
          this.showButtons('转正式档案')
          this.hideButtons('退出强制状态','强制关阀')
        }
      }
    },
    // 工程派工初始化
    async 'dispatchReadyEvent' () {
      if (isEmpty(this.show_data.f_meter_brand)) {
        return
      }
      let data = {
        f_gasbrand_id: this.show_data.f_meter_brand
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getGasModel`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气表型号查询失败！！！'}
      )

      this.setLabelOptions('气表型号', res.data)
    },
    // 气表品牌失去焦点
    async 'meterBrandChenge' (index) {
      if (isEmpty(this.show_data.f_meter_brand)) {
        return
      }
      this.setLabelValue('气表型号', null)
      let data = {
        f_gasbrand_id: this.show_data.f_meter_brand
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/getGasModel`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气表型号查询失败！！！'}
      )

      this.setLabelOptions('气表型号', res.data)
    },
    // 单价失去焦点
    async 'priceChange' (index) {
      if (isEmpty(this.show_data.f_price)) {
        return
      }
      let data = {
        operator: '*',
        num1: this.show_data.f_price,
        num2: this.show_data.f_install_count
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/logic/compute`,
        {data: data},
        {resolveMsg: null, rejectMsg: '工程材料费计算失败！！！'}
      )

      this.setLabelValue('工程材料费', res.data)
    },
    // 安装户数失去焦点
    'installCountChange' (index) {
      if (isEmpty(this.show_data.f_install_count)) {
        return
      }
      if (Number(this.show_data.f_install_count) > Number(this.show_data.f_apply_count)) {
        this.$showMessage('安装数已超过申请数！！！')
        // this.setLabelValue('安装户数', null)
        // this.setLabelValue('安装点数', null)
        // return
      }

      if (Number(this.show_data.f_install_count) <= 0) {
        this.$showMessage('至少有一个用户！！！')
        this.setLabelValue('安装户数', null)
        this.setLabelValue('安装点数', null)
        return
      }
    },
    // 土建单位失去焦点
    'judgmentEngineering' (index) {
      if (this.show_data.f_engineering_operator_id === '无' && this.show_data.f_civil_engineering !== "无") {
        this.$showMessage('土建工程派单与实际选择不符，请仔细核对后再次提交')
        throw null
      }
    },
    // 报建性质失去焦点
    'applyNatureChange' (index) {
      if (this.show_data.f_apply_nature === '散户') {
        //绑定票据类型为电子票
        this.setLabelValue('票据类型', '电子票')
        this.hideLabels('营业执照')
        this.electiveLabels('营业执照', '购货单位识别号', '购货单位银行账号', '购货单位地址电话')
      }
      if (this.show_data.f_apply_nature === '小区') {
        //票据类型为专票
        this.setLabelValue('票据类型', '专票')
        this.showLabels('营业执照', '小区/巷道')
        this.requiredLabels('小区/巷道')
      }
    },
    // 票据类型失去焦点
    'applyPaperChange' (index) {
      console.log("测试是否进入")
      if (this.show_data.f_paper_type === '专票') {
        this.requiredLabels('购货单位名称','购货单位识别号', '购货单位银行账号', '购货单位地址电话')
      }else {
        this.electiveLabels( '购货单位识别号', '购货单位银行账号', '购货单位地址电话')
      }
    },
    'chargeAfter'(index){
      if (this.show_data.f_surplus_money !== this.show_data.f_due_money){
        this.hideButtons('退回')
      }else {
        this.showButtons('退回')
      }
    },
    //购货单位识别号失去焦点
    'getAuthenticationMethod' (index){
      if (isEmpty(this.show_data.f_taxpayer_id)) {
        this.setLabelValue('认证类型','个人认证')
      }else {
        this.setLabelValue('认证类型','企业认证')
      }
    },
    //搜索小区
    'selectArea' (val,index) {
      let pcdText = `and f_residential_area like '%${val}%'`
      let data = {
        tablename: 't_area_address',
        condition: `f_filiale like '%${"榆林."+this.$login.f.orgs}%'  and f_area_status = '启用' ${pcdText}`
      }
      new HttpResetClass().load("POST", `rs/sql/applySingleTable`, {data:data}, {resolveMsg: null, rejectMsg: null}).then((res)=>{
        console.log('请求发送完成！！！！！'+JSON.stringify(res))
        if(res.data.length>0){
          this.setLabelOptions('小区/巷道', res.data.map(item => {
            return {
              label: item.f_residential_area,
              value: item.id
            }
          }))
        }
      })
    },
    //身份证号码校验
    'checkIdnumber' (index) {
      if(this.show_data.f_credentials === '身份证'){
        var verify = /^[1-9]\d{5}(18|19|20|21)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
        if (!verify.test(this.show_data.fields[index].value)){
          this.show_data.fields[index].value = null
          this.$showMessage('身份证号码格式错误请重新输入！！！')
        }
      }
    },
    //电话号码校验
    'checkPhone' (index) {
      var verify = /^([1][0-9]{10})$/
      if (!verify.test(this.show_data.fields[index].value)){
        this.show_data.fields[index].value = null
        this.$showMessage('电话号码格式错误请重新输入！！！')
      }
    },
    'changeDispatching'(index){
      if (this.show_data.fields[index].value === '安检维修中心'){
        this.hideLabels('现场项目负责人', '安装单位', '安装单位现场负责人','建设单位', '监理单位', '土建单位', '检测单位')
        this.electiveLabels('现场项目负责人', '安装单位', '安装单位现场负责人','建设单位', '监理单位', '土建单位', '检测单位')
      }else if (this.show_data.fields[index].value === '施工工队'){
        this.showLabels('现场项目负责人', '安装单位', '安装单位现场负责人','建设单位', '监理单位', '土建单位', '检测单位')
        this.requiredLabels('现场项目负责人', '安装单位', '安装单位现场负责人','建设单位', '监理单位', '土建单位', '检测单位')
      }
    },
    'getRefund'(index){
      if (this.show_data.fields[index].value === '否'){
        this.hideLabels('退费金额', '退款项')
        this.electiveLabels('退费金额', '退款项')
      }else if (this.show_data.fields[index].value === '是'){
        this.showLabels('退费金额', '退款项')
        this.requiredLabels('退费金额', '退款项')
      }
    },
    'hasTrouble'(index) {
      if (this.show_data.fields[index].value === '有纠纷'){
        this.hideButtons('提交', '签字', '图纸变更')
        this.showLabels('纠纷原因')
      }else {
        this.showButtons('提交', '签字', '图纸变更')
        this.hideLabels('纠纷原因')
      }
    },
    //金额大小写转换
    'applyCapitalizedAmount' (index){
      // 通过正则过滤小数点后两位
      let money = (this.show_data.fields[index].value.match(/^\d*(\.?\d{0,2})/g)[0]) || null
      this.setLabelValue('应交金额大写',this.smalltoBIG(money))
    },

    // ===========================================
    'initializtionView' () {
      if (this.show_data.f_apply_nature === '散户') {
        this.hideLabels('营业执照')
        this.electiveLabels('营业执照', '购货单位识别号', '购货单位银行账号', '购货单位地址电话')
      }
      if (this.show_data.f_apply_nature === '小区') {
        this.showLabels('营业执照', '小区/巷道', '小区名称')
        this.requiredLabels('小区/巷道')
        // this.hideComponents('用户花名单')
      }
    },
    // 检查重复
    'checkRepeat' (index) {
      this.checkDuplicate(index)
    },
    async 'button'() {
      if (this.show_data.button.before) {
        await this[this.show_data.button.before]()
      }
      // 点击重置按钮就重置数据
      if (this.show_data.button.button_name === '重置') {
        this.$dispatch('breakControl', this.selectdata)
        return
      }
      this.show_data.start_activity = this.$workflow_vue.start_activity
      this.show_data.xmlfilename = this.$workflow_vue.workflow_xmlfilename
      let data = {
        apply: this.show_data,
        user: this.$login.f
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/logic/ApplyProductService`,
        {data: data},
        {resolveMsg: null, rejectMsg: '数据保存失败'}
      )
      if (this.show_data.button.after) {
        this[this.show_data.button.after]()
      }
      this.$dispatch('loadPage')
    },
    // 失去焦点出触发事件
    'onchange' (index) {
    },
    selectSearch (val, index) {},
    'onblur' (index) {},
    'oninput' (index) {},
    async 'onchangeModal' (index, fieldIndex) {
    },
    async 'onblurModal' (index, fieldIndex) {

    },
    async 'oninputModal' (index, fieldIndex) {

    },
    async 'onetomanydelete' (index, rowIndex) {

      let http = new HttpResetClass()

      let res = await http.load(
        'DELETE',
        `rs/entity/${this.show_data.onetomany[index].tables[0]}/${this.show_data.onetomany[index].rows[rowIndex].id}`,
        null,
        {resolveMsg: null, rejectMsg: '删除失败！！！'}
      )

      res = await this.$resetpost(
        'rs/entity/t_apply',
        this.show_data
      )

      this.$dispatch('breakControl', this.show_data)
    },
    async 'onetomanyupdate' (index, rowIndex) {
      let data = this.show_data.onetomany[index].rows[rowIndex]

      this.show_data.onetomany[index].fields.forEach(item => {
        data[item.field] = item.value
      })
      let res = await this.$resetpost(
        `rs/entity/${this.show_data.onetomany[index].tables[0]}`,
        data
      )

      res = await this.$resetpost(
        'rs/entity/t_apply',
        this.show_data
      )

      this.$dispatch('breakControl', this.show_data)
    },
    async 'onetomanyadd' (index) {
      let data = {
        f_process_id : this.show_data.f_process_id,
        f_operator_id: this.$login.f.id,
        f_operator: this.$login.f.name,
        f_operation_date: new Date().Format('yyyy-MM-dd HH:mm:ss'),
        f_orgid: this.$login.f.orgid,
        f_orgname: "榆林."+this.$login.f.orgs
      }
      this.show_data.onetomany[index].fields.forEach(item => {
        data[item.field] = item.value
      })
      let res = await this.$resetpost(
        `rs/entity/${this.show_data.onetomany[index].tables[0]}`,
        data
      )

      res = await this.$resetpost(
        'rs/entity/t_apply',
        this.show_data
      )

      this.$dispatch('breakControl', this.show_data)
    },
    'complyInstallation' (index) {
      if (this.show_data.defname === '报建受理'){
        if (this.show_data.f_accept_install === '否') {
          console.log("测试")
          this.hideButtons('下发','提交')
          this.showButtons('终止')
        } else {
          this.hideButtons('终止')
          this.showButtons('下发','提交')
        }
      }
      if (this.show_data.defname === '现场勘察'){
        if (this.show_data.f_survey_opinion === '否') {
          console.log("测试")
          this.hideButtons('下发','提交')
          this.showButtons('终止')
        } else {
          this.hideButtons('终止')
          this.showButtons('下发','提交')
        }
      }
      if (this.show_data.defname === '报建受理' || this.show_data.defname === '现场勘察'){
        this.installCountCheck()
      }
    },
    async 'saveData'(index) {
      if (this.show_data.f_residential_area_id) {
        let data = {
          tablename: 't_area_address',
          condition: `id = '${this.show_data.f_residential_area_id}'`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: '小区查询失败！！！'}
        )

        this.area = res.data[0]
      }
      this.areaAddressSplicing()
    },
    async 'importEvent' (index, table, configName, filepath) {
      let data = {
        selectdata: this.show_data,
        table: table,
        filepath: filepath,
        configName: configName,
        user: this.$login.f
      }

      let res = await this.$resetpost(
        `rs/logic/importEvent`,
        data
      )

      this.$dispatch('breakControl', this.show_data)
    },
    'onbutchange' (index) {

    },
    'onbutblur' (index) {

    },
    'onbutinput' (index) {

    }
  },
  watch: {
  }
}
</script>
<style scoped>
/*清除model中的浮动*/
.clearfix:after,.clearfix:before{
  display: table;
}
.clearfix:after{
  clear: both;
}
</style>
