<template>
  <div>
    <div style="display: flex">
      <div style="width: 50%">
        <el-form :model="dataOldForm" ref="dataForm" label-width="80px">
          <el-form-item label="日期" prop="outTime">
            <el-date-picker
              disabled
              v-model="dataOldForm.outTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="支出金额" prop="outMoney">
            <el-input disabled v-model="dataOldForm.outMoney" placeholder="支出金额"></el-input>
          </el-form-item>
          <el-form-item label="内容" prop="outNr">
            <el-input disabled v-model="dataOldForm.outNr" placeholder="内容"></el-input>
          </el-form-item>
          <el-form-item label="支付方式" prop="outWay">
            <el-select
              disabled
              v-model="dataOldForm.outWay"
              placeholder="选择支付方式"
              style="width: 90%;"
            >
              <el-option
                v-for="item in payList"
                :key="item.dictId"
                :label="item.name"
                :value="item.dictId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="支出类别" prop="outType">
            <el-select
              disabled
              v-model="dataOldForm.outType"
              placeholder="选择支出类别"
              style="width: 90%;"
            >
              <el-option
                v-for="item in expenseList"
                :key="item.dictId"
                :label="item.name"
                :value="item.dictId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="立项归属" prop="outProject">
            <el-select
              disabled
              v-model="dataOldForm.outProject"
              placeholder="选择立项归属"
              style="width: 90%;"
            >
              <el-option
                v-for="item in projectList"
                :key="item.projectId"
                :label="item.project"
                :value="item.projectId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="收款人" prop="outPayee">
            <el-input disabled v-model="dataOldForm.outPayee" placeholder="收款人"></el-input>
          </el-form-item>
          <el-form-item label="地址" prop="outPayeeAddress">
            <el-input disabled v-model="dataOldForm.outPayeeAddress" placeholder="地址"></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="outPayeePhone">
            <el-input disabled v-model="dataOldForm.outPayeePhone" placeholder="电话"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="outRemark">
            <el-input disabled v-model="dataOldForm.outRemark" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div style="width: 50%">
        <el-form :model="dataForm" ref="dataForm" label-width="80px">
          <el-form-item label="日期" prop="outTime">
            <el-date-picker
              disabled
              v-model="dataForm.outTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="支出金额" prop="outMoney">
            <el-input disabled v-model="dataForm.outMoney" placeholder="支出金额"></el-input>
          </el-form-item>
          <el-form-item label="内容" prop="outNr">
            <el-input disabled v-model="dataForm.outNr" placeholder="内容"></el-input>
          </el-form-item>
          <el-form-item label="支付方式" prop="outWay">
            <el-select
              disabled
              v-model="dataForm.outWay"
              placeholder="选择支付方式"
              style="width: 90%;"
            >
              <el-option
                v-for="item in payList"
                :key="item.dictId"
                :label="item.name"
                :value="item.dictId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="支出类别" prop="outType">
            <el-select
              disabled
              v-model="dataForm.outType"
              placeholder="选择支出类别"
              style="width: 90%;"
            >
              <el-option
                v-for="item in expenseList"
                :key="item.dictId"
                :label="item.name"
                :value="item.dictId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="立项归属" prop="outProject">
            <el-select
              disabled
              v-model="dataForm.outProject"
              placeholder="选择立项归属"
              style="width: 90%;"
            >
              <el-option
                v-for="item in projectList"
                :key="item.projectId"
                :label="item.project"
                :value="item.projectId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="收款人" prop="outPayee">
            <el-input disabled v-model="dataForm.outPayee" placeholder="收款人"></el-input>
          </el-form-item>
          <el-form-item label="地址" prop="outPayeeAddress">
            <el-input disabled v-model="dataForm.outPayeeAddress" placeholder="地址"></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="outPayeePhone">
            <el-input disabled v-model="dataForm.outPayeePhone" placeholder="电话"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="outRemark">
            <el-input disabled v-model="dataForm.outRemark" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div style="text-align: center">
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="pass()">通过</el-button>
        <el-button type="danger" @click="noPassed()">不通过</el-button>
      </span>
    </div>
  </div>
