<template>
  <div class="app-container">
    <div class="filter-container">
      <!-- 搜索条件 -->
      <el-select
        v-model="getdataListParm.parammaps.pastureName"
        placeholder="牧场"
        class="filter-item"
        style="width:120px;"
      >
        <el-option
          v-for="item in findAllPasture"
          :key="item.id"
          :label="item.name"
          :value="item.name"
        />
      </el-select>
      <el-input
        v-model="getdataListParm.parammaps.assetName"
        placeholder="设备名称"
        style="width: 140px;"
        class="filter-item"
      />
      <el-input
        v-model="getdataListParm.parammaps.assetNumber"
        placeholder="设备内部编号"
        style="width: 140px;"
        class="filter-item"
      />

      <!-- <el-date-picker
        v-model="getdataListParm.parammaps.date"
        type="date"
        placeholder="点检时间"
        style="width:170px;top:-3px;"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
      /> -->

      <el-date-picker ref="inputDatetime" v-model="getdataListParm.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />

      <!-- <el-date-picker
        v-model="getdataListParm.parammaps.startTime"
        type="date"
        placeholder="开始日期"
        style="width:140px;top:-3px;"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
      />
      <el-date-picker
        v-model="getdataListParm.parammaps.stopTime"
        type="date"
        placeholder="结束日期"
        style="width:140px;top:-3px;"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
      /> -->
      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="form_search"
      >搜索</el-button>
      <div>
        <el-button
          v-if="isSpotCheckAdd"
          class="filter-item"
          style="margin-left: 10px;"
          type="primary"
          icon="el-icon-edit"
          @click="form_add"
        >点检</el-button>
      </div>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      element-loading-text="给我一点时间"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      :row-style="rowStyle"
      :cell-style="cellStyle"
      class="elTable"
    >
      <!-- table表格 -->
      <el-table-column label="序号" align="center" type="index" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备内部编号" align="center" width="150px">
        <template slot-scope="scope">
          <span>{{ scope.row.assetNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备名称" width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.assetName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备类别" width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.typeName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.department }}</span>
        </template>
      </el-table-column>

      <el-table-column label="点检结果" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.inspectionResults }}</span>
        </template>
      </el-table-column>
      <el-table-column label="点检人" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.inspection }}</span>
        </template>
      </el-table-column>

      <el-table-column label="点检日期" sortable prop="date" min-width="110px" align="center" />

      <el-table-column label="操作" align="center" width="240" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="form_see(row)">查看</el-button>
          <!-- <el-button v-if="isSpotCheckUpdate" type="success" size="mini" @click="form_edit(row)">编辑</el-button> -->
          <el-button v-if="isSpotCheckDelate" type="danger" size="mini" @click="form_delete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="getdataListParm.offset"
      :limit.sync="getdataListParm.pagecount"
      @pagination="getList"
    />
    <!-- 弹出层点检 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form ref="temp" :rules="rules" :model="temp" label-position="right" label-width="140px" style="width: 800px; margin-left:50px;">
        <el-row>

          <el-col :span="12">
            <el-form-item label="设备名称：" prop="assetName">
              <el-autocomplete
                ref="assetName"
                v-model="temp.assetName"
                value-key="assetName"
                class="inline-input"
                :fetch-suggestions="formNameSearch"
                placeholder="请输入内容"
                :disabled="dialogStatus==='update'||dialogStatus==='see'"
                style="width:250px;"
                @select="handleformNameSelect"
              >
                <template slot-scope="{ item }">
                  <div class="name" style="display: inline;">{{ item.eqName }}</div>
                  <span class="addr">{{ item.eqCode }}</span>
                </template>
              </el-autocomplete>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="牧场设备编号：" prop="eqCode">
              <el-autocomplete
                ref="eqCode"
                v-model="temp.eqCode"
                value-key="eqCode"
                class="inline-input"
                :fetch-suggestions="formNumberSearch"
                placeholder="请输入内容"
                :disabled="dialogStatus==='update'||dialogStatus==='see'"
                style="width:250px;"
                @select="handleformNumberSelect"
              >
                <template slot-scope="{ item }">
                  <div class="name" style="display: inline;">{{ item.eqName }}</div>
                  <span class="addr">{{ item.eqCode }}</span>
                </template>
              </el-autocomplete>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="点检人：" prop="employeId">
              <el-select
                v-model="assetA.employeId"
                placeholder="点检人"
                class="filter-item"
                style="width:250px;"
                :disabled="dialogStatus==='update'||dialogStatus==='see'"
              >
                <el-option
                  v-for="item in findAllEmploye"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="点检日期：" prop="date">
              <el-date-picker
                v-model="assetA.date"
                type="date"
                placeholder="日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                :disabled="dialogStatus==='update'||dialogStatus==='see'"
                style="width:250px;"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        element-loading-text="给我一点时间"
        :data="tempSolr"
        border
        fit
        highlight-current-row
        style="width: 100%;margin-bottom:50px"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable"
      >
        <!-- table表格 -->
        <el-table-column
          type="index"
          label="序号"
          width="50"
        />
        <el-table-column label="部位" width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.partName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="检查内容" width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.examine }}</span>
          </template>
        </el-table-column>

        <el-table-column label="标准" min-width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.standard }}</span>
          </template>
        </el-table-column>

        <el-table-column label="检查结果" min-width="80px" header-align="center" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.checkResult"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="0"
              :inactive-value="1"
              :disabled="dialogStatus==='see'"
              @change="handleEnableChange(scope.$index, scope.row)"
            />
          </template>
        </el-table-column>

        <el-table-column v-if="dialogStatus==='create'" label="备注" min-width="130px" align="center">
          <template slot-scope="scope">
            <input
              v-model="scope.row.note"
              type="text"
              value="scope.row.note"
              style="width:130px;"
            >
          </template>
        </el-table-column>
        <el-table-column v-if="dialogStatus==='see'" label="备注" min-width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.note }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="dialogStatus==='create'" type="primary" @click="dialogStatus==='create'?add_dialog_save():edit_dialog_save()">确认</el-button>
        <el-button @click="dialogFormVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入
