<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="委托单位名称">
              <j-search-select-tag placeholder="请选择委托单位名称" value="" :dictOptions="weituoClientList"
                                   @change="handlewcChange" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="委托编号">
              <j-search-select-tag placeholder="请选择委托编号" v-model="weituoId" :dictOptions="weituoNoList"
                                   @change="handlewnChange" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="日期">
              <j-search-select-tag placeholder="请选择日期" :dictOptions="gongdanDateList" @change="handlegddChange" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="工单号">
              <j-search-select-tag placeholder="请选择工单" v-model="queryParam.woId" :dictOptions="gongdanList"
                                   @change="handlegdChange" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="试验类型">
              <j-multi-select-tag ref="shiyanType" placeholder="请选择试验类型" dictCode="shiiyan_type"
                                  v-model="shiyanType" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="试验开始时间">
                <a-time-picker
                  style="width: 100%"
                  format="HH:mm"
                  :valueFormat="'HH:mm'"
                  v-model="shiyanKaishitime"
                  placeholder="请选择试验开始时间"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="试验结束时间">
                <a-time-picker
                  style="width: 100%"
                  format="HH:mm"
                  :valueFormat="'HH:mm'"
                  v-model="shiyanJieshutime"
                  placeholder="请选择结束时间"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="频次">
                <a-input placeholder="请输入频次（分钟）" v-model="queryParam.pinci"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" @click="submitSJ" icon="check" style="margin-left: 8px">提交</a-button>
              <a-button type="primary" @click="create" icon="vertical-align-bottom" style="margin-left: 8px">生成</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('工单数据')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
    <!-- 高级查询区域 -->
    <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
    <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
      <a-menu slot="overlay">
        <a-menu-item key="1" @click="batchDel">
          <a-icon type="delete" />
          删除
        </a-menu-item>
      </a-menu>
      <a-button style="margin-left: 8px"> 批量操作
        <a-icon type="down" />
      </a-button>
    </a-dropdown>
    </div> -->

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <!-- <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table> -->

      
        <vxe-toolbar>
          <template #buttons>
            <vxe-button icon="vxe-icon-square-plus" @click="insertEvent()">新增</vxe-button>
            <vxe-button @click="$refs.xTable.removeCheckboxRow()">删除选中</vxe-button>
          </template>
        </vxe-toolbar>

        <vxe-table
          border
          show-overflow
          ref="xTable"
          height="500"
          :data="dataSource"
          :mouse-config="{selected: true}"
          :checkbox-config="{range: true}"
          :menu-config="tableMenu"
          :loading="loading"
          :keyboard-config="{isArrow: true, isDel: true, isEnter: true, isTab: true, isEdit: true, isChecked: true}"
          :edit-config="{trigger: 'dblclick', mode: 'cell'}">
          <vxe-column type="checkbox" width="60"></vxe-column>
          <vxe-column field="shiyanType_dictText" title="试验类型" :edit-render="{autofocus: '.vxe-input--inner'}">
            <template #edit="{ row }">
              <input v-model="row.shiyanType" type="text" class="myinput" />
            </template>
          </vxe-column>
          <vxe-column field="shiyanTime" title="生成时间" :edit-render="{autofocus: '.vxe-input--inner'}">
            <template #edit="{ row }">
              <vxe-input v-model="row.shiyanTime" type="text"></vxe-input>
            </template>
          </vxe-column>
          <vxe-column field="shiyanWendu" title="温度" :edit-render="{autofocus: '.vxe-input--inner'}">
            <template #edit="{ row }">
              <vxe-input v-model="row.shiyanWendu" type="text"></vxe-input>
            </template>
          </vxe-column>
          <vxe-column field="shiyanShidu" title="湿度" :edit-render="{autofocus: '.vxe-input--inner'}">
            <template #edit="{ row }">
              <vxe-input v-model="row.shiyanShidu" type="text"></vxe-input>
            </template>
          </vxe-column>
        </vxe-table>
    </div>

    <itdm-gongdan-shuju-modal ref="modalForm" @ok="modalFormOk"></itdm-gongdan-shuju-modal>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { saveSj } from '@/api/api'
import '@assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ItdmGongdanShujuModal from './modules/ItdmGongdanShujuModal'
import { filterMultiDictText } from '@comp/dict/JDictSelectUtil'
import VXETable from 'vxe-table'

