<template>
  <el-dialog
    :title="!dataForm.userId ? '人员新增' : '人员修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="工人姓名" prop="name">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.name" placeholder="工人姓名"></el-input>
    </el-form-item>
    <el-form-item label="工人性别" prop="sex">
      <el-select :disabled="dataForm.approval===1" v-model="dataForm.sex" placeholder="请选择">
        <el-option
          v-for="item in sexs"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="出生日期" prop="birthday">
      <el-date-picker
        :disabled="dataForm.approval===1"
        v-model="dataForm.birthday"
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="选择日期" />
    </el-form-item>
      <el-form-item label="文化程度" prop="education">
        <el-input :disabled="dataForm.approval===1" v-model="dataForm.education" placeholder="文化程度"></el-input>
      </el-form-item>
      <el-form-item label="现住址" prop="addr">
        <el-input :disabled="dataForm.approval===1" v-model="dataForm.addr" placeholder="现住址"></el-input>
      </el-form-item>
    <el-form-item label="户籍" prop="register">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.register" placeholder="户籍"></el-input>
    </el-form-item>

    <el-form-item label="本人电话" prop="phone">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.phone" placeholder="本人电话"></el-input>
    </el-form-item>


    <el-form-item label="身高" prop="height">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.height" placeholder="身高"></el-input>
    </el-form-item>
    <el-form-item label="体重" prop="weight">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.weight" placeholder="体重"></el-input>
    </el-form-item>
      <el-form-item label="位置" prop="positionId">
        <el-select
          :disabled="dataForm.approval===1"
          v-model="dataForm.positionId"
          placeholder="选择位置"
        >
          <el-option
            v-for="item in positionList"
            :key="item.dictId"
            :label="item.name"
            :value="item.dictId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="职位" prop="workId">
        <el-select
          :disabled="dataForm.approval===1"
          v-model="dataForm.workId"
          placeholder="选择职位"
        >
          <el-option
            v-for="item in workList"
            :key="item.dictId"
            :label="item.name"
            :value="item.dictId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item  label="成本折算系数" prop="cbzsxs">
        <el-input :disabled="dataForm.approval===1" v-model="dataForm.cbzsxs" placeholder="成本折算系数"></el-input>
      </el-form-item>

      <el-form-item label="应急联系人" prop="urgentName">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.urgentName" placeholder="应急联系人"></el-input>
    </el-form-item>
    <el-form-item label="与本人关系" prop="urgentRelation">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.urgentRelation" placeholder="与本人关系"></el-input>
    </el-form-item>
    <el-form-item label="紧急联系人电话" prop="urgentPhone">
      <el-input :disabled="dataForm.approval===1" v-model="dataForm.urgentPhone" placeholder="紧急联系人电话"></el-input>
    </el-form-item>
    <el-form-item label="本人照片" prop="image">
      <el-upload
        :disabled="dataForm.approval===1"
        class="avatar-uploader"
        :headers="headers"
        accept="image/jpeg,image/jpg,image/png"
        :action="imageUploaderUrl"
        :show-file-list="false"
        :on-success="handleImageSuccess">
        <img v-if="imageUrl" :src="imageUrl" class="avatar">
        <img v-else-if="isUpdate && imageBase64" :src="imageBase64">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item label="身份证正面" prop="imageFront">
      <el-upload
        :disabled="dataForm.approval===1"
        class="avatar-uploader"
        :headers="headers"
        accept="image/jpeg,image/jpg,image/png"
        :action="imageCardUploaderUrl"
        :show-file-list="false"
        :on-success="handleImageFrontSuccess">

        <img v-if="imageFrontUrl" :src="imageFrontUrl" class="avatar">
        <img v-else-if="isUpdate && imageFrontBase64" :src="imageFrontBase64">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item label="身份证背面" prop="imageBack">
      <el-upload
        :disabled="dataForm.approval===1"
        class="avatar-uploader"
        :headers="headers"
        accept="image/jpeg,image/jpg,image/png"
        :action="imageCardUploaderUrl"
        :show-file-list="false"
        :on-success="handleImageBackSuccess">

        <img v-if="imageBackUrl" :src="imageBackUrl" class="avatar">
        <img v-else-if="isUpdate && imageBackBase64" :src="imageBackBase64">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item label="出勤记录" v-if="isUpdate">
        <el-table
          :data="tableData"
          stripe
          style="width: 100%">
          <el-table-column label="序号" width="90" align="center">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column
            prop="dateDay"
            label="年月"
            width="180">
            <template slot-scope="scope">
              <el-date-picker
                @change="preventSelectDate($event,scope)"
                style="width: 100%"
                v-model="scope.row.dateDay"
                type="date"
                value-format="yyyy-MM"
                placeholder="选择日期" />
            </template>
          </el-table-column>
          <el-table-column
            prop="workDay"
            label="出勤天数"
            width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.workDay"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="remark"
            label="备注">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
    <el-form-item label="工资账目" v-if="isUpdate">
      <el-button size="mini" style="margin-left: 88% " type="primary" @click="visibleSalary = true; salaryId=''; salaryObj={}">
        新增
      </el-button>
      <template>
        <div  v-for="(item, key) in salaryDict" :key="key">
          <hr style="border: 2px solid red">

          <span>{{item.year}}年</span>
          <el-button size="mini" style="margin-left: 78%" type="warning" @click="visibleSalary = true; salaryId=key; salaryObj=salaryDict[key]">修改</el-button>

          <div>入职时间{{item.startTime}} &nbsp;&nbsp;&nbsp;&nbsp; 离职时间{{item.startTime}}</div>
          <div>1.{{item.borrowingDetails?item.borrowingDetails:'暂无'}}</div>
          <div>2.{{item.gzjsfs?item.gzjsfs:'暂无'}}</div>
          <div>3.{{item.gzjqjsjjd?item.gzjqjsjjd:'暂无'}}</div>
          <div>4.{{item.remark?item.remark:'暂无'}}</div>
          <hr style="border: 2px solid red">
        </div>
      </template>
    </el-form-item>
    </el-form>
    <el-dialog :title="!salaryId? '工资账目新增' : '工资账目修改'" :visible.sync="visibleSalary" append-to-body>
          <el-form :model="salaryObj" ref="dataFormSalary" :rules="dataRuleSalary">
            <el-form-item label="年份" prop="year">
              <el-date-picker
                :disabled="salaryObj.approval===1"
                v-model="salaryObj.year"
                type="date"
                value-format="yyyy"
                placeholder=“选择日期” />
            </el-form-item>
            <el-form-item label="入职时间" prop="year">
              <el-date-picker
                :disabled="salaryObj.approval===1"
                v-model="salaryObj.startTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder=“选择日期” />
            </el-form-item>
            <el-form-item label="离职时间" prop="year">
              <el-date-picker
                :disabled="salaryObj.approval===1"
                v-model="salaryObj.endTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder=“选择日期” />
            </el-form-item>
            <el-form-item label="借款明细" prop="borrowingDetails" >
              <el-input :disabled="salaryObj.approval===1" v-model="salaryObj.borrowingDetails"  placeholder="借款明细" ></el-input>
            </el-form-item>
            <el-form-item label="工资标准计算方式" prop="gzjsfs">
              <el-input :disabled="salaryObj.approval===1" v-model="salaryObj.gzjsfs" placeholder="工资标准计算方式"></el-input>
            </el-form-item>
            <el-form-item label="工资结清及时间结点" prop="gzjqjsjjd">
              <el-input :disabled="salaryObj.approval===1" v-model="salaryObj.gzjqjsjjd" placeholder="工资结清及时间结点"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input :disabled="salaryObj.approval===1" v-model="salaryObj.remark" placeholder="备注"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="visibleSalary = false">取 消</el-button>
            <el-button type="primary" @click="dataFormSubmitSalary()">确 定</el-button>
          </div>
    </el-dialog>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {cloneDeep} from 'lodash'

  export default {
    data () {
      return {
        visible: false,
        visibleSalary: false,
        tableData: [], // 出勤记录
        otableData: [], // 用作判断是否有重复的日期
        ptableData: [], // 用作是否修改出勤记录
        dataForm: {
          userId: 0,
          name: '',
          sex: '',
          birthday: '',
          register: '',
          card: '',
          phone: '',
          addr: '',
          education: '',
          height: '',
          weight: '',
          urgentName: '',
          urgentRelation: '',
          urgentPhone: '',
          typeId: '',
          typeName: '',
          cbzsxs: '',
          positionId: '',
          positionName: '',
          workId: '',
          workName: '',
          status: '',
          inductionTime: '',
          quitTime: '',
          image: '',
          imageFront: '',
          imageBack: '',
          bankImage: '',
          bankName: '',
          bankCard: '',
          bankRelation: '',
          balance: '',
          settleTime: '',
          createTime: '',
          updateTime: '',
          createName: '',
          approval: ''
        },
        pdataForm: {}, // 用作是否修改人员信息
        dataFormDict: {}, // 用作是否修改人员信息
        dataRule: {
          name: [
            { required: true, message: '工人姓名不能为空', trigger: 'blur' }
          ],
          sex: [
            { required: true, message: '工人性别不能为空', trigger: 'blur' }
          ],
          birthday: [
            { required: true, message: '出生日期不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '电话号不能为空', trigger: 'blur' }
          ],
          typeName: [
            { required: true, message: '类别名称（内部、外雇等）不能为空', trigger: 'blur' }
          ],
          positionName: [
            { required: true, message: '职位名称不能为空', trigger: 'blur' }
          ],
          workName: [
            { required: true, message: '工种名称不能为空', trigger: 'blur' }
          ]
        },
        workList: [],
        positionList: [],
        imageUploaderUrl: '',
        imageUrl: '',
        imageCardUploaderUrl: '',
        imageFrontUrl: '',
        imageBackUrl: '',
        headers: {},
        sexs: [{value: 0, label: '女'}, {value: 1, label: '男'}],
        isUpdate: false,
        imageBase64: '',
        imageFrontBase64: '',
        imageBackBase64: '',

        // 工资账目
        salaryId: '',
        salaryDict: {}, // 工资账目
        salaryObj: {},
        psalaryDict: {}, // 用于比较是否修改
        dataRuleSalary: {
          // name: [
          //   { required: true, message: '工人姓名不能为空', trigger: 'blur' }
          // ]
        }
      }
    },
    methods: {
      init (id, workList, positionList, domain, token) {
        this.isUpdate = false
        this.tableData = []
        this.imageUrl = ''
        this.imageBackUrl = ''
        this.imageFrontUrl = ''
        this.workList = workList
        this.positionList = positionList
        this.imageUploaderUrl = domain + 'sys/oss/upload?categoryType=photo'
        this.imageCardUploaderUrl = domain + 'sys/oss/upload?categoryType=card'
        this.headers.token = token
        this.dataForm.userId = id || 0
        this.visible = true
        this.dataForm.approval = 0
        this.salaryDict = {}
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.userId) {
            this.isUpdate = true
            this.$http({
              url: this.$http.adornUrl(`/business/businessworker/info/${this.dataForm.userId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.data.name
                this.dataForm.sex = data.data.sex
                this.dataForm.birthday = data.data.birthday
                this.dataForm.register = data.data.register
                this.dataForm.card = data.data.card
                this.dataForm.phone = data.data.phone
                this.dataForm.addr = data.data.addr
                this.dataForm.education = data.data.education
                this.dataForm.height = data.data.height
                this.dataForm.weight = data.data.weight
                this.dataForm.urgentName = data.data.urgentName
                this.dataForm.urgentRelation = data.data.urgentRelation
                this.dataForm.urgentPhone = data.data.urgentPhone
                this.dataForm.typeId = data.data.typeId
                this.dataForm.typeName = data.data.typeName
                this.dataForm.cbzsxs = data.data.cbzsxs
                this.dataForm.positionId = data.data.positionId
                this.dataForm.positionName = data.data.positionName
                this.dataForm.workId = data.data.workId
                this.dataForm.workName = data.data.workName
                this.dataForm.status = data.data.status
                this.dataForm.inductionTime = data.data.inductionTime
                this.dataForm.quitTime = data.data.quitTime
                this.dataForm.image = data.data.image
                this.dataForm.imageFront = data.data.imageFront
                this.dataForm.imageBack = data.data.imageBack
                this.dataForm.bankImage = data.data.bankImage
                this.dataForm.bankName = data.data.bankName
                this.dataForm.bankCard = data.data.bankCard
                this.dataForm.bankRelation = data.data.bankRelation
                this.dataForm.balance = data.data.balance
                this.dataForm.settleTime = data.data.settleTime
                this.dataForm.createTime = data.data.createTime
                this.dataForm.updateTime = data.data.updateTime
                this.dataForm.createName = data.data.createName
                this.dataForm.approval = data.data.approval

                // 获取图片base64
                this.$http.request({
                  url: this.$http.adornUrl('/sys/oss/list?filePath=' + this.dataForm.image),
                  method: 'get'
                }).then(({data}) => {
                  this.imageBase64 = data.replace(/[\r\n]/g, '')
                })
                this.$http.request({
                  url: this.$http.adornUrl('/sys/oss/list?filePath=' + this.dataForm.imageFront),
                  method: 'get'
                }).then(({data}) => {
                  this.imageFrontBase64 = data.replace(/[\r\n]/g, '')
                })
                this.$http.request({
                  url: this.$http.adornUrl('/sys/oss/list?filePath=' + this.dataForm.imageBack),
                  method: 'get'
                }).then(({data}) => {
                  this.imageBackBase64 = data.replace(/[\r\n]/g, '')
                })

                this.pdataForm = cloneDeep(this.dataForm)
              }
            })

            // 获取出勤记录
            this.$http({
              url: this.$http.adornUrl('/business/businessworkercq/list?userId=' + id),
              method: 'get'
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.tableData = data.page
                let count = 12 - this.tableData.length
                for (let i = 0; i < count; i++) {
                  this.tableData.push({dateDay: '', workDay: '', remark: ''})
                }
                this.otableData = cloneDeep(this.tableData)
                this.tableData.forEach((item) => {
                  this.ptableData.unshift(JSON.stringify(item))
                  this.dataFormDict[item.id] = cloneDeep(item)
                })
              }
            })

            // 获取工资账目
            this.$http({
              url: this.$http.adornUrl('/business/businessworkersalary/list?userId=' + id),
              method: 'get'
            }).then(({data}) => {
              if (data && data.code === 0) {
                data.page.list.forEach((item) => {
                  this.salaryDict[item.id] = item
                })

                this.psalaryDict = cloneDeep(this.salaryDict)
              }
            })
          }
        })
      },

      // 表单提交
      dataFormSubmit () {
        let d = new Date()
        let birthdays = new Date(this.dataForm.birthday.replace(/-/g, '/'))
        let age = d.getFullYear() - birthdays.getFullYear() - (d.getMonth() < birthdays.getMonth() || (d.getMonth() === birthdays.getMonth() && d.getDate() < birthdays.getDate()) ? 1 : 0)

        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.userId) {
              this.$http({
                url: this.$http.adornUrl(`/business/businessworker/save`),
                method: 'post',
                data: this.$http.adornData({
                  'userId': this.dataForm.userId || undefined,
                  'name': this.dataForm.name,
                  'sex': this.dataForm.sex,
                  'birthday': this.dataForm.birthday,
                  'register': this.dataForm.register,
                  'card': this.dataForm.card,
                  'phone': this.dataForm.phone,
                  'addr': this.dataForm.addr,
                  'education': this.dataForm.education,
                  'height': this.dataForm.height,
                  'weight': this.dataForm.weight,
                  'urgentName': this.dataForm.urgentName,
                  'urgentRelation': this.dataForm.urgentRelation,
                  'urgentPhone': this.dataForm.urgentPhone,
                  'typeId': this.dataForm.typeId,
                  'typeName': this.dataForm.typeName,
                  'cbzsxs': this.dataForm.cbzsxs,
                  'positionId': this.dataForm.positionId,
                  'positionName': this.dataForm.positionName,
                  'workId': this.dataForm.workId,
                  'workName': this.dataForm.workName,
                  'status': '0',
                  'inductionTime': this.dataForm.inductionTime,
                  'quitTime': this.dataForm.quitTime,
                  'image': this.dataForm.image,
                  'imageFront': this.dataForm.imageFront,
                  'imageBack': this.dataForm.imageBack,
                  'bankImage': this.dataForm.bankImage,
                  'bankName': this.dataForm.bankName,
                  'bankCard': this.dataForm.bankCard,
                  'bankRelation': this.dataForm.bankRelation,
                  'balance': this.dataForm.balance,
                  'settleTime': this.dataForm.settleTime,
                  'createTime': this.dataForm.createTime,
                  'updateTime': this.dataForm.updateTime,
                  'createName': this.dataForm.createName,
                  'age': age,
                  'approval': '0',
                  'isFp': this.dataForm.positionId in [151, 152] ? '0' : '1'
                })
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            } else {
              // 人员是否修改
              if (JSON.stringify(this.pdataForm) !== JSON.stringify(this.dataForm)) {
                this.$http({
                  url: this.$http.adornUrl(`/business/businessapproval/save`),
                  method: 'post',
                  data: this.$http.adornData({
                    'approvalId': this.dataForm.userId,
                    'approvalName': this.dataForm.name,
                    'approvalOldData': JSON.stringify(this.pdataForm),
                    'approvalData': JSON.stringify(this.dataForm),
                    'approvalType': '0',
                    'approvalSuccess': '1'
                  })
                }).then(({data}) => {
                  if (data && data.code === 0) {
                    this.$message({
                      message: '操作成功',
                      type: 'success',
                      duration: 1500
                    })
                  } else {
                    this.$message.error(data.msg)
                  }
                })
              }

              // 出勤记录是否修改
              this.tableData.forEach((tdata) => {
                // 出勤记录是否修改 不在原始列表中就是修改
                if (this.ptableData.indexOf(JSON.stringify(tdata)) === -1) {
                  // 修改还是添加  如果有id就是修改 否则就是添加
                  if (tdata.userId) {
                    this.$http({
                      url: this.$http.adornUrl(`/business/businessapproval/save`),
                      method: 'post',
                      data: this.$http.adornData({
                        'approvalId': tdata.id,
                        'approvalFatherId': this.dataForm.userId,
                        'approvalName': '出勤记录',
                        'approvalOldData': JSON.stringify(this.dataFormDict[tdata.id]),
                        'approvalData': JSON.stringify(tdata),
                        'approvalType': '1',
                        'approvalSuccess': '1'
                      })
                    }).then(({data}) => {
                      if (data && data.code === 0) {
                        this.$message({
                          message: '操作成功',
                          type: 'success',
                          duration: 1500

                        })
                      } else {
                        this.$message.error(data.msg)
                      }
                    })
                  } else {
                    this.$http({
                      url: this.$http.adornUrl(`/business/businessworkercq/save`),
                      method: 'post',
                      data: this.$http.adornData({
                        'userId': this.dataForm.userId,
                        'dateDay': tdata.dateDay,
                        'workDay': tdata.workDay,
                        'remark': tdata.remark,
                        'approval': '0'
                      })
                    }).then(({data}) => {
                      if (data && data.code === 0) {
                        this.$message({
                          message: '操作成功',
                          type: 'success',
                          duration: 1500
                        })
                      } else {
                        this.$message.error(data.msg)
                      }
                    })
                  }
                }
              })

              this.visible = false
              this.$emit('refreshDataList')
            }
          }
        })
      },
      // 账目薪资提交
      dataFormSubmitSalary () {
        this.$refs['dataFormSalary'].validate((valid) => {
          if (valid) {
            if (!this.salaryObj.id) {
              this.$http({
                url: this.$http.adornUrl(`/business/businessworkersalary/save`),
                method: 'post',
                data: this.$http.adornData({
                  'id': this.salaryObj.id || undefined,
                  'userId': this.dataForm.userId,
                  'year': this.salaryObj.year,
                  'startTime': this.salaryObj.startTime,
                  'endTime': this.salaryObj.endTime,
                  'borrowingDetails': this.salaryObj.borrowingDetails,
                  'gzjsfs': this.salaryObj.gzjsfs,
                  'gzjqjsjjd': this.salaryObj.gzjqjsjjd,
                  'remark': this.salaryObj.remark,
                  'createTime': this.salaryObj.createTime,
                  'updateTime': this.salaryObj.updateTime,
                  'createName': this.salaryObj.createName,
                  'deleteTime': this.salaryObj.deleteTime,
                  'approval': '0',
                  'status': '0'
                })
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visibleSalary = false
                      // 获取工资账目
                      this.$http({
                        url: this.$http.adornUrl('/business/businessworkersalary/list?userId=' + this.dataForm.userId),
                        method: 'get'
                      }).then(({data}) => {
                        if (data && data.code === 0) {
                          this.salaryDict = {}
                          data.page.list.forEach((item) => {
                            this.salaryDict[item.id] = item
                          })

                          this.psalaryDict = cloneDeep(this.salaryDict)
                        }
                      })
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            } else {
              // 账目薪资修改
              if (JSON.stringify(this.salaryObj) !== JSON.stringify(this.psalaryDict[this.salaryObj.id])) {
                this.$http({
                  url: this.$http.adornUrl(`/business/businessapproval/save`),
                  method: 'post',
                  data: this.$http.adornData({
                    'approvalId': this.dataForm.userId,
                    'approvalFatherId': this.dataForm.userId,
                    'approvalName': '工资账目',
                    'approvalOldData': JSON.stringify(this.psalaryDict[this.salaryObj.id]),
                    'approvalData': JSON.stringify(this.salaryObj),
                    'approvalType': '2',
                    'approvalSuccess': '1'
                  })
                }).then(({data}) => {
                  if (data && data.code === 0) {
                    this.$message({
                      message: '操作成功',
                      type: 'success',
                      duration: 1500
                    })
                  } else {
                    this.$message.error(data.msg)
                  }
                })
              }

              this.visibleSalary = false
            }
          }
        })
      },

      // 图片上传成功的回调
      handleImageSuccess (res, file) {
        if (res && res.code === 0) {
          this.imageUrl = URL.createObjectURL(file.raw)
          this.dataForm.image = res.data
        }
      },
      handleImageFrontSuccess (res, file) {
        if (res && res.code === 0) {
          this.imageFrontUrl = URL.createObjectURL(file.raw)
          this.dataForm.imageFront = res.data
        }
      },
      handleImageBackSuccess (res, file) {
        if (res && res.code === 0) {
          this.imageBackUrl = URL.createObjectURL(file.raw)
          this.dataForm.imageBack = res.data
        }
      },

      preventSelectDate (val, row) {
        let flag = true
        this.otableData.forEach((data) => {
          if (row.row.dateDay === data.dateDay) {
            this.$message.error('选择的日期已存在，请重新选择')
            this.tableData = cloneDeep(this.otableData)
            flag = false
          }
        })
        if (flag) {
          this.otableData = cloneDeep(this.tableData)
        }
      }
    }
  }
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

</style>