</template>

<script>
export default {
  components: {
  },
  data () {
    return {
      id: '',
      // 字典获取的数据数组
      payList: [], // 支付方式
      recipientList: [], // 收款人
      expenseList: [], // 支出类别
      // 所有的立项列表
      projectList: [], // 立项数据
      // 系统用户列表
      sysUserList: [],
      dataForm: { // 明细表新数据
        id: '',
        start: '', // 起始位置日期
        outTime: '',
        outMoney: '',
        outNr: '',
        outWay: '',
        outType: '',
        outProject: '', // 立项归属
        outPayee: '',
        outPayeeAddress: '',
        outPayeePhone: '',
        outRemark: '',
        status: '',
        writeUserId: '', // 填写人id
        approval: ''
      },
      dataOldForm: { // 明细表原始数据
        id: '',
        start: '', // 起始位置日期
        outTime: '',
        outMoney: '',
        outNr: '',
        outWay: '',
        outWayName: '', // 支付方式
        outType: '',
        outTypeName: '', // 支出类别
        outProject: '', // 立项归属
        outPayee: '',
        outPayeeName: '', // 收款人
        outPayeeAddress: '',
        outPayeePhone: '',
        outRemark: '',
        status: '',
        writeUserId: '', // 填写人id
        approval: ''
      }
    }
  },
  methods: {
    getDataList (id, approvalApply) {
      console.log(id)
      this.id = id || 0
      this.approvalApply = approvalApply
      this.visible = true
      this.$nextTick(() => {
        // 获取字典数据
        this.$http.request({
          url: this.$http.adornUrl('/business/businessdict/list'),
          method: 'get'
        }).then(({data}) => {
          // console.log(data);
          if (data && data.code === 0) {
            data.data.forEach((item) => {
              if (item.dictCode === 'pay_type') {
                this.payList = item.children
              } else if (item.dictCode === 'recipient') {
                this.recipientList = item.children
              } else if (item.dictCode === 'expense_type') {
                this.expenseList = item.children
              }
            })
            // 获取立项数据
            this.$http.request({
              url: this.$http.adornUrl('/business/businessproject/allList'),
              method: 'get'
            }).then(({data}) => {
              // console.log(data);
              if (data && data.code === 0) {
                this.projectList = data.page
                // console.log(this.projectList);
                // 系统的所有用户
                this.$http.request({
                  url: this.$http.adornUrl('/sys/user/listNoPage'),
                  method: 'get'
                }).then(({data}) => {
                    // console.log(data);
                  if (data && data.code === 0) {
                    this.sysUserList = data.page
                      // console.log(this.sysUserList);
                      // 获取人员信息
                    this.$http.request({
                      url: this.$http.adornUrl('/business/businessworker/selectAllContainsDeparture'),
                      method: 'get'
                    }).then(({data}) => {
                        // console.log(data);
                      if (data && data.code === 0) {
                        this.ryList = data.page
                      }
                    })
                  }
                })
              }
            })
          }
        })
        this.$http.request({
          url: this.$http.adornUrl('/business/businessapproval/info/' + id),
          method: 'get'
        }).then(({data}) => {
          console.log(data)
          if (data && data.code === 0) {
            this.dataForm = {
              ...JSON.parse(data.businessApproval.approvalData)
            }
            this.dataOldForm = {
              ...JSON.parse(data.businessApproval.approvalOldData)
            }
            console.log(this.dataForm)
          }
        })
      })
    },
    pass () {
      this.$http.request({
        url: this.$http.adornUrl('/business/businessapproval/pass'),
        method: 'post',
        body: this.$http.adornData({
          'id': this.id,
          'approvalData': JSON.stringify(this.dataForm),
          'approvalType': 6
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.$message('操作成功')
        }
      })
    },
    noPassed () {
      this.$http.request({
        url: this.$http.adornUrl('/business/businessapproval/noPass'),
        method: 'post',
        body: this.$http.adornData({
          'id': this.id,
          'approvalId': this.dataForm.id,
          'approvalType': 6
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.$message('操作成功')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