export default {
  name: 'ItdmGongdanShujuList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ItdmGongdanShujuModal
  },
  data() {
    return {
      weituoId: '',
      weituoClientList: [],
      weituoNoList: [],
      gongdanList: [],
      gongdanDateList: [],
      gongdanDetailList: [],
      shiyanKaishitime: '',
      shiyanJieshutime: '',
      shiyanType: 0,

      // queryParam:{
      //   woId:"1660195756643786754",
      //   shiyanType:"0,1",
      //   shiyanKaishitime:"00:00",
      //   shiyanJieshutime:"23:59",
      //   pinci:"90"
      // },
      description: '工单数据管理页面',
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        // {
        //   title:'工单id',
        //   align:"center",
        //   dataIndex: 'woId'
        // },
        {
          title: '试验类型',
          align: 'center',
          dataIndex: 'shiyanType_dictText'
        },
        // {
        //   title:'试验开始时间',
        //   align:"center",
        //   dataIndex: 'shiyanKaishitime'
        // },
        // {
        //   title:'试验结束时间',
        //   align:"center",
        //   dataIndex: 'shiyanJieshutime'
        // },
        // {
        //   title:'频次',
        //   align:"center",
        //   dataIndex: 'pinci'
        // },
        {
          title: '生成的时间',
          align: 'center',
          dataIndex: 'shiyanTime'
        },
        {
          title: '试验数据温度',
          align: 'center',
          dataIndex: 'shiyanWendu'
        },
        {
          title: '试验数据湿度',
          align: 'center',
          dataIndex: 'shiyanShidu'
        },
        {
          title: '任务日期',
          align: 'center',
          dataIndex: 'workDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        // {
        //   title:'试验图片',
        //   align:"center",
        //   dataIndex: 'extraPic',
        //   scopedSlots: {customRender: 'imgSlot'}
        // },
        // {
        //   title:'备注',
        //   align:"center",
        //   dataIndex: 'remark'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/itdmgomgongdanshuju/ItdmGongdanshuju/list',
        delete: '/itdmgomgongdanshuju/ItdmGongdanShuju/delete',
        deleteBatch: '/itdmgomgongdanshuju/ItdmGongdanshuju/deleteBatch',
        exportXlsUrl: '/itdmgongdanshuju/itdmGongdanShuju/exportXls',
        importExcelUrl: 'itdmgongdanshuju/itdmGongdanShuju/importExcel',
        add: '/itdmgomgongdanshuju/ItdmGongdanshuju/add'

      },
      dictOptions: {},
      superFieldList: [],

      // vex-table
      // tableData: [
      //   { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
      //   { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
      //   { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
      //   { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 23, address: 'test abc' },
      //   { id: 10005, name: 'Test5', role: 'Develop', sex: 'Women', age: 30, address: 'Shanghai' },
      //   { id: 10006, name: 'Test6', role: 'Designer', sex: 'Women', age: 21, address: 'test abc' },
      //   { id: 10007, name: 'Test7', role: 'Test', sex: 'Man', age: 29, address: 'test abc' },
      //   { id: 10008, name: 'Test8', role: 'Develop', sex: 'Man', age: 35, address: 'test abc' }
      // ],
      tableMenu: {
        body: {
          options: [
            [
              { code: 'copy', name: '复制', prefixIcon: 'vxe-icon-copy', disabled: false },
              { code: 'remove', name: '删除', disabled: false },
              { code: 'save', name: '保存', prefixIcon: 'vxe-icon-save', disabled: false }
            ]
          ]
        }
      },
    }
  },
  created() {
    this.isorter.column = 'id'
    this.isorter.order = 'asc'

    this.getSuperFieldList()
    this.init()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {

          // vex-table
          async insertEvent () {
            const $table = this.$refs.xTable
            const record = {
              sex: '1'
            }
            const { row: newRow } = await $table.insertAt(record)
            await $table.setActiveCell(newRow, 'name')
          },
          getInsertEvent () {
            const $table = this.$refs.xTable
            const insertRecords = $table.getInsertRecords()
            VXETable.modal.alert(insertRecords.length)
          },
          getSelectionEvent () {
            const $table = this.$refs.xTable
            const selectRecords = $table.getCheckboxRecords()
            VXETable.modal.alert(selectRecords.length)
          },

      // 提交
      submitSJ(){
        console.log(this.dataSource)
        saveSj(this.dataSource).then((res) => {
          confirm.log(res)
        })
      },

    init() {

      getAction('/weituo/itdmWeituoInfo/distinctClientList', {}).then((res) => {
        if (res.success) {
          console.log(res.result)
          this.weituoClientList = res.result.map(i => {
            return { value: i, text: i }
          })
          console.log(this.weituoClientList)
        }
      })

    },

    handlewcChange(data) {

      var weituoClient = { weituoClient: data }
      getAction('/weituo/itdmWeituoInfo/weituoNoList', weituoClient).then((res) => {
        if (res.success) {
          console.log('xxxxxxxxxxxxxxxxxxx')
          console.log(res.result)
          this.weituoNoList = res.result.map(i => {
            return { value: i.id, text: i.weituoNo }
          })
          console.log(this.weituoNoList)
        }
      })
      console.log(data)
    },

    handlewnChange(data) {

      //gongdanDateList
      var weituoClient = { weituoId: data }

      // getAction('/gongdandetail/itdmGongdanDetail/gongdanIdList', weituoClient).then((res) => {
      //   if (res.success) {
      //     console.log("=========================")
      //     console.log(res.result)
      //     this.gongdanList = res.result.map(i=>{
      //       return { value: i, text: i}
      //     })
      //     console.log(this.gongdanList)
      //   }
      // })

      getAction('/gongdandetail/itdmGongdanDetail/gongdanWorkdateList', weituoClient).then((res) => {
        if (res.success) {
          console.log('=========================')
          console.log(res.result)
          this.gongdanDateList = res.result.map(i => {
            return { value: i, text: i }
          })
          console.log(this.gongdanDateList)
        }
      })

    },

    handlegdChange(data) {
      var woId = { woId: data }
      getAction('/gongdandetail/itdmGongdanDetail/gongdanDateListByWoId', woId).then((res) => {
        if (res.success) {
          console.log('****************')
          this.$refs.shiyanType.onChange([])
          this.shiyanType =''

          for (const key in res.result) {
            this.shiyanType = res.result[key].shijiShiiyanType
            this.shiyanKaishitime = res.result[key].shijiStartTime
            this.shiyanJieshutime = res.result[key].shijiEndTime
            console.log(this.queryParam)

          }
        }
      })

    },
    handlegddChange(data) {
      console.log(data)
      //gongdanList
      var weituoClient = { weituoId: this.weituoId, workdate: data }

      getAction('/gongdandetail/itdmGongdanDetail/gongdanWoIdList', weituoClient).then((res) => {
        if (res.success) {
          console.log('=========================')
          console.log(res.result)
          this.gongdanList = res.result.map(i => {
            return { value: i, text: i }
          })
          console.log(this.gongdanList)
        }
      })

      // for (const key in this.gongdanDetailList) {
      //
      //   if(this.gongdanDetailList[key].shijiWorkDate === data) {
      //
      //     this.queryParam.shiyanType = this.gongdanDetailList[key].shijiShiiyanType;
      //     this.queryParam.shiyanKaishitime = this.gongdanDetailList[key].shijiStartTime;
      //     this.queryParam.shiyanJieshutime = this.gongdanDetailList[key].shijiEndTime;
      //     console.log(this.queryParam)
      //   }
      //
      // }
    },

    initDictConfig() {
    },

    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'woId', text: '工单id', dictCode: '' })
      fieldList.push({
        type: 'list_multi',
        value: 'shiyanType',
        text: '试验类型',
        dictTable: '',
        dictText: '',
        dictCode: 'shiiyan_type'
      })
      fieldList.push({ type: 'string', value: 'shiyanKaishitime', text: '试验开始时间', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shiyanJieshutime', text: '试验结束时间', dictCode: '' })
      fieldList.push({ type: 'string', value: 'pinci', text: '频次', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shiyanTime', text: '生成的时间', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shiyanWendu', text: '试验数据温度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shiyanShidu', text: '试验数据湿度', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'extraPic', text: '试验图片', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      this.superFieldList = fieldList
    },
    create() {

      var select = this.queryParam
      select.shiyanKaishitime = this.shiyanKaishitime
      select.shiyanJieshutime = this.shiyanJieshutime
      select.shiyanType = this.shiyanType




      httpAction('/itdmgomgongdanshuju/ItdmGongdanshuju/create',select, 'post').then((res) => {
        if (res.success) {
          console.log(res)
          this.$message.success(res.message)
          this.modalFormOk()
        } else {
          this.$message.warning(res.message)
        }
        this.searchReset()
      })

    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>