import { GetDataByName, GetDataByNames, PostDataByName, ExecDataByConfig, checkButtons } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils/index.js'
// eslint-disable-next-line no-unused-vars
import { validateEMail } from '@/utils/validate.js'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
// import { connect } from 'http2'
export default {
  name: 'SpotCheck',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      isSpotCheckAdd: [],
      isSpotCheckUpdate: [],
      isSpotCheckDelate: [],
      tableKey: 0,
      list: [],
      total: 0,
      list2: [],
      listLoading: true,
      state1: '',
      solrASssetTypeId: '',
      requestParam: {
        name: 'insertAsset',
        offset: 0,
        pagecount: 0,
        parammaps: {}
      },
      tempSolr: {
        assetNumber: '',
        assetName: '',
        assetTypeId: '',
        assetId: '',
        bigIds: ''
      },
      assetA: {
        date: parseTime(new Date(), '{y}-{m}-{d}'),
        inputDatetime: parseTime(new Date(), '{y}-{m}-{d}'),
        typeName: '',
        assetTypeId: '',
        assetName: '',
        assetNumber: '',
        employeId: this.$store.state.user.employeid,
        departmentId: this.$store.state.user.departmentid,
        pastureId: this.$store.state.user.pastureid,
        eqCode: '',
        eqName: '',
        eqId: ''
      },
      requestFilterParams: {
        parammaps: {}
      },
      // 1-2:table& 搜索传参
      getdataListParm: {
        name: 'getBigSpotcheckList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          inputDatetime: '',
          pastureName: Cookies.get('pasturename'),
          assetNumber: '',
          assetName: '',
          startTime: '',
          stopTime: ''
        }
      },

      // 2-3：下拉框请求后数据加入[]
      findAllProvider: [],
      findAllAssetType: [],
      findAllPasture: [],
      findAllDepart: [],
      findAllEmploye: [],
      getDictByName: [],
      // 2-1.请求下拉框接口
      requestParams: [
        { name: 'findAllProvider', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllAssetType', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'getDictByName', offset: 0, pagecount: 0, params: ['资产状态'] }
      ],

      postDataPramas: {
        'common': {
          'returnmap': '0'
        },
        'data': [
          {
            'name': 'checkSpotCheck',
            'type': 'v',
            'parammaps': {
              'assetNumber': '',
              'checkdate': ''
            }
          },
          {
            'name': 'insertBigSpotCheck1',
            'resultname': 'insertBigSpotcheck1',
            'type': 'e',
            'parammaps': {
              'assetNumber': '',
              'assetName': '',
              'employeId': '',
              'date': '',
              'eqId': '',
              'inspectionResults': '',
              'departmentId': '',
              'assetTypeId': '',
              'pastureId': ''
            }
          },
          {
            'name': 'insertSpotList',
            'resultmaps': {
              'list': []
            },
            'children': [
              {
                'name': 'insertSpotCheck1',
                'type': 'e',
                'parammaps': {
                  'partName': '@insertSpotList.partName',
                  'examine': '@insertSpotList.examine',
                  'standard': '@insertSpotList.standard',
                  'note': '@insertSpotList.note',
                  'assetTypeId': '@insertSpotList.assetTypeId',
                  'checkResult': '@insertSpotList.checkResult',
                  'bigId': '@insertBigSpotcheck1.LastInsertId',
                  'partId': '@insertSpotList.partId'
                }
              }
            ]
          },
          {
            'name': 'updateSpotCheckResults',
            'type': 'e',
            'parammaps': {
              'id': '@insertBigSpotcheck1.LastInsertId'
            }
          }
        ]
      },
      temp: {
        assetName: '',
        assetNumber: '',
        eqCode: '',
        eqName: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '点检',
        see: '查看'
      },
      dialogPvVisible: false,
      // 校验规则
      rules: {
        assetNumber: [
          { required: true, message: '必填', trigger: 'blur' }
          // 引入自定义校验并使用
          // { validator: validateEMail, trigger: 'blur' }
        ],
        equipmentName: [{ required: true, message: '必填', trigger: 'blur' }]
      },
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      buttons: []
    }
  },
  created() {
    const that = this
    GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': Cookies.get('name') }}).then(response => {
      that.buttons = response.data.list
      that.get_auto_buttons()
    })
    this.get_select_list()
    this.getList()
  },

  methods: {
    get_auto_buttons() {
      // 点检
      const SpotCheckAdd = 'maintenance:spotCheck:add'
      const isSpotCheckAdd = checkButtons(this.$store.state.user.buttons, SpotCheckAdd)
      this.isSpotCheckAdd = isSpotCheckAdd
      // 编辑
      const SpotCheckUpdate = 'maintenance:spotCheck:update'
      const isSpotCheckUpdate = checkButtons(this.$store.state.user.buttons, SpotCheckUpdate)
      this.isSpotCheckUpdate = isSpotCheckUpdate
      // 删除
      const SpotCheckDelate = 'maintenance:spotCheck:delate'
      const isSpotCheckDelate = checkButtons(this.$store.state.user.buttons, SpotCheckDelate)
      this.isSpotCheckDelate = isSpotCheckDelate
    },
    // 模糊查询-点检名称
    formNumberSearch(queryString, cb) {
      this.requestFilterParams.name = 'findAssetMain'
      this.requestFilterParams.offset = 0
      this.requestFilterParams.pagecount = 20
      this.requestFilterParams.parammaps['eqCode'] = queryString
      this.requestFilterParams.parammaps['eqName'] = ''
      this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
      // this.requestFilterParams.parammaps['deptId'] = this.$store.state.user.departmentid
      this.requestFilterParams.parammaps['assetNumber'] = queryString
      this.requestFilterParams.parammaps['assetName'] = ''
      GetDataByName(this.requestFilterParams).then(response => {
        cb(response.data.list)
      })
    },
    formNameSearch(queryString, cb) {
      this.requestFilterParams.name = 'findAssetMain'
      this.requestFilterParams.offset = 0
      this.requestFilterParams.pagecount = 20
      this.requestFilterParams.parammaps['assetNumber'] = ''
      this.requestFilterParams.parammaps['assetName'] = queryString
      this.requestFilterParams.parammaps['eqCode'] = ''
      this.requestFilterParams.parammaps['eqName'] = queryString
      this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
      // this.requestFilterParams.parammaps['deptId'] = this.$store.state.user.departmentid
      GetDataByName(this.requestFilterParams).then(response => {
        cb(response.data.list)
      })
    },
    handleformNumberSelect(item) {
      console.log(item)

      this.requestFilterParams.name = 'findByBigIdSpotCheck'
      this.requestFilterParams.parammaps['assetName'] = item.assetName
      this.requestFilterParams.parammaps['assetNumber'] = item.assetNumber
      this.requestFilterParams.parammaps['eqName'] = item.eqName
      this.requestFilterParams.parammaps['eqCode'] = item.eqCode
      this.requestFilterParams.parammaps['eqId'] = item.eqId
      this.temp.assetName = item.assetName
      this.temp.eqCode = item.eqCode
      this.assetA.assetNumber = item.assetNumber
      this.assetA.assetName = item.assetName
      this.assetA.assTypeId = item.assetTypeId
      this.assetA.assetId = item.assetId
      this.assetA.eqCode = item.eqCode
      this.assetA.eqName = item.eqName
      this.assetA.eqId = item.eqId
      this.temp.assetNumber = item.assetNumber
      this.temp.assetName = item.assetName
      this.temp.eqCode = item.eqCode
      this.temp.eqName = item.eqName

      this.assetA.date = parseTime(new Date(), '{y}-{m}-{d}')
      GetDataByName(this.requestFilterParams).then(response => {
        this.$nextTick(() => {
          console.log(response.data.list.length)
          if (response.data.list.length !== null && response.data.list.length > 0) {
            console.log(this.tempSolr)
            console.log(response.data.list)
            this.tempSolr = response.data.list
          }
        })
      })
    },
    handleformNameSelect(item) {
      console.log(item)
      this.requestFilterParams.name = 'findByBigIdSpotCheck'
      this.requestFilterParams.parammaps['assetName'] = item.assetName
      this.requestFilterParams.parammaps['assetNumber'] = item.assetNumber
      this.requestFilterParams.parammaps['eqName'] = item.eqName
      this.requestFilterParams.parammaps['eqCode'] = item.eqCode
      this.requestFilterParams.parammaps['eqId'] = item.eqId

      this.temp.assetName = item.assetName
      this.temp.eqCode = item.eqCode
      this.temp.assetNumber = item.assetNumber
      this.temp.assetName = item.assetName
      this.temp.eqCode = item.eqCode
      this.temp.eqName = item.eqName

      this.assetA.assetNumber = item.assetNumber
      this.assetA.assetName = item.assetName
      this.assetA.assTypeId = item.assetTypeId
      this.assetA.assetId = item.assetId
      this.assetA.eqCode = item.eqCode
      this.assetA.eqName = item.eqName
      this.assetA.eqId = item.eqId

      this.assetA.date = parseTime(new Date(), '{y}-{m}-{d}')
      GetDataByName(this.requestFilterParams).then(response => {
        this.$nextTick(() => {
          if (response.data.list.length !== null && response.data.list.length > 0) {
            this.tempSolr = response.data.list
          }
        })
      })
    },

    // 将获取的点检信息插入的数据库中big（主表）
    insertBigSpotCheck() {
      if (this.list.length > 0) {
        this.requestFilterParams.name = 'insertBigSpotCheck'
        this.requestFilterParams.parammaps = {}
        this.requestFilterParams.parammaps = this.tempSolr
        console.log(this.requestFilterParams)
        GetDataByName(this.requestFilterParams).then(response => {
          this.tempSolr.bigIds = response.data.list[0].bigId // 获取生成父表中的主键
        })
      }
    },

    // 请求信息，获取点检模板中的信息
    handleSpotCheckTemp(tempSolr) {
      this.requestParams.name = 'findByBigIdSpotCheck'
      this.requestParams.parammaps['bigId'] = this.tempSolr.assTypeId
      GetDataByName(this.requestParams).then(response => {
        this.$nextTick(() => {
          if (response.data.list.length > 0) {
            this.list2 = response.data.list
          }
        })
      })
    },

    // 保存子表中的信息
    insertSpotCheck(tempSolr) {
      // this.requestFilterParams.name = 'insertSpotCheck'
      // this.requestParam.parammaps = {}
      // this.temp.bigId = this.bigIds
      // this.temp.assTypeId = this.tempSolr.assTypeId

      // this.requestParam.parammaps['fsion'] = this.list2
      // GetDataByName(this.requestParam).then(response => {
      //   this.$notify({
      //     title: '成功',
      //     message: '新增成功',
      //     type: 'success',
      //     duration: 2000
      //   })
      //   // this.uplodeStockList111()
      // })
    },

    handleEnableChange(index, row) {
      // if (this.dialogStatus === 'update') {
      //   this.postDataPramas.common = { 'returnmap': '0' }
      //   this.postDataPramas.data = []
      //   this.postDataPramas.data[0] = { 'name': 'updateSpotCheck', 'type': 'e', 'parammaps': {}}
      //   this.postDataPramas.data[0].parammaps['checkResult'] = row.checkResult
      //   this.postDataPramas.data[0].parammaps['id'] = row.id
      //   this.postDataPramas.data[1] = { 'name': 'updateSpotCheckResults', 'type': 'e', 'parammaps': { }}
      //   this.postDataPramas.data[1].parammaps['id'] = row.bigId
      //   ExecDataByConfig(this.postDataPramas).then(response => {
      //     this.$notify({
      //       title: '成功',
      //       message: '修改成功',
      //       type: 'success',
      //       duration: 2000
      //     })
      //   })
      // }
    },

    // 1-1: table&搜索
    getList() {
      this.listLoading = true

      // if (this.getdataListParm.parammaps.date === null) {
      //   this.getdataListParm.parammaps.date = ''
      // }
      // if (this.getdataListParm.parammaps.startTime === null) {
      //   this.getdataListParm.parammaps.startTime = ''
      // }
      // if (this.getdataListParm.parammaps.stopTime === null) {
      //   this.getdataListParm.parammaps.stopTime = ''
      // }
      if (this.$refs['inputDatetime'] !== undefined && this.$refs['inputDatetime'].value !== null) {
        this.getdataListParm.parammaps.startTime = this.$refs['inputDatetime'].value[0]
        this.getdataListParm.parammaps.stopTime = this.$refs['inputDatetime'].value[1]
      } else {
        this.getdataListParm.parammaps.startTime = ''
        this.getdataListParm.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParm).then(response => {
        this.list = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.total = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    // 2-2：下拉框
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        this.findAllProvider = response.data.findAllProvider.list
        this.findAllAssetType = response.data.findAllAssetType.list
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllDepart = response.data.findAllDepart.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.getDictByName = response.data.getDictByName.list
      })
    },
    form_search() {
      this.listLoading = true
      if (this.$refs['inputDatetime'] !== undefined && this.$refs['inputDatetime'].value !== null) {
        this.getdataListParm.parammaps.startTime = this.$refs['inputDatetime'].value[0]
        this.getdataListParm.parammaps.stopTime = this.$refs['inputDatetime'].value[1]
      } else {
        this.getdataListParm.parammaps.startTime = ''
        this.getdataListParm.parammaps.stopTime = ''
      }
      this.getdataListParm.offset = 1
      this.getList()
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    },
    form_reset() {
      this.assetA.inputDatetime = parseTime(new Date(), '{y}-{m}-{d}')
      this.assetA.typeName = ''
      this.assetA.assTypeId = ''
      this.assetA.assetTypeId = ''
      this.assetA.eqId = ''

      this.assetA.assetName = ''
      this.assetA.assetNumber = ''
      this.assetA.employeId = this.$store.state.user.employeid
      this.assetA.departmentId = this.$store.state.user.departmentid
      this.assetA.pastureId = this.$store.state.user.pastureid
      this.tempSolr = []

      this.temp.assetName = ''
      this.temp.eqCode = ''
    },
    form_add() {
      this.form_reset()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.assetA.employeId = this.$store.state.user.employeid
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },
    // add_dialog_save() {
    //   this.postDataPramas.common = { 'returnmap': '0' }
    //   this.postDataPramas.data = []
    //   this.postDataPramas.data[0] = { 'name': 'checkSpotCheck', 'type': 'v', 'parammaps': { 'assetNumber': this.assetA.assetNumber, 'checkdate': this.assetA.date }}

    //   this.postDataPramas.data[1] = { 'name': 'insertBigSpotCheck1', 'resultname': 'insertBigSpotcheck1', 'type': 'e', 'parammaps': {}}
    //   this.postDataPramas.data[1].parammaps = this.assetA
    //   this.postDataPramas.data[1].parammaps.assTypeId = this.tempSolr[0].assTypeId

    //   this.postDataPramas.data[1].parammaps.pastureId = this.$store.state.user.pastureid
    //   this.postDataPramas.data[2] = { 'name': 'insertSpotList', 'resultmaps': { 'list': [] }}
    //   this.postDataPramas.data[2].children = []
    //   this.postDataPramas.data[2].children[0] = { 'name': 'insertSpotCheck1', 'type': 'e', 'parammaps': { }}
    //   this.assetA.inspectionResults = 0

    //   this.postDataPramas.data[2].resultmaps.list = this.tempSolr
    //   this.postDataPramas.data[2].children[0].parammaps.partName = '@insertSpotList.partName'
    //   this.postDataPramas.data[2].children[0].parammaps.examine = '@insertSpotList.examine'
    //   this.postDataPramas.data[2].children[0].parammaps.standard = '@insertSpotList.standard'
    //   this.postDataPramas.data[2].children[0].parammaps.note = '@insertSpotList.note'
    //   this.postDataPramas.data[2].children[0].parammaps.assTypeId = '@insertSpotList.assetTypeId'
    //   this.postDataPramas.data[2].children[0].parammaps.checkResult = '@insertSpotList.checkResult'
    //   this.postDataPramas.data[2].children[0].parammaps.bigId = '@insertBigSpotcheck1.LastInsertId'
    //   this.postDataPramas.data[2].children[0].parammaps.partId = '@insertSpotList.partId'
    //   this.postDataPramas.data[3] = { 'name': 'updateSpotCheckResults', 'type': 'e', 'parammaps': { 'id': '@insertBigSpotcheck1.LastInsertId' }}

    //   ExecDataByConfig(this.postDataPramas).then(response => {
    //     if (response.msg === 'fail') {
    //       this.$notify({
    //         title: '保存失败',
    //         message: response.data,
    //         type: 'warning',
    //         duration: 2000
    //       })
    //     } else {
    //       this.getList()
    //       this.dialogFormVisible = false
    //       this.$notify({
    //         title: '',
    //         message: '保存成功',
    //         type: 'success',
    //         duration: 2000
    //       })
    //     }
    //   })
    // },
    add_dialog_save() {
      this.assetA.inspectionResults = ''
      if (this.tempSolr.length != null && this.tempSolr.length > 0) {
        var num = this.tempSolr.filter((i, j) => { return i.checkResult == 0 }).length
        var check_rest = '检测' + this.tempSolr.length + '项,合格' + num + '项'
        this.assetA.inspectionResults = check_rest
      } else {
        var check_rest = '检测0项,合格0项'
        this.assetA.inspectionResults = check_rest
      }

      this.postDataPramas.data[0].parammaps.assetNumber = this.assetA.assetNumber
      this.postDataPramas.data[0].parammaps.checkdate = this.assetA.date

      this.postDataPramas.data[1].parammaps = this.assetA
      this.postDataPramas.data[1].parammaps.assetTypeId = this.tempSolr[0].assetTypeId
      this.postDataPramas.data[1].parammaps.eqId = this.assetA.eqId

      this.postDataPramas.data[1].parammaps.pastureId = this.$store.state.user.pastureid
      this.postDataPramas.data[2].resultmaps.list = this.tempSolr

      ExecDataByConfig(this.postDataPramas).then(response => {
        if (response.msg === 'fail') {
          this.$notify({
            title: '保存失败',
            message: response.data,
            type: 'warning',
            duration: 2000
          })
        } else {
          this.getList()
          this.dialogFormVisible = false
          this.$notify({
            title: '',
            message: '保存成功',
            type: 'success',
            duration: 2000
          })
        }
      })
    },

    form_see(row) {
      console.log('row', row)
      this.assetA = Object.assign({}, row) // copy obj
      this.dialogStatus = 'see'
      this.dialogFormVisible = true
      this.temp.assetName = row.assetName
      this.temp.eqCode = row.assetNumber
      this.requestFilterParams.name = 'findByIdSpotCheck'
      this.requestFilterParams.parammaps['id'] = this.assetA.id
      GetDataByName(this.requestFilterParams).then(response => {
        this.tempSolr = response.data.list
        if (response.data.total) {
          this.total = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },
    form_edit(row) {
      this.assetA = Object.assign({}, row) // copy obj
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.requestFilterParams.name = 'findByIdSpotCheck'
      this.requestFilterParams.parammaps['id'] = this.assetA.id
      GetDataByName(this.requestFilterParams).then(response => {
        this.tempSolr = response.data.list
        if (response.data.total) {
          this.total = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },
    edit_dialog_save() {
      this.$refs['temp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'updateAsset'
          this.requestParam.parammaps = this.temp
          PostDataByName(this.requestParam).then(response => {
            console.log(response)
            if (response.msg === 'fail') {
              this.$notify({
                title: '失败',
                message: '保存失败-' + response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getList()
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },
    form_delete(row) {
      MessageBox.confirm('确认删除此条信息？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.postDataPramas.common = { 'returnmap': '0' }
          this.postDataPramas.data = []
          this.postDataPramas.data[0] = { 'name': 'deleteSpotcheck', 'type': 'e', 'parammaps': { }}
          this.postDataPramas.data[0].parammaps['id'] = row.id
          this.postDataPramas.data[1] = { 'name': 'deleteBigSpotcheck', 'type': 'e', 'parammaps': {}}
          this.postDataPramas.data[1].parammaps['id'] = row.id
          ExecDataByConfig(this.postDataPramas).then(response => {
            this.getList()
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
