<template>
  <div class="app-container">
    <div v-if="isPercentage" class="percentage" style="width: 210px;height: 90px;background: #fff;position: fixed;bottom: 0;left: 0;z-index: 9999999999999;">
      <h4 style="padding-left: 10px;line-height: 0;">导出进度：</h4>
      <el-progress style="padding-left: 10px;" :text-inside="true" :stroke-width="26" :percentage="percentage" />
    </div>
    <div class="filter-container">
      <el-select v-model="tableObj.parammaps.pastureName" placeholder="牧场" style="width: 140px;" class="filter-item" @change="change_pasture1">
        <el-option v-for="item in pastureList" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-select v-model="tableObj.parammaps.departName" clearable placeholder="部门" class="filter-item">
        <el-option v-for="item in departList1" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <!-- <el-input v-model="tableObj.parammaps.formNumber" placeholder="编号" style="width: 140px;" class="filter-item" />
      <el-input v-model="tableObj.parammaps.formName" placeholder="表名称" style="width: 140px;" class="filter-item" />
      <el-select v-model="tableObj.parammaps.formType" clearable placeholder="表结构" class="filter-item">
        <el-option v-for="item in useTypes" :key="item.id" :label="item.name" :value="item.name" />
      </el-select> -->
      <el-date-picker v-model="tableObj.parammaps.date" 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="isElecAdd" class="filter-item" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
        <el-button v-if="isElecExport" v-waves class="filter-item" type="success" icon="el-icon-download" @click="form_export">导出</el-button>
        <el-upload style="display: inline-block;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImportExcel" :on-success="handleImportExcelSuccess">
          <el-button v-if="isElecImport" v-waves class="filter-item" type="warning" icon="el-icon-upload2" @click="form_search">导入</el-button>
        </el-upload>
        <el-button class="filter-item" type="danger" icon="el-icon-download" @click="form_delete">删除</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"
 
    >
      <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="牧场"  min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.pastureName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门"  min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.departmentName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当天汽油用量" min-width="140px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.dosage }}</span>
        </template>
      </el-table-column>
 
      <el-table-column label="单价"  min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.price }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当天费用"  min-width="110px"align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.expense  }}</span>
        </template>
      </el-table-column>
      <el-table-column label="记录人" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.empname   }}</span>
        </template>
      </el-table-column>
      <el-table-column label="日期" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.date  }}</span>
        </template>
      </el-table-column>
 
      <el-table-column label="备注" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.remarks  }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button v-if="isElecModify" type="success" size="mini" @click="form_edit(row)">编辑</el-button>
          <el-button type="primary" size="mini" style="width:70px" @click="see_record(row)">用量记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination v-show="total>0" :total="total" :page.sync="tableObj.offset" :limit.sync="tableObj.pagecount" @pagination="get_table_data" />
    <!-- 弹出层新增or修改 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form ref="temp" :rules="rules1" :model="temp" label-position="right" label-width="110px">
        
        <el-row>
           
          <el-col :span="8">

            <el-form-item label="牧场：" prop="pastureId" v-show="dialogStatus==='create'">
                <el-select v-model="temp.pastureId" placeholder="牧场"   class="filter-item" @change="change_pasture2" style="width:100%">
                  <el-option v-for="item in pastureList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
            </el-form-item>

            <el-form-item label="牧场：" prop="pastureId" v-show="dialogStatus==='update'">
                <el-input ref="pastureName" v-model="temp.pastureName"  disabled />
            </el-form-item>


          </el-col>
          <el-col :span="8">
            <el-form-item label="部门："  prop="departmentId"  v-show="dialogStatus==='create'">
              <el-select v-model="temp.departmentId" clearable placeholder="部门" class="filter-item" style="width:100%">
                <el-option v-for="item in departList2" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item label="部门："  prop="departmentId"  v-show="dialogStatus==='update'">
                <el-input ref="departmentName" v-model="temp.departmentName"  disabled />
            </el-form-item>
    
          </el-col>
 

           
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="当前汽油用量：" prop="dosage">
              <el-input ref="dosage" v-model="temp.dosage"    />
            </el-form-item>
          </el-col>
         
          <el-col :span="8">
            <el-form-item label="单价(元)：" prop="price">
              <el-input ref="price" v-model="temp.price"   />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当前费用：" prop="expense">
              <el-input ref="expense" v-model="temp.expense"   />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="记录人：" prop="inputid"   v-show="dialogStatus==='create'">
              <el-select ref="inputid" v-model="temp.inputid " placeholder="记录人" class="filter-item" style="width:100%;"   @change="change_emp">
                <el-option v-for="item in findAllEmploye" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item label="记录人："  prop="empname"  v-show="dialogStatus==='update'" >
              <el-input ref="empname" v-model="temp.empname"  disabled />
            </el-form-item>
           
          </el-col>
          <el-col :span="8">
            <el-form-item label="录入日期：" prop="date">
              <el-date-picker v-model="temp.date" type="date" placeholder="当前时间" format="yyyy-MM-dd" value-format="yyyy-MM-dd" disabled style="width:100%;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注：" prop="remarks">
              <el-input ref="remarks" v-model="temp.remarks"  />
            </el-form-item>
          </el-col>
          
        </el-row>
         
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="dialogStatus==='create'" ref="createb" type="success" :disabled="isokDisable" @click="add_dialog_save_again()">保存并新增</el-button>
        <el-button type="primary" :disabled="isokDisable" @click="dialogStatus==='create'?add_dialog_save():edit_dialog_save()">保存并关闭</el-button>
        <el-button @click="dialogFormVisible = false;get_table_data()">取消并关闭</el-button>
      </div>
    </el-dialog>
    <!-- 用量记录 -->
    <el-dialog  title="用量记录" :visible.sync="dialogFormDosageRecord" :close-on-click-modal="false">
      <div class="dosageRecord">
        <div style="position: absolute;top:20px;left:100px;font:18px/24px '' ;color:#303133;">
          <span style="margin:0 10px;">牧场：{{ dosageRecordTemp.pastureName }}</span>
          <span>部门:{{ dosageRecordTemp.departmentName }}</span>
        </div>
        <el-table
          :key="tableKey"
          v-loading="listLoadingDosageRecord"
          element-loading-text="给我一点时间"
          :data="listDosageRecord"
          border
          fit
          highlight-current-row
          style="width: 100%;"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable"
          @sort-change="tableSort2"
        >
          <el-table-column label="序号" align="center" type="index" width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index + (pageNumDosageRecord-1) * pageSizeDosageRecord + 1 }}</span>
            </template>
          </el-table-column>
  
          <el-table-column label="用量"  prop="dosage" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.dosage }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单价"  prop="price" align="center" min-width="110px" >
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总价"   prop="expense" align="center" min-width="110px">
            <template slot-scope="scope">
              <span>{{ scope.row.expense }}</span>
            </template>
          </el-table-column>
          <el-table-column label="记录人" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.empname }}</span>
            </template>
          </el-table-column>
          <el-table-column label="记录日期" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.date }}</span>
            </template>
          </el-table-column>
        
        </el-table>
        <pagination v-show="totalDosageRecord>=0" :total="totalDosageRecord" :page.sync="getDosageRecordListParm.offset" :limit.sync="getDosageRecordListParm.pagecount" @pagination="get_record_list" />
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormDosageRecord = false">关闭</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 删除 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormDelete" :close-on-click-modal="false" width="40%">
      <el-form ref="deleteTemp" :rules="rules2" :model="deleteTemp" label-position="right" label-width="190px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="请选择要删除数据的日期:" prop="startTime">
              <el-date-picker ref="startTime" v-model="deleteTemp.startTime" :clearable="false" type="date" placeholder="日期" style="width:100%px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :disabled="isokDisable" @click="form_delete_sure()">确认</el-button>
        <el-button @click="dialogFormDelete = false;get_table_data()">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入
