<template>
  <template-page
    v-if="pageShow"
    ref="pageRef"
    :get-list="getList"
    :exportList="exportList"
    :table-attributes="tableAttributes"
    :table-events="tableEvents"
    :options-evens-group="optionsEvensGroup"
    :moreParameters="moreParameters"
    :column-parsing="columnParsing"
    :operation="operation()"
    key="pageType"
  >
    <div class="cartographer_big">
      <el-dialog title="工作联络函" width="100%" :modal="false" :visible.sync="formDialog" :before-close="handleClose">
        <zj-page-container>
          <zj-page-fill>
            <div style="box-sizing: border-box; padding: 20px 20px 0 20px">
              <zj-form-container
                v-if="formDialog"
                ref="formRef"
                :form-data="formData"
                :form-attributes="{ size: 'mini' }"
              >
                <zj-form-module title="基本信息" label-width="100px" :form-data="formData" :form-items="formItems">
                </zj-form-module>
                <template v-if="[-1].includes(openType) && formData.leLetterItems && formData.leLetterItems.length">
                  <template v-for="(item, index) in formData.leLetterItems">
                    <zj-form-module
                      :key="`${index}1`"
                      :title="`网点审核${index + 1}`"
                      label-width="100px"
                      :form-data="item"
                      :form-items="formItems1"
                    >
                    </zj-form-module>
                    <zj-form-module
                      :key="`${index}2`"
                      :title="`中心审核${index + 1}`"
                      label-width="100px"
                      :form-data="item"
                      :form-items="formItems2"
                    >
                    </zj-form-module>
                  </template>
                </template>
              </zj-form-container>
              <zj-form-container
                v-if="formDialog && [1, 2].includes(openType)"
                ref="formRef1"
                :form-data="formData1"
                :form-attributes="{ size: 'mini' }"
              >
                <zj-form-module title="网点审核" label-width="100px" :form-data="formData1" :form-items="formItems1">
                </zj-form-module>
              </zj-form-container>
              <zj-form-container
                v-if="formDialog && [2].includes(openType)"
                ref="formRef2"
                :form-data="formData2"
                :form-attributes="{ size: 'mini' }"
              >
                <zj-form-module title="中心审核" label-width="100px" :form-data="formData2" :form-items="formItems2">
                </zj-form-module>
              </zj-form-container>
            </div>
          </zj-page-fill>
          <div style="text-align: right; box-sizing: border-box; padding: 16px 20px">
            <el-button size="mini" @click="handleClose">取消</el-button>
            <el-button v-if="openType == 0" size="mini" type="primary" @click="save()">保存</el-button>
            <el-button v-if="openType == 0" size="mini" type="primary" @click="save('SEND')">发送</el-button>
            <el-button v-if="openType == 1" size="mini" type="primary" @click="networkAudit">网点申诉</el-button>
            <el-button v-if="openType == 2" size="mini" type="primary" @click="centralAudit">中心审核</el-button>
          </div>
        </zj-page-container>
      </el-dialog>
    </div>
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import operation_mixin from '@/components/template/operation_mixin.js'
import {
  letterProcessList,
  letterProcessListExport,
  letterProcessDetailLetter,
  letterProcessAddLetter,
  letterProcessUpdateLetter,
  letterProcessDelLetter,
  letterProcessAppeal, // 网点申诉
  letterProcessCancel, // 作废
  letterProcessExamine, // 中心批复
  letterProcessReject, // 驳回
  letterProcessSend // 发送
} from '@/api/workContactLetterPage.js'
import { required } from '@/components/template/rules_verify.js'
import { getWebsit } from '@/api/customerManagement.js'
import { letterManagerList } from '@/api/departmentSetting.js'
import { letterManagerListProject } from '@/api/assessmentItemSetting.js'
import { listPageV2 } from '@/api/workOrder/orderType'
import { getClassifyList } from '@/api/goods'
import ImageUpload from '@/components/file-upload'
import { orderBaseDetail } from '@/api/workOrderPool.js'
export default {
  components: { TemplatePage, ImageUpload },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      pageType: 'list',
      pageShow: true,
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      // 勾选选中行
      recordSelected: [],
      /** 表单变量 */
      formDialog: false,
      formData: {
        belongCompany: '',
        belongCompanyCode: '',
        companyWechatId: '',
        companyWechatName: '',
        context: '',
        dapartment: '',
        dapartmentId: '',
        examineFration: 0,
        examineName: '',
        examinePrice: 0,
        examineStatus: '',
        examineTime: '',
        fraction: 0,
        leLetterId: '',
        leLetterItems: [],
        letteWebsitNum: 0,
        letterNum: 0,
        letterNumber: '',
        mainId: '',
        mainName: '',
        orderCreateTime: '',
        orderId: '',
        orderSmallType: '',
        orderSmallTypeText: '',
        price: 0,
        projectId: '',
        projectName: '',
        projectReg: '',
        projectText: '',
        remark: '',
        sendTime: '',
        status: '',
        type: '',
        websitId: '',
        websitName: '',
        fileUrl: []
      },
      websitList: [],
      managerList: [],
      managerListProject: [],
      orderSmallTypeData: [],
      classifyList: [],
      openType: 0,
      formData1: {
        appealRemark: '',
        appealUrl: [],
        createBy: '',
        createTime: '',
        examineFration: 0,
        examineName: '',
        examinePrice: 0,
        examineRemark: '',
        examineStatus: '',
        examineTime: '',
        leLetterId: '',
        leLetterItemId: '',
        websitAppeal: ''
      },
      formData2: {
        appealRemark: '',
        appealUrl: '',
        createBy: '',
        createTime: '',
        examineFration: 0,
        examineName: '',
        examinePrice: 0,
        examineRemark: '',
        examineStatus: '',
        examineTime: '',
        leLetterId: '',
        leLetterItemId: '',
        websitAppeal: ''
      }
    }
  },
  computed: {
    // 事件组合
    optionsEvensGroup() {
      return [
        [
          [
            this.optionsEvensAuth('add', {
              click: this.openForm
            })
          ]
        ],
        [
          [
            this.optionsEvensAuth('void', {
              click: () => {
                if (this.recordSelected.length === 0) {
                  this.$message.warning('请勾选数据')
                  return
                }
                this.$confirm(' 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                })
                  .then(() => {
                    letterProcessCancel({
                      ids: this.recordSelected.map(item => item.leLetterId).join(',')
                    })
                      .then(res => {
                        this.$refs?.pageRef?.refreshList()
                        this.recordSelected = []
                        this.$message({
                          message: '操作成功',
                          type: 'success'
                        })
                      })
                      .catch(err => {
                        this.$message.error('操作失败')
                      })
                  })
                  .catch(() => {})
              }
            })
          ]
        ],
        [
          [
            this.optionsEvensAuth('send', {
              click: () => {
                if (this.recordSelected.length === 0) {
                  this.$message.warning('请勾选数据')
                  return
                }
                this.$confirm(' 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                })
                  .then(() => {
                    letterProcessSend({
                      ids: this.recordSelected.map(item => item.leLetterId).join(',')
                    })
                      .then(res => {
                        this.$refs?.pageRef?.refreshList()
                        this.recordSelected = []
                        this.$message({
                          message: '操作成功',
                          type: 'success'
                        })
                      })
                      .catch(err => {
                        this.$message.error('操作失败')
                      })
                  })
                  .catch(() => {})
              }
            })
          ]
        ],
        [
          [
            this.optionsEvensAuth('oneCaseRejected', {
              click: () => {
                if (this.recordSelected.length === 0) {
                  this.$message.warning('请勾选数据')
                  return
                }
                this.$confirm(' 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                })
                  .then(() => {
                    letterProcessReject({
                      ids: this.recordSelected.map(item => item.leLetterId).join(',')
                    })
                      .then(res => {
                        this.$refs?.pageRef?.refreshList()
                        this.recordSelected = []
                        this.$message({
                          message: '操作成功',
                          type: 'success'
                        })
                      })
                      .catch(err => {
                        this.$message.error('操作失败')
                      })
                  })
                  .catch(() => {})
              }
            })
          ]
        ]
      ]
    },
    // 更多参数
    moreParameters() {
      return []
    },
    formItems() {
      return [
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '联络函编号',
            prop: 'letterNumber',
            rules: []
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '下发时间',
            prop: 'sendTime',
            rules: []
          }
        },
        {
          name: 'el-radio',
          options: [
            { label: '考核函', value: '考核函' },
            { label: '奖励函', value: '奖励函' },
            { label: '整改函', value: '整改函' }
          ],
          md: 6,
          attributes: {
            disabled: this.openType != 0,
            placeholder: '请输入'
          },
          formItemAttributes: {
            label: '函件类型',
            prop: 'type',
            rules: [...required]
          }
        },
        {
          name: 'el-select',
          options: this.managerList.map(item => ({
            data: item,
            label: item.dapartment,
            value: item.id
          })),
          echoInsertion: true,
          md: 6,
          attributes: {
            disabled: this.openType != 0,
            placeholder: '请选择',
            clearable: true,
            filterable: true
          },
          formItemAttributes: {
            label: '来源科室',
            prop: 'dapartmentId',
            propName: 'dapartment',
            rules: [...required]
          },
          events: {
            change: val => {
              if (val) {
                this.formData.dapartment = this.managerList?.find(item => item.id === val)?.dapartment
              } else {
                this.formData.dapartment = ''
              }
            }
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: this.openType != 0
          },
          formItemAttributes: {
            label: '工单编号',
            prop: 'orderId',
            rules: [...required]
          },
          events: {
            input: val => {
              if (val) {
                orderBaseDetail({
                  orderBaseId: val,
                  returnErr: true
                })
                  .then(res => {
                    if (res.data.orderProducts.length == 1) {
                      this.formData.mainId = res.data.orderProducts?.[0]?.mainId || ''
                      this.formData.mainName = res.data.orderProducts?.[0]?.mainName || ''
                    }
                    this.formData.orderSmallType = res.data?.orderSmallType || ''
                    this.formData.orderSmallTypeText = res.data?.orderSmallTypeText || ''
                    this.formData.orderCreateTime = res.data?.createTime || ''
                    this.formData.websitId = res.data?.websitId || ''
                    this.formData.websitName = res.data?.websitName || ''
                  })
                  .catch(err => {
                    this.formData.mainId = ''
                    this.formData.mainName = ''
                    this.formData.orderSmallType = ''
                    this.formData.orderSmallTypeText = ''
                    this.formData.orderCreateTime = ''
                    this.formData.websitId = ''
                    this.formData.websitName = ''
                  })
              }
            }
          }
        },
        {
          name: 'el-select',
          options: this.classifyList.map(item => ({
            data: item,
            label: item.name,
            value: item.categoryId
          })),
          echoInsertion: true,
          md: 6,
          attributes: {
            disabled: this.openType != 0,
            placeholder: '请选择',
            clearable: true,
            filterable: true
          },
          formItemAttributes: {
            label: '产品大类',
            prop: 'mainId',
            propName: 'mainName',
            rules: [...required]
          },
          events: {
            change: val => {
              if (val) {
                this.formData.mainName = this.classifyList?.find(item => item.categoryId === val)?.name
              } else {
                this.formData.mainName = ''
              }
            }
          }
        },
        {
          name: 'el-select',
          md: 6,
          options: this.orderSmallTypeData,
          attributes: {
            disabled: this.openType != 0,
            placeholder: '请选择',
            clearable: true,
            filterable: true
          },
          formItemAttributes: {
            label: '工单类型',
            prop: 'orderSmallType',
            rules: [...required]
          },
          events: {
            change: val => {
              if (val) {
                this.orderInfo.orderSmallTypeText = this.orderSmallTypeData.find(item => item.value == val).label
              } else {
                this.orderInfo.orderSmallTypeText = ''
              }
            }
          }
        },
        {
          md: 6,
          name: 'el-date-picker',
          attributes: {
            disabled: this.openType != 0,
            style: { width: '100%' },
            type: 'datetime',
            'value-format': 'yyyy-MM-dd HH:mm:ss'
          },
          formItemAttributes: {
            label: '工单创建日期',
            prop: 'orderCreateTime',
            rules: []
          }
        },
        {
          name: 'el-select',
          options: this.websitList.map(item => ({
            data: item,
            label: item.name,
            value: item.websitId
          })),
          echoInsertion: true,
          md: 12,
          attributes: {
            disabled: this.openType != 0,
            placeholder: '请选择',
            clearable: true,
            filterable: true
          },
          formItemAttributes: {
            label: '接收网点',
            prop: 'websitId',
            propName: 'websitName',
            rules: [...required]
          },
          events: {
            change: val => {
              if (val) {
                this.formData.websitName = this.websitList?.find(item => item.websitId === val)?.name
              } else {
                this.formData.websitName = ''
              }
            }
          }
        },
        {
          name: 'el-select',
          options: this.managerListProject.map(item => ({
            data: item,
            label: item.projectName,
            value: item.projectId
          })),
          echoInsertion: true,
          md: 12,
          attributes: {
            disabled: this.openType != 0,
            placeholder: '请选择',
            clearable: true,
            filterable: true
          },
          formItemAttributes: {
            label: '考核项目',
            prop: 'projectId',
            propName: 'projectName',
            rules: [...required]
          },
          events: {
            change: val => {
              if (val) {
                var data = this.managerListProject?.find(item => item.projectId === val)
                this.formData.projectName = data?.projectName
                this.formData.projectReg = data?.projectReg || ''
                this.formData.projectText = data?.projectText || ''
                this.formData.price = data?.price || ''
                this.formData.fraction = data?.fraction || ''
              } else {
                this.formData.projectReg = ''
                this.formData.projectText = ''
                this.formData.price = ''
                this.formData.fraction = ''
                this.formData.projectName = ''
              }
            }
          }
        },
        {
          md: 12,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '考核条例',
            prop: 'projectReg',
            rules: [...required]
          }
        },
        {
          md: 24,
          name: 'el-input',
          attributes: {
            disabled: true,
            type: 'textarea',
            rows: 3
          },
          formItemAttributes: {
            label: '考核规定',
            prop: 'projectText',
            rules: [...required]
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '考核金额',
            prop: 'price',
            rules: [...required]
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '考核分数',
            prop: 'fraction',
            rules: [...required]
          }
        },
        {
          md: 24,
          name: 'el-input',
          attributes: {
            disabled: this.openType != 0,
            type: 'textarea',
            rows: 3
          },
          formItemAttributes: {
            label: '函件内容',
            prop: 'context',
            rules: [...required]
          }
        },
        {
          md: 24,
          name: 'el-input',
          attributes: {
            disabled: this.openType != 0,
            type: 'textarea',
            rows: 3
          },
          formItemAttributes: {
            label: '备注',
            prop: 'remark',
            rules: []
          }
        },
        {
          md: 24,
          isShow: true,
          name: 'slot-component',
          formItemAttributes: {
            label: '附件',
            prop: 'fileUrl',
            rules: []
          },
          render: (h, { props, onInput }) => {
            return (
              <div>
                <ImageUpload fileList={this.formData.fileUrl} limit={1} isEdit={this.openType == 0} />
              </div>
            )
          }
        }
      ]
    },
    formItems1() {
      return [
        {
          name: 'el-radio',
          options: [
            { label: '接受', value: 'OK' },
            { label: '申诉', value: 'AP' }
          ],
          md: 8,
          attributes: {
            disabled: [-1, 2].includes(this.openType),
            placeholder: '请输入'
          },
          formItemAttributes: {
            label: '核实结果',
            prop: 'websitAppeal',
            rules: [...required]
          }
        },
        {
          md: 8,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '申诉人',
            prop: 'createBy',
            rules: []
          }
        },
        {
          md: 8,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '申诉时间',
            prop: 'createTime',
            rules: []
          }
        },
        {
          md: 24,
          name: 'el-input',
          attributes: {
            disabled: [-1, 2].includes(this.openType),
            type: 'textarea',
            rows: 3
          },
          formItemAttributes: {
            label: '申诉内容',
            prop: 'appealRemark',
            rules: [...required]
          }
        },
        {
          md: 24,
          name: 'slot-component',
          formItemAttributes: {
            label: '申诉附件',
            prop: 'appealUrl',
            rules: []
          },
          render: (h, { props, onInput }) => {
            return (
              <div>
                <ImageUpload fileList={this.formData1.appealUrl} limit={1} isEdit={this.openType == 1} />
              </div>
            )
          }
        }
      ]
    },
    formItems2() {
      return [
        {
          name: 'el-radio',
          options: [
            { label: '通过', value: 'OK' },
            { label: '驳回', value: 'FAIL' },
            { label: '减免', value: 'SUB' }
          ],
          md: 24,
          attributes: {
            disabled: [-1].includes(this.openType),
            placeholder: '请输入'
          },
          formItemAttributes: {
            label: '审核结果',
            prop: 'examineStatus',
            rules: [...required]
          },
          events: {
            change: val => {
              if (val == 'OK') {
                this.formData2.examinePrice = 0
                this.formData2.examineFration = 0
              } else if (val == 'FAIL') {
                this.formData2.examinePrice = this.formData.price
                this.formData2.examineFration = this.formData.fraction
              } else if (val == 'SUB') {
                this.formData2.examinePrice = ''
                this.formData2.examineFration = ''
              }
            }
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: [-1].includes(this.openType) || ['OK', 'FAIL'].includes(this.formData2.examineStatus)
          },
          formItemAttributes: {
            label: '审批金额',
            prop: 'examinePrice',
            rules: [...required]
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: [-1].includes(this.openType) || ['OK', 'FAIL'].includes(this.formData2.examineStatus)
          },
          formItemAttributes: {
            label: '审批分数',
            prop: 'examineFration',
            rules: [...required]
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '审批人',
            prop: 'examineName',
            rules: []
          }
        },
        {
          md: 6,
          name: 'el-input',
          attributes: {
            disabled: true
          },
          formItemAttributes: {
            label: '审批时间',
            prop: 'createTime',
            rules: []
          }
        },
        {
          md: 24,
          name: 'el-input',
          attributes: {
            disabled: [-1].includes(this.openType),
            type: 'textarea',
            rows: 3
          },
          formItemAttributes: {
            label: '审批内容',
            prop: 'examineRemark',
            rules: [...required]
          }
        }
      ]
    }
  },
  methods: {
    // 列表请求函数
    getList: letterProcessList,
    // 列表导出函数
    exportList: letterProcessListExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    // 打开创建弹窗
    openForm() {
      Promise.all([
        getWebsit({ status: true }),
        letterManagerList({ pageNum: 1, pageSize: -1, params: [] }),
        letterManagerListProject({
          pageNum: 1,
          pageSize: -1,
          params: [{ param: 'a.status', compare: '=', value: 'ON' }]
        }),
        listPageV2({ pageNum: 1, pageSize: -1, params: [{ param: 'a.status', compare: '=', value: 'true' }] }),
        getClassifyList({ type: 2, status: true })
      ]).then(([res2, res3, res4, res5, res6]) => {
        this.openType = 0
        this.websitList = res2.data
        this.managerList = res3.data.records
        this.managerListProject = res4.data.records
        this.orderSmallTypeData = res5.data.records.map(item => ({
          value: item.id,
          label: item.orderSmallTypeText
        }))
        this.classifyList = res6.data.map(item => {
          var { children, ...data } = item
          return {
            ...data
          }
        })
        this.formDialog = true
      })
    },
    // 打开详情弹窗
    openDetailForm(row) {
      Promise.all([
        letterProcessDetailLetter({ id: row.leLetterId }),
        getWebsit({ status: true }),
        letterManagerList({ pageNum: 1, pageSize: -1, params: [] }),
        letterManagerListProject({
          pageNum: 1,
          pageSize: -1,
          params: [{ param: 'a.status', compare: '=', value: 'ON' }]
        }),
        listPageV2({ pageNum: 1, pageSize: -1, params: [{ param: 'a.status', compare: '=', value: 'true' }] }),
        getClassifyList({ type: 2, status: true })
      ]).then(([res1, res2, res3, res4, res5, res6]) => {
        this.formData = {
          ...res1.data,
          fileUrl: res1.data.fileUrl ? res1.data.fileUrl.split(',') : []
        }
        // 中心审批时需要把申述数据转换到formData1
        if (this.openType == 2 && res1.data.leLetterItems?.[0]) {
          this.formData1 = {
            ...res1.data.leLetterItems?.[0],
            appealUrl: res1.data.leLetterItems?.[0]?.appealUrl ? res1.data.leLetterItems?.[0]?.appealUrl.split(',') : []
          }
        }
        // 查看详情数据转换
        if (this.openType == -1) {
          this.formData = {
            ...this.formData,
            leLetterItems: this.formData.leLetterItems
              ? this.formData.leLetterItems.map(item => {
                  return {
                    ...item,
                    appealUrl: item?.appealUrl ? item?.appealUrl.split(',') : []
                  }
                })
              : []
          }
        }
        this.websitList = res2.data
        this.managerList = res3.data.records
        this.managerListProject = res4.data.records
        this.orderSmallTypeData = res5.data.records.map(item => ({
          value: item.id,
          label: item.orderSmallTypeText
        }))
        this.classifyList = res6.data.map(item => {
          var { children, ...data } = item
          return {
            ...data
          }
        })
        this.formDialog = true
      })
    },
    handleClose() {
      this.$refs?.formRef?.resetFields()
      this.$data.formData = this.$options.data().formData
      this.$data.formData1 = this.$options.data().formData1
      this.$data.formData2 = this.$options.data().formData2
      this.formDialog = false
      this.openType = 0
    },
    // 操作按钮
    operation() {
      return this.operationBtn({
        details: {
          click: ({ row, index, column }) => {
            this.openType = -1
            this.openDetailForm(row)
          }
        },
        edit: {
          conditions: ({ row, index, column }) => {
            return row.status === 'WAIT'
          },
          click: ({ row, index, column }) => {
            this.openType = 0
            this.openDetailForm(row)
          }
        },
        networkAppeal: {
          conditions: ({ row, index, column }) => {
            return row.status === 'SEND'
          },
          click: ({ row, index, column }) => {
            this.openType = 1
            this.openDetailForm(row)
          }
        },
        centralRebatch: {
          conditions: ({ row, index, column }) => {
            return row.status === 'WAIT_EXAMINE'
          },
          click: ({ row, index, column }) => {
            this.openType = 2
            this.openDetailForm(row)
          }
        }
        // del: {
        //   conditions: ({ row, index, column }) => {
        //     return true
        //   },
        //   prompt: '确定删除?',
        //   click: ({ row, index, column }) => {
        //     letterProcessDelLetter({
        //       id: row.id
        //     })
        //       .then(res => {
        //         this.$refs.pageRef.refreshList()
        //         this.$message({
        //           type: 'success',
        //           message: `删除成功!`
        //         })
        //       })
        //       .catch(err => {
        //         console.log(err)
        //       })
        //   }
        // }
      })
    },
    // 保存
    save(status) {
      this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          ;(this.formData?.leLetterId ? letterProcessUpdateLetter : letterProcessAddLetter)({
            ...this.formData,
            status: status || this.formData.status,
            fileUrl: this.formData.fileUrl.length ? this.formData.fileUrl.map(item => item.url).join(',') : ''
          }).then(res => {
            this.$message({
              type: 'success',
              message: '保存成功'
            })
            this.handleClose()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    },
    networkAudit() {
      this.$refs.formRef1.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          letterProcessAppeal({
            ...this.formData1,
            appealUrl: this.formData1.appealUrl.length ? this.formData1.appealUrl.map(item => item.url).join(',') : '',
            leLetterId: this.formData?.leLetterId
          }).then(res => {
            this.$message({
              type: 'success',
              message: '审核成功'
            })
            this.handleClose()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    },
    centralAudit() {
      this.$refs.formRef2.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          letterProcessExamine({
            ...this.formData2,
            leLetterItemId: this.formData.leLetterItems?.[0]?.leLetterItemId,
            leLetterId: this.formData?.leLetterId
          }).then(res => {
            this.$message({
              type: 'success',
              message: '审核成功'
            })
            this.handleClose()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
