<template>
  <div class="col-sm-12">
    <!-- 已办业务 -->
    <criteria-paged :model="model" v-ref:cp>
      <criteria partial='criteria' @condition-changed='$parent.searchCondition' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>工程编号：</strong></label>
              <input type="text" style="width:60%" class="input_search" placeholder='工程编号' v-model="model.f_apply_num"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="f_apply_num like '%{}%'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>客户名称：</strong></label>
              <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                     v-on:keyup.enter="$parent.$parent.search()" condition="f_user_name like '%{}%'" placeholder='客户名称'>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>联系电话：</strong></label>
              <input type="text" style="width:60%" class="input_search" placeholder='联系电话' v-model="model.f_phone"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="f_phone like '%{}%'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>联&ensp;系&ensp;人：</strong></label>
              <input type="text" style="width:60%" class="input_search" v-model="model.f_contact"
                     v-on:keyup.enter="$parent.$parent.search()" condition="f_contact like '%{}%'" placeholder='联系人'>
            </div>
            <div class="form-group col-sm-2 button-range">
              <button class="button_search button_spacing" @click="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_search button_spacing" @click="$parent.$parent.loadPage()">返回</button>
              <button class="button_clear button_spacing"  @click="$parent.$parent.clear()">清空</button>
              <bj-export-excel :data="$parent.$parent.getCondition"
                            :field="$parent.$parent.getfield"
                            :civil="$parent.$parent.civil"
                            :uncivil="$parent.$parent.uncivil"
                            sqlurl="rs/logic/applyExportfile"
                            sql-name="supervisoryExcel"
                            template-name='报建记录信息导出'
                            :choose-col="true"></bj-export-excel>
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.criteriaShow = !$parent.$parent.criteriaShow"
                class="button_spacing"
                style="float: right">
              </div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>设计人员：</strong></label>
              <v-select class="select select_list"
                        placeholder='设计人员'
                        v-model="model.f_designer_people"
                        :value.sync="model.f_designer_people"
                        :options='$parent.$parent.designerPeoples'
                        :value-single="true"
                        close-on-select
                        condition="f_designer_people = '{}'">
              </v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>合同编号：</strong></label>
              <input type="text" style="width:60%" class="input_search" placeholder='合同编号' v-model="model.f_contract_number"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="f_contract_number like '%{}%'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>报建类型：</strong></label>
              <v-select
                v-model="model.f_apply_type"
                placeholder='报建类型'
                condition="u.f_apply_type in {}"
                :value.sync="model.f_apply_type"
                :options='$parent.$parent.applytype'
                class="select select_list"
                multiple
                @change="$parent.$parent.applyTypeChange()"></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>办理环节：</strong></label>
              <v-select
                v-model="model.defname"
                placeholder='办理环节'
                condition="act.defname = '{}'"
                :value.sync="model.defname"
                :options='$parent.$parent.defnames'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>报建性质：</strong></label>
              <v-select
                v-model="model.f_apply_nature"
                placeholder='报建性质'
                condition="f_apply_nature = '{}'"
                :value.sync="model.f_apply_nature"
                :options='$parent.$parent.applyNatures'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>用户分类：</strong></label>
              <v-select
                v-model="model.f_user_classification"
                placeholder='用户分类'
                condition="f_user_classification = '{}'"
                :value.sync="model.f_user_classification"
                :options='$parent.$parent.UserList'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>用户类型：</strong></label>
              <v-select
                v-model="model.f_user_type"
                placeholder='普通/煤改'
                condition="f_user_type = '{}'"
                :value.sync="model.f_user_type"
                :options='$parent.$parent.UserType'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>用户地址：</strong></label>
              <input type="text" style="width:60%" class="input_search" placeholder='用户地址' v-model="model.f_address"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="f_address like '%{}%'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>图纸情况：</strong></label>
              <v-select
                v-model="model.f_filetype"
                placeholder='图纸情况'
                condition="f_filetype {}"
                :value.sync="model.f_filetype"
                :options='$parent.$parent.filetype'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label  for="startDate" class="font_normal_body"><strong>开始时间：</strong></label>
              <datepicker id="startDate" placeholder="报建开始日期"
                          style="width: 60%!important;"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="true"
                          condition="f_apply_date >= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label for="endDate" class="font_normal_body"><strong>截止时间：</strong></label>
              <datepicker id="endDate" placeholder="报建截止日期"
                          style="width: 60%!important;"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :format="'yyyy-MM-dd 23:59:59'"
                          :show-reset-button="true"
                          condition="f_apply_date <= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label  for="startDate" class="font_normal_body"><strong>派工时间：</strong></label>
              <datepicker id="startDate1" placeholder="派工开始日期"
                          style="width: 60%!important;"
                          v-model="model.startDate1"
                          :value.sync="model.startDate1"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="true"
                          condition="u.f_release_date >= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label for="endDate" class="font_normal_body"><strong>派工时间：</strong></label>
              <datepicker id="endDate1" placeholder="派工截止日期"
                          style="width: 60%!important;"
                          v-model="model.endDate1"
                          :value.sync="model.endDate1"
                          :format="'yyyy-MM-dd 23:59:59'"
                          :show-reset-button="true"
                          condition="u.f_release_date <= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label  for="startDate" class="font_normal_body"><strong>回单日期：</strong></label>
              <datepicker id="startDate1" placeholder="回单开始日期"
                          style="width: 60%!important;"
                          v-model="model.startDate2"
                          :value.sync="model.startDate2"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="true"
                          condition="u.f_outdoors_receipt_time >= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label for="endDate" class="font_normal_body"><strong>回单日期：</strong></label>
              <datepicker id="endDate1" placeholder="回单截止日期"
                          style="width: 60%!important;"
                          v-model="model.endDate2"
                          :value.sync="model.endDate2"
                          :format="'yyyy-MM-dd 23:59:59'"
                          :show-reset-button="true"
                          condition="u.f_outdoors_receipt_time <= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>派工类型：</strong></label>
              <v-select
                v-model="model.f_dispatching_type"
                placeholder='工队/维修'
                condition="u.f_dispatching_type = '{}'"
                :value.sync="model.f_dispatching_type"
                :options='$parent.$parent.dispatching'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>新旧报建：</strong></label>
              <v-select
                v-model="model.f_house_type"
                placeholder='新旧报建'
                condition="u.f_house_type {}"
                :value.sync="model.f_house_type"
                :options='$parent.$parent.houseType'
                class="select select_list"
                :value-single="true"
                close-on-select >
              </v-select>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body"><strong>来&emsp;&emsp;源：</strong></label>
              <v-select
                v-model="model.f_apply_source"
                placeholder='来源'
                condition="u.f_apply_source = '{}'"
                :value.sync="model.f_apply_source"
                :options='$parent.$parent.sources'
                class="select select_list"
                :value-single="true"
                close-on-select >
              </v-select>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid v-if="$parent.showData" :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <template partial='head'>
          <tr>
            <th style="white-space: nowrap;">序号</th>
            <th style="white-space: nowrap;">工程编号</th>
            <th style="white-space: nowrap;">客户名称</th>
            <th style="white-space: nowrap;">联系人</th>
            <th style="white-space: nowrap;">安装户数</th>
            <th style="white-space: nowrap;">合同编号</th>
            <th style="white-space: nowrap;">电话</th>
            <th style="white-space: nowrap;">设计人员</th>
            <th style="white-space: nowrap;">报建类型</th>
            <th style="white-space: nowrap;">报建性质</th>
            <th style="white-space: nowrap;">用户类型</th>
            <th style="white-space: nowrap;">办理环节</th>
            <th style="white-space: nowrap;">用户分类</th>
            <th style="white-space: nowrap;">地址</th>
            <th style="white-space: nowrap;">来源</th>
            <th style="white-space: nowrap;">流程状态</th>
            <th style="white-space: nowrap;">报建日期</th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{$index+1}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_apply_num}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_user_name}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_contact}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_install_count}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_contract_number}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_phone}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr><font>{{row.f_designer_people}}</font></nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_apply_type}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_apply_nature}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_user_type}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.defname}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_user_classification}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_address}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_apply_source}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_sub_state}}</nobr>
            </td>
            <td @dblclick="$parent.$parent.$parent.check(row)" style="text-align: center;">
              <nobr>{{row.f_apply_date}}</nobr>
            </td>
          </tr>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