require('script-loader!file-saver')
import { GetDataByName, GetDataByNames, PostDataByName, checkButtons, ExecDataByConfig, GetAccount } from '@/api/common'
// import {  DownloadExcel, GetDataByNameXlsx } from '@/api/common'
import waves from '@/directive/waves' // waves directive
// eslint-disable-next-line no-unused-vars
// import { isIntegerZero } from '@/utils/validate.js'
import { parseTime, sortChange, json2excel } from '@/utils/index.js'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { MessageBox } from 'element-ui'
import { getToken } from '@/utils/auth'
import Cookies from 'js-cookie'
export default {
  name: 'GasolineConsum',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      isokDisable: false,
      isElecAdd: [],
      isElecExport: [],
      isElecImport: [],
      isElecModify: [],
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
 
   
      requestParam: {
        name: 'insertElectricity',
        offset: 0,
        pagecount: 0,
        parammaps: {}
      },
      postDataPramas: {

      },
      // 1-2:table&搜索传参
      tableObj: {
        name: 'getGasoline',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          formName: '',  formNumber: '',   formType: '',    pastureName: Cookies.get('pasturename'),  departName: '', date: ''
        }
      },
      downLoadObj: {
        name: 'getGasoline',
        page: 1,
        offset: 1,
        pagecount: 0,
        returntype: 'Map',
        parammaps: {
          formName: '',  formNumber: '',   formType: '',    pastureName: Cookies.get('pasturename'),  departName: '', date: ''
        }
      },
      downLoadList:[],
      // 2-3：下拉框请求后数据加入[]
      useTypes: [{ id: 0, name: '1级表' }, { id: 1, name: '2级表' }, { id: 2, name: '3级表' }],
      getDictByName: [],
      findAllAssetType: [],
     
 
      pastureList: [],
      departList1:[],
      departList2:[],
      findAllEmploye: [],
      // 2-1.请求下拉框接口
      requestParams: [
        { name: 'getDictByName', 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: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }}
      ],
      getDepartParam1: {
        name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }
      },
      getDepartParam2: {
        name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }
      },
      requestFilterParams: {
        name: 'getElecList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: { }
      },

      temp: { 
        pastureName: '',
        departName: '',
        dosage: '',
        price: '',
        expense: '',
        remarks: '',
        empname: '',
        date: parseTime(new Date(), '{y}-{m}-{d}'),
        inputid: this.$store.state.user.employeid,
        departmentId: '',
        pastureId: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '新增',
        DosageRecord: '用量记录',
        delete: '删除'
      },
      dialogFormDosageRecord: false,
      totalDosageRecord: 0,
      listDosageRecord: [],
      listLoadingDosageRecord: false,
      getDosageRecordListParm: {
        name: 'getGasolineList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: { "departmentId": ""}
      },
      dosageRecordTemp: {},
      // 校验规则
      rules1: {
        // endAmount: [{ type: 'number', required: true, validator: (rule, value, callback) => {
        //   if (!value) {
        //     callback(new Error('不能为空'))
        //   }
        //   if (value < 0) {
        //     callback(new Error('必须大于0'))
        //   } else if (value < this.temp.aAmount) {
        //     callback(new Error('必须大于上次值'))
        //   }
        //   setTimeout(() => {
        //     const re = /^\d+$/ // /^[0-9]*[1-9][0-9]*$/
        //     const rsCheck = re.test(value)
        //     if (!rsCheck) {
        //       callback(new Error('请输入整数'))
        //     } else {
        //       callback()
        //     }
        //   }, 0)
        // }, trigger: 'blur' }],
        pastureId: [{ required: true, message: '必填', trigger: 'blur' }],
        departmentId: [{ required: true, message: '必填', trigger: 'blur' }],
        dosage: [{ required: true, message: '必填', trigger: 'blur' }],
        price: [{ required: true, message: '必填', trigger: 'blur' }],
        departmentId: [{ required: true, message: '必填', trigger: 'blur' }],
        expense: [{ required: true, message: '必填', trigger: 'blur' }],
       
         
      },

      rules2: { },
    
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      buttons: [],
      isPercentage: false,
      percentage: 1,
      dialogFormDelete: false,
      deleteTemp: {}
    }
  },

  computed: {
    // 设置请求头
    headers() {
      return {
        // 设置token
        token: getToken()
      }
    },
    uploadData() {
      return {
        name: 'importGasoline',
        importParams: '牧场,部门,当天汽油用量,单价,当天费用,记录人,日期,备注',
        sheetname: '汽油用量'
      }
    },
    // 设置上传地址
    uploadExcelUrl() {
      // process.env.VUE_APP_BASE_API是服务器的路径，也是axios的基本路径
      return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
    }
  },
  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.get_table_data()
  },

  methods: {
    tableSort1(column) {
      sortChange(column, this.list)
    },
    tableSort2(column) {
      sortChange(column, this.listDosageRecord)
    },
    get_auto_buttons() {
      // 新增
      const ElecAdd = 'cost:gasoline:add'
      const isElecAdd = checkButtons(this.$store.state.user.buttons, ElecAdd)
      this.isElecAdd = isElecAdd
      // 导出
      const ElecExport = 'cost:gasoline:export'
      const isElecExport = checkButtons(this.$store.state.user.buttons, ElecExport)
      this.isElecExport = isElecExport
      // 导入
      const ElecImport = 'cost:gasoline:import'
      const isElecImport = checkButtons(this.$store.state.user.buttons, ElecImport)
      this.isElecImport = isElecImport
      // 编辑
      const ElecModify = 'cost:gasoline:modify'
      const isElecModify = checkButtons(this.$store.state.user.buttons, ElecModify)
      this.isElecModify = isElecModify
    },
    isIntegerZero_(rule, value, callback) {
      if (value === '' || value === undefined || value === null) {
        return callback(new Error('输入不可以为空'))
      }
      if (value.length === 0) {
        return callback(new Error('输入不可以为空'))
      }
      setTimeout(() => {
        const re = /^\d+$/ // /^[0-9]*[1-9][0-9]*$/
        const rsCheck = re.test(value)
        if (!rsCheck) {
          callback(new Error('请输入整数'))
        } else {
          callback()
        }
      }, 0)
    },
   
    form_export() {
      this.downLoadObj.parammaps = this.tableObj.parammaps
      GetDataByName(this.downLoadObj).then(response => {
        if (response.data.list !== null) {
          this.downLoadList = response.data.list
        } else {
          this.downLoadList = []
        }

        var excelDatasTabChart1 = [
          {
            tHeader: [
               '牧场', '部门', '当天汽油用量', '单价', '当天费用', '记录人', '日期', '备注'
            ],
            filterVal: ['pastureName', 'departmentName','dosage','price','expense','empname','date','remarks'  ],
            tableDatas: this.downLoadList,
            sheetName: '汽油用量'
          }
        ]
        json2excel(excelDatasTabChart1, '汽油用量', true, 'xlsx')
      })
    },


    

    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    beforeImportExcel(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 2MB!')
      }
      return isLt2M
    },
    handleImportExcelSuccess(res, file) {
      this.get_table_data()
      if (res.msg === 'ok') {
        this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
        if (res.data.err_count > 0) {
          this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })

           import('@/vendor/Export2Excel').then(excel => {
             const list1 = res.data.result
             const tHeader = [
             '牧场', '部门', '当天汽油用量', '单价', '当天费用', '记录人', '日期', '备注', '错误信息'
             ]
             const filterVal = [
             '牧场', '部门', '当天汽油用量', '单价', '当天费用', '记录人', '日期', '备注', 'error_msg'
             ]
             const data1 = this.formatJson(filterVal, list1)
             excel.export_json_to_excel({ header: tHeader, data: data1, filename: '导入报错信息', autoWidth: true, bookType: 'xlsx' })
           })
        }
      } else {
        this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
      }
    },
   
  
   
  
    // 1-1: table&搜索
    get_table_data() {
      if(this.tableObj.parammaps.pastureName == '现代牧业'){
        this.tableObj.parammaps.pastureName =''
      }
      this.listLoading = true
      GetDataByName(this.tableObj).then(response => {
        if (response.data.list == null) {
          this.list = []
           this.total = 0
        } else {
          this.list = response.data.list
          this.pageNum = response.data.pageNum
          this.pageSize = response.data.pageSize
          if (response.data.total) {
            this.total = response.data.total
          }
        }
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    // 2-2：下拉框
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        this.getDictByName = response.data.getDictByName.list
        this.findAllAssetType = response.data.findAllAssetType.list
        this.pastureList = response.data.findAllPasture.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.get_departList1()
        this.get_departList2()
      })
    },
    
    change_pasture1(item) {
      this.getDepartParam1.parammaps.pastureId = this.pastureList.find(obj => obj.name == item).id
      this.tableObj.parammaps.departName = ''
      this.get_departList1()
    },
    get_departList1() {
      GetDataByName(this.getDepartParam1).then(response => {
        this.departList1 = response.data.list
      })
    },


    change_pasture2(item) {
      this.getDepartParam2.parammaps.pastureId = item
      this.temp.departmentId = ''
      this.get_departList2()
    },
    get_departList2() {
      GetDataByName(this.getDepartParam2).then(response => {
        this.departList2 = response.data.list
      })
    },

    form_search() {
      this.listLoading = true
      this.tableObj.offset = 1
      if(this.tableObj.parammaps.date == null){
        this.tableObj.parammaps.date =''
      }

    
      this.get_table_data()
    },


    change_emp(item){
      console.log('记录人', item)
      this.$set(this.temp, 'inputid', item)
      this.$forceUpdate()
    },
   
    form_reset() {

    

      this.temp.pastureName = ''
      this.temp.departName = ''
      this.temp.dosage = ''
      this.temp.price = ''
      this.temp.expense = ''
      this.temp.remarks = ''
      this.temp.date = parseTime(new Date(), '{y}-{m}-{d}')
      this.temp.empname = ''
      this.temp.inputid = this.$store.state.user.employeid
      this.temp.departmentId = ''
      this.temp.pastureId = ''


      
    },
    form_add() {
      this.form_reset()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
       
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
 
    },
   
    
    add_dialog_save() {
      console.log("this.temp=====>",this.temp)
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['temp'].validate(valid => {
        if (valid) {

          var send_data = {
              "name": "insertGasoline",
              "offset": 0,
              "pagecount": 0,
              "parammaps": this.temp
          }
          
          PostDataByName(send_data).then(response => {
  
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },
    // 继续新增
    add_dialog_save_again() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['temp'].validate(valid => {
        if (valid) {
          var send_data = {
              "name": "insertGasoline",
              "offset": 0,
              "pagecount": 0,
              "parammaps": this.temp
          }
          
          PostDataByName(send_data).then(response => {
            console.log('保存发送参数', this.postDataPramas)
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.form_reset()
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },
    form_edit(row) {

      console.log("row=======",row)
      this.temp = Object.assign({}, row) // copy obj
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },
    edit_dialog_save() {
      this.$refs['temp'].validate(valid => {
        if (valid) {
           
          var send_data = {
              "name": "updateGasoline",
              "offset": 0,
              "pagecount": 0,
              "parammaps": this.temp
          }
          
          PostDataByName(send_data).then(response => {
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },
    form_delete() {
      this.deleteTemp = {}
      this.dialogStatus = 'delete'
      this.dialogFormDelete = true
    },
    form_delete_sure() {
      this.$refs['deleteTemp'].validate(valid => {
        if (valid) {
    
          var send_data = {
            "name":"delGasoline","offset":0,"pagecount":0,
            "parammaps":{"date":this.deleteTemp.startTime}
          }
          PostDataByName(send_data).then(response => {
            if (response.msg == 'fail') {
              this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
            } else {
              this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
              this.dialogFormDelete = false
              this.get_table_data()
            }
          })
        }
      })
    },
    see_record(row) {
      this.dialogStatus = 'DosageRecord'
      this.dialogFormDosageRecord = true
      this.dosageRecordTemp = Object(row, {})
      console.log("row=========see_record",row)
      this.get_record_list()
    },
    get_record_list() {
      this.listLoadingDosageRecord = true
      this.getDosageRecordListParm.parammaps.departmentId = this.dosageRecordTemp.departmentId
      GetDataByName(this.getDosageRecordListParm).then(response => {
        this.listDosageRecord = response.data.list
        this.pageNumDosageRecord = response.data.pageNum
        this.pageSizeDosageRecord = response.data.pageSize
        if (response.data.total) {
          this.totalDosageRecord = response.data.total
        }
        setTimeout(() => {
          this.listLoadingDosageRecord = false
        }, 100)
      })
    }

  }
}
</script>