import {HttpResetClass, PagedList} from 'vue-client'
  import {isEmpty} from '../../Util'
  export default {
    title: '勘探详情',
    props: ['showData'],
    data () {
      return {
        model: new PagedList('rs/sql/yiBanSupervisory', 20, {
          data: {
            f_filiale: "榆林."+this.$login.f.orgs
          },
        }),
        applytype: [{label: '全部', value: ''}, ...this.$appdata.getParam('报建类型')?this.$appdata.getParam('报建类型'):[]],
        defnames: isEmpty(this.$appdata.getParam('办理环节')) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam('办理环节')], // 流程节点
        applyNatures: [{label: '全部', value: ''},{label: '工业', value: '工业'},{label: '商业', value: '商业'},{label: '散户', value: '散户'},{label: '小区', value: '小区'},{label: '分户挂表', value: '分户挂表'}], // 报建性质
        criteriaShow: false,
        sources:[{label: '微信公众号', value: '微信公众号'},{label: '线下发起', value: '线下发起'}],
        filetype:[{label: '已上传图纸', value: 'is not null'}, {label: '未上传图纸', value: 'is null'}],
        UserList:[{label: '全部', value: ''}, ...this.$appdata.getParam('用户分类')?this.$appdata.getParam('用户分类'):[]],
        UserType:[{label: '全部', value: ''}, {label: '普通用户', value: '普通用户'}, {label: '煤改用户', value: '煤改用户'}],
        designerPeoples:  this.getDesigner(),
        dispatching:  [{label: '全部', value: ''}, {label: '施工工队', value: '施工工队'}, {label: '安检维修中心', value: '安检维修中心'}],
        houseType:[{label: '全部', value: ''}, {label: '旧报建', value: ` = '旧报导入'`}, {label: '新报建', value: ' is null' }],
        getfield: {
          'f_apply_num': ' 工 程 编 号 ',
          'f_charge_date': ' 收 费 日 期 ',
          'f_user_name': '  用 户 单 位  ',
          'f_user_classification': ' 用户分类 ',
          'f_user_type': '   用户类型   ',
          'f_address': '     地     址     ',
          'f_install_count': ' 安装户数 ',
          'huoyan': ' 火眼 ',
          'xiaohuoyan': ' 小火眼 ',
          'bigualu': ' 壁挂炉 ',
          'jiayongzao': ' 家用灶 ',
          'reshuiqi': ' 热水器 ',
          'cainuanlu': ' 采暖炉 ',
          'chashuilu': ' 茶水炉 ',
          'zhengche': ' 蒸车 ',
          'zhengqifashengqi': ' 蒸汽发生器 ',
          'zaoju': ' 灶具 ',
          'yasuoji': ' 压缩机 ',
          'mokuailu': ' 模块炉 ',
          'danweikw': ' 锅炉单位(KW) ',
          'danweimw': ' 锅炉单位(MW) ',
          'dunwei': ' 锅炉吨位(T) ',
          'baojingqi': ' 报警器 ',
          "zibifa": ' 安全自闭阀 ',
          'f_meter_types': '   表 具 明 细   ',
          'f_construct_operator': ' 现 场 项 目 负 责 人 ',
          'f_contact': ' 联 系 人 ',
          'f_phone': '   电   话   ',
          'f_outdoors_time': ' 户内出单日期 ',
          'f_outdoors_receipt_time': ' 户内回单日期 ',
          'f_courtyard_time': ' 庭院出单日期 ',
          'f_courtyard_receipt_time': ' 庭院回单日期 ',
          'f_construction_unit':'   施  工  单  位   ',
          'f_contract_number': ' 合 同 编 号 ',
          'f_apply_nature': ' 报 建 性 质 ',
          'defname': ' 办 理 环 节 ',
          'f_designer_people':' 设计人员 ',
          'f_apply_source': ' 来源 ',
          'f_apply_type': ' 报 建 类 型 ',
          'f_sub_state': ' 流 程 状 态 ',
          'f_apply_date': ' 报 建 日 期 ',
          'f_house_type': ' 新 旧 报 建 ',
        },
        civil: {
          'f_apply_num': '工程编号',
          'f_charge_date': '收费日期',
          'f_user_name': '用户单位',
          'f_user_type': '   用户类型   ',
          'f_address': '地址',
          'f_install_count': '安装户数',
          'baojingqi': ' 报警器 ',
          "zibifa": ' 安全自闭阀 ',
          'f_meter_types': '表具明细',
          'f_construct_operator': '现场项目负责人',
          'f_contact': '联系人',
          'f_phone': '电话',
          'f_construction_unit':'施工单位',
          'f_house_type': ' 新 旧 报 建 '
        },
        uncivil: {
          'f_apply_num': '工程编号',
          'f_charge_date': '收费日期',
          'f_user_name': '用户单位',
          'f_user_type': '   用户类型   ',
          'f_address': '地址',
          'f_install_count': '安装户数',
          'huoyan': '火眼',
          'xiaohuoyan': '小火眼',
          'bigualu': '壁挂炉',
          'jiayongzao': '家用灶',
          'reshuiqi': '热水器',
          'cainuanlu': '采暖炉',
          'chashuilu': '茶水炉',
          'zhengche': '蒸车',
          'zhengqifashengqi': '蒸汽发生器',
          'zaoju': '灶具',
          'yasuoji': '压缩机',
          'mokuailu': '模块炉',
          'danweikw': '锅炉单位(KW)',
          'danweimw': '锅炉单位(MW)',
          'dunwei': '锅炉吨位(T)',
          'f_meter_types': '表具明细',
          'f_construct_operator': '现场项目负责人',
          'f_contact': '联系人',
          'f_phone': '电话',
          'f_outdoors_time': ' 户内出单日期 ',
          'f_outdoors_receipt_time': ' 户内回单日期 ',
          'f_courtyard_time': ' 庭院出单日期 ',
          'f_courtyard_receipt_time': ' 庭院回单日期 ',
          'f_construction_unit':'施工单位',
          'f_house_type': ' 新 旧 报 建 '
        }
      }
    },
    ready () {
      // 调用查询
      // this.search()
    },
    events: {
    },
    methods: {
      loadPage () {
        this.$dispatch('loadPage')
      },
      searchCondition (args) {
        args.condition = args.condition
        if (args.condition.includes('民用报建')) {
          args.condition = args.condition.replace('f_apply_type = \'民用报建\'', '(f_apply_type = \'民用报建\' or f_apply_type = \'分户挂表\')');
        }
        args.condition += ` and act1.userids like '%${this.$login.f.id}%'`
        console.log("args.condition",args.condition)
        this.model.search(args.condition, args.model)
      },
      // 查询
      search () {
        this.$dispatch('search')
      },
      check (val) {
        this.$dispatch('apply', val)
      },
      async applyTypeChange () {
        let http = new HttpResetClass()
        if (!isEmpty(this.$refs.cp.$refs.cri.model.f_apply_type)) {
          let res = await http.load('POST', 'rs/logic/getDefnameByType', {
              f_apply_type: this.$refs.cp.$refs.cri.model.f_apply_type},
            {resolveMsg: null, rejectMsg: '流程标识获取失败！！！'}
          )
          this.defnames = [{label: '全部', value: ''}, ...res.data]
          // this.applyNatures = isEmpty(this.$appdata.getParam(`${this.$refs.cp.$refs.cri.model.f_apply_type}性质`)) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam(`${this.$refs.cp.$refs.cri.model.f_apply_type}性质`)]
        } else {
          this.defnames = isEmpty(this.$appdata.getParam('办理环节')) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam('办理环节')]
          // this.applyNatures = isEmpty(this.$appdata.getParam('报建性质')) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam('报建性质')] // 报建性质
        }
      },
      async getDesigner() {
        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("ces",res.data.map(item => {
          return {
            label: item.name,
            value: item.name
          }
        }))
        this.designerPeoples = res.data.map(item => {
          return {
            label: item.name,
            value: item.name
          }
        })
      },
      clear () {
        Object.keys(this.$refs.cp.$refs.cri.model).forEach((key) => {
          this.$refs.cp.$refs.cri.model[key] = null
          this.$refs.cp.$refs.cri.model.f_apply_type = []
        })
      }
    },
    computed: {
      getCondition () {
        return {
          condition: this.$refs.cp.$refs.cri.condition,
          data: {
            // orgid: this.$login.f.orgid
            f_filiale: "榆林."+this.$login.f.orgs
          }
        }
      },
      getLoginDepartment(){
        return this.$login.f.rolesnames.includes('市场部报装')
      }
    }
  }
</script>
<style scoped>
</style>
