<template>
  <div class="app-container">
    <div class="search-bx">
      <div class="search">
        <el-row :gutter="0">
          <el-input
            v-model="tableObj.getdataListParm.parammaps.reimbursementCode"
            placeholder="报销申请编号"
            class="filter-item"
            style="width: 120px; padding-bottom: 10px"
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.employeeId"
            placeholder="申报人"
            class="filter-item"
            style="width: 120px"
            clearable
            filterable
          >
            <el-option
              v-for="item in empNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-input
            v-model="tableObj.getdataListParm.parammaps.beginServiceCost"
            placeholder="申报金额"
            style="width: 80px"
          ></el-input>
          -
          <el-input
            v-model="tableObj.getdataListParm.parammaps.endServiceCost"
            placeholder="申报金额"
            style="width: 80px"
          ></el-input>

          <el-date-picker
            v-model="tableObj.getdataListParm.parammaps.inputDatetime1"
            class="inputDatetime filter-item"
            type="daterange"
            range-separator="至"
            start-placeholder="申报时间"
            end-placeholder="申报时间"
            style="width: 250px"
          />

          <el-select
            v-model="tableObj.getdataListParm.parammaps.statusName"
            placeholder="申报单状态"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in statusNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-select
            v-model="tableObj.getdataListParm.parammaps.declareTypeName"
            placeholder="申报类型"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in declareTypeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-select
            v-model="tableObj.getdataListParm.parammaps.costStatus"
            placeholder="回款状态"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in returnMoneyList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-input
            v-model="tableObj.getdataListParm.parammaps.postCode"
            placeholder="寄送发票快递单号"
            class="filter-item"
            style="width: 120px"
          />

          <el-button class="successBorder" @click="form_search">查询</el-button>
          <el-button class="successBorder" @click="form_clear">重置</el-button>

          <el-button
            v-if="isExpensesapplyAdd"
            class="success"
            icon="el-icon-plus"
            @click="form_add"
            >新增</el-button
          >
          <!-- <el-button  class="success" icon="el-icon-upload2" @click="form_export">导出</el-button> -->
        </el-row>
      </div>
    </div>

    <div class="table">
      <el-table
        :key="tableObj.tableKey"
        v-loading="tableObj.listLoading"
        element-loading-text="给我一点时间"
        :data="tableObj.list"
        border
        fit
        highlight-current-row
        style="width: 100%"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        :max-height="myHeight"
      >
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50px"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{
              scope.$index + (tableObj.pageNum - 1) * tableObj.pageSize + 1
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="报销申请单号"
          min-width="120px"
          align="center"
          show-overflow-tooltip
          fixed="left"
        >
          <template slot-scope="scope">
            <span
              style="color: #409eff; cursor: pointer"
              @click="form_see(scope.row)"
              >{{ scope.row.reimbursementCode }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="申请单状态"
          min-width="110px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.statusName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="回款状态"
          min-width="90px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.costStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="申报人"
          min-width="90px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.employeeName }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="申报类型"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.declareTypeName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="申报金额（元）"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.serviceCost }}</span>
          </template>
        </el-table-column>
        <el-table-column label="申报时间" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.declareDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="申报原因"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.declareReason }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="发票照片"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span
              style="color: #409eff; cursor: pointer"
              @click="form_see_nums(scope.row)"
              >查看</span
            >
          </template>
        </el-table-column>

        <!-- <el-table-column label="发票照片" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-popover
              placement="right"
              width="400"
              trigger="click">

              <div class="app-add">
                <el-row>

                          <el-image style="width: 350px; height: 350px;display:inline-block"  :src="scope.row.picname1"></el-image>

                  </el-row>
     1111
              </div>

              <el-button slot="reference">查看</el-button>
            </el-popover>

          </template>
        </el-table-column> -->

        <el-table-column
          label="寄送发票快递单号"
          min-width="140px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.postData }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="备注"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          :width="autoWidth"
          v-if="autoWidth !== 0"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              class="miniSuccess"
              @click="form_edit(row)"
              v-if="isExpensesapplyAdd && row.isModify == '1'"
              >编辑</el-button
            >
            <el-button
              class="miniDanger"
              @click="form_delete(row)"
              v-if="isExpensesapplyAdd && row.isDel == '1'"
              >删除</el-button
            >
            <el-button
              class="miniSuccess"
              @click="form_revoke(row)"
              v-if="isExpensesapplyAdd && row.isRevoke == '1'"
              >撤销</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="tableObj.total >= 0"
        :total="tableObj.total"
        :page.sync="tableObj.getdataListParm.offset"
        :limit.sync="tableObj.getdataListParm.pagecount"
        @pagination="get_table_data"
      />
    </div>

    <!-- 新增/编辑 -->
    <el-dialog
      :title="textMap[create.dialogStatus]"
      :visible.sync="create.dialogFormVisible"
      :close-on-click-modal="false"
      width="95%"
    >
      <div class="app-add">
        <el-form
          ref="tempTableForm"
          :rules="create.rules"
          :model="create.temp"
          label-position="right"
          label-width="150px"
          style="width: 95%; margin: 0 auto 50px"
        >
          <el-row :gutter="25">
            <el-col :span="declareTypeLength">
              <el-form-item label="申报类型：" prop="declareTypeName">
                <el-select
                  ref="declareTypeName"
                  v-model="create.temp.declareTypeName"
                  placeholder="请选择"
                  class="filter-item"
                  style="width: 100%"
                  @change="change_declare"
                  filterable
                  :disabled="create.dialogStatus == 'see'"
                >
                  <el-option
                    v-for="(item, index) in declareTypeList"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>

              <el-form-item label="申报金额：" prop="serviceCost">
                <el-input
                  ref="serviceCost"
                  v-model="create.temp.serviceCost"
                  class="filter-item"
                  style="width: 100%"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>

              <el-form-item label="寄送发票快递名称：" prop="postName">
                <el-input
                  ref="postName"
                  v-model="create.temp.postName"
                  class="filter-item"
                  style="width: 100%"
                  maxlength="11"
                  placeholder="请输入发票快递名称"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>

              <el-form-item label="寄送发票快递单号：" prop="postCode">
                <el-input
                  ref="postCode"
                  v-model="create.temp.postCode"
                  class="filter-item"
                  style="width: 100%"
                  maxlength="11"
                  placeholder="请输入发票快递单号"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>

              <el-form-item label="申报原因：" prop="declareReason">
                <el-input
                  ref="declareReason"
                  v-model="create.temp.declareReason"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 8 }"
                  :rows="8"
                  placeholder="请输入，最多200个字"
                  maxlength="200"
                  class="filter-item"
                  style="width: 100%"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>

              <el-form-item label="备注：" prop="remark">
                <el-input
                  ref="remark"
                  v-model="create.temp.remark"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 8 }"
                  :rows="8"
                  placeholder="请输入备注，最多200个字"
                  maxlength="200"
                  class="filter-item"
                  style="width: 100%"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>

              <el-form-item label="发票照片：" prop="scenePhoto1">
                <el-upload
                  id="uploadPic"
                  list-type="picture-card"
                  class="uploadPic"
                  :action="uploadImageUrl"
                  :limit="9"
                  :headers="headers"
                  :file-list="fileList"
                  :on-preview="handlePicPreview"
                  :auto-upload="true"
                  :on-change="
                    (file, fileList) => {
                      return handlePicChange(file, fileList);
                    }
                  "
                  :on-success="
                    (response, file, fileList) => {
                      return handlePicSuccess(response, file, fileList);
                    }
                  "
                  :on-remove="
                    (file, fileList) => {
                      return handlePicRemove(file, fileList);
                    }
                  "
                >
                  <i slot="default" class="el-icon-plus"></i>
                </el-upload>
                <el-dialog
                  :visible.sync="dialogVisible"
                  append-to-body
                  width="40%"
                >
                  <img width="80%" :src="dialogImageUrl" alt="" />
                </el-dialog>
              </el-form-item>
            </el-col>

            <el-col :span="16" v-show="declareType == 1">
              <h3>报销清单</h3>
              <el-row
                v-if="
                  create.dialogStatus === 'create' ||
                  create.dialogStatus == 'update'
                "
              >
                <el-button class="miniPrimary" @click="add_travel_expenses()"
                  >增加一条明细</el-button
                >
                <el-button class="miniPrimary" @click="choose_travel()"
                  >关联出差单</el-button
                >
              </el-row>
              <el-row v-if="create.dialogStatus == 'see'">
                <el-button class="miniPrimary" @click="printTable1()"
                  >打印</el-button
                >
              </el-row>

              <el-row>
                <el-col :span="8">
                  <el-form-item label="报销人：" prop="employeeName">
                    <el-input
                      v-model="create.temp.employeeName"
                      style="width: 130px"
                      disabled
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item label="时间：" prop="billDate">
                    <el-date-picker
                      v-model="create.temp.billDate"
                      type="date"
                      placeholder="选择日期"
                      format="yyyy-MM-dd"
                      value-format="yyyy-MM-dd"
                      style="width: 150px"
                      :clearable="false"
                      :disabled="create.dialogStatus == 'see'"
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item label="合计金额：" prop="vdate">
                    <el-input v-model="sumPriceAll1" disabled />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-table
                  key="0"
                  :data="tableTravelList"
                  border
                  show-summary
                  :summary-method="getSummaries1"
                  fit
                  highlight-current-row
                  style="width: 100%"
                  :row-style="rowStyle"
                  :cell-style="cellStyle"
                  class="elTable table-fixed"
                  @selection-change="change_table_selection1"
                >
                  <el-table-column type="selection" align="center" width="50" />
                  <el-table-column
                    label="序号"
                    align="center"
                    type="index"
                    width="50px"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.$index + 1 }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="日期"
                    min-width="170px"
                    align="center"
                    prop="businessDate"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.businessDate
                      }}</span>

                      <el-date-picker
                        v-if="scope.row.Edit"
                        v-model="scope.row.businessDate"
                        type="date"
                        placeholder="选择日期"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        style="width: 95%; padding: 10px 0"
                        :clearable="false"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="出差地"
                    min-width="110px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.businessAdress
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.businessAdress"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="拜见人"
                    min-width="110px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.clienter
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.clienter"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="差旅费"
                    min-width="110px"
                    align="center"
                  >
                    <el-table-column
                      label="交通费"
                      min-width="110px"
                      align="center"
                      prop="toll"
                    >
                      <template slot-scope="scope">
                        <span v-if="scope.row.NoEdit">{{
                          scope.row.toll
                        }}</span>
                        <el-input
                          v-if="scope.row.Edit"
                          v-model="scope.row.toll"
                          type="number"
                          @input="change_sumPrice1(scope.row)"
                          style="width: 95%; padding: 10px 0"
                        />
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="油费"
                      min-width="110px"
                      align="center"
                      prop="oilCost"
                    >
                      <template slot-scope="scope">
                        <span v-if="scope.row.NoEdit">{{
                          scope.row.oilCost
                        }}</span>
                        <el-input
                          v-if="scope.row.Edit"
                          v-model="scope.row.oilCost"
                          type="number"
                          @input="change_sumPrice1(scope.row)"
                          style="width: 95%; padding: 10px 0"
                        />
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="住宿费"
                      min-width="110px"
                      align="center"
                      prop="hotelCost"
                    >
                      <template slot-scope="scope">
                        <span v-if="scope.row.NoEdit">{{
                          scope.row.hotelCost
                        }}</span>
                        <el-input
                          v-if="scope.row.Edit"
                          v-model="scope.row.hotelCost"
                          type="number"
                          @input="change_sumPrice1(scope.row)"
                          style="width: 95%; padding: 10px 0"
                        />
                      </template>
                    </el-table-column>
                  </el-table-column>
                  <el-table-column
                    label="业务招待费"
                    min-width="110px"
                    align="center"
                    prop="serviceCost"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.serviceCost
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.serviceCost"
                        type="number"
                        @input="change_sumPrice1(scope.row)"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="其他费用"
                    min-width="110px"
                    align="center"
                    prop="otherCost"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.otherCost
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.otherCost"
                        type="number"
                        @input="change_sumPrice1(scope.row)"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="合计"
                    min-width="110px"
                    align="center"
                    prop="sumPrice"
                  >
                    <template slot-scope="scope">
                      <span> {{ scope.row.sumPrice }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="出差单号"
                    min-width="110px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.travelCode }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column
                    v-if="
                      create.dialogStatus == 'update' ||
                      create.dialogStatus == 'create'
                    "
                    label="操作"
                    align="center"
                    width="110"
                    class-name="small-padding fixed-width"
                    fixed="right"
                  >
                    <template slot-scope="{ row }">
                      <el-button
                        v-if="
                          create.dialogStatus == 'update' ||
                          create.dialogStatus == 'create'
                        "
                        class="miniDanger"
                        @click="form_delete1(row)"
                        >删除</el-button
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </el-row>
            </el-col>

            <el-col :span="16" v-show="declareType == 2">
              <h3>报销清单</h3>
              <el-row
                v-if="
                  create.dialogStatus === 'create' ||
                  create.dialogStatus == 'update'
                "
              >
                <el-button class="miniPrimary" @click="add_buy_expenses()"
                  >增加一条明细</el-button
                >
              </el-row>
              <el-row v-if="create.dialogStatus == 'see'">
                <el-button class="miniPrimary" @click="printTable2()"
                  >打印</el-button
                >
              </el-row>

              <el-row>
                <el-col :span="8">
                  <el-form-item label="报销人：" prop="employeeName">
                    <el-input
                      v-model="create.temp.employeeName"
                      style="width: 130px"
                      disabled
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item label="时间：" prop="billDate">
                    <el-date-picker
                      v-model="create.temp.billDate"
                      type="date"
                      placeholder="选择日期"
                      format="yyyy-MM-dd"
                      value-format="yyyy-MM-dd"
                      style="width: 150px"
                      :clearable="false"
                      :disabled="create.dialogStatus == 'see'"
                    />
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item label="合计金额：" prop="vdate">
                    <el-input v-model="sumPriceAll2" disabled />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-table
                  key="0"
                  :data="tableBuyList"
                  border
                  show-summary
                  :summary-method="getSummaries2"
                  fit
                  highlight-current-row
                  style="width: 100%"
                  :row-style="rowStyle"
                  :cell-style="cellStyle"
                  class="elTable table-fixed"
                >
                  <el-table-column
                    label="序号"
                    align="center"
                    type="index"
                    width="50px"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.$index + 1 }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column
                    label="类型"
                    min-width="110px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.goodsType
                      }}</span>
                      <el-select
                        v-if="scope.row.Edit"
                        v-model="scope.row.goodsType"
                        placeholder="类型"
                        class="filter-item"
                        style="width: 95%; padding: 10px 0"
                        clearable
                      >
                        <el-option
                          v-for="item in buyTypeList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                        />
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="名称"
                    min-width="110px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.goodsName
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.goodsName"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="购买日期"
                    min-width="170px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.purchaseDate
                      }}</span>
                      <el-date-picker
                        v-if="scope.row.Edit"
                        v-model="scope.row.purchaseDate"
                        type="date"
                        placeholder="选择日期"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        style="width: 95%; padding: 10px 0"
                        :clearable="false"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="数量"
                    min-width="110px"
                    align="center"
                    prop="goodsNum"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.goodsNum
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.goodsNum"
                        type="number"
                        @input="change_sumPrice2(scope.row)"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="单位名称"
                    min-width="110px"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.company
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.company"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="单价"
                    min-width="110px"
                    align="center"
                    prop="goodsPrice"
                  >
                    <template slot-scope="scope">
                      <span v-if="scope.row.NoEdit">{{
                        scope.row.goodsPrice
                      }}</span>
                      <el-input
                        v-if="scope.row.Edit"
                        v-model="scope.row.goodsPrice"
                        type="number"
                        @input="change_sumPrice2(scope.row)"
                        style="width: 95%; padding: 10px 0"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="合计"
                    min-width="110px"
                    align="center"
                    prop="sumPrice"
                  >
                    <template slot-scope="scope">
                      <span> {{ scope.row.sumPrice }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column
                    v-if="
                      create.dialogStatus == 'update' ||
                      create.dialogStatus == 'create'
                    "
                    label="操作"
                    align="center"
                    width="110"
                    class-name="small-padding fixed-width"
                    fixed="right"
                  >
                    <template slot-scope="{ row }">
                      <el-button
                        v-if="
                          create.dialogStatus == 'update' ||
                          create.dialogStatus == 'create'
                        "
                        class="miniDanger"
                        @click="form_delete2(row)"
                        >删除</el-button
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </el-row>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="cancelClose"
            @click="
              create.dialogFormVisible = false;
              get_table_data();
            "
            >关闭</el-button
          >
          <el-button
            v-if="
              create.dialogStatus === 'create' ||
              create.dialogStatus === 'update'
            "
            class="success"
            :disabled="isokDisable"
            @click="
              create.dialogStatus === 'create'
                ? add_dialog_save()
                : form_edit_save()
            "
            >确认</el-button
          >
        </div>
      </div>
    </el-dialog>

    <!-- 出差单详情 -->
    <el-dialog
      title="出差单详情"
      :visible.sync="seeTravel.dialogFormVisible"
      top="10px"
      :close-on-click-modal="false"
      width="95%"
    >
      <div class="app-add">
        <TravelDetail :travel-data="travelData" ref="childtravel" />

        <div slot="footer" class="dialog-footer">
          <el-button class="success" @click="add_travel_save()">确认</el-button>
          <el-button class="cancelClose" @click="add_travel_close()"
            >关闭</el-button
          >
        </div>
      </div>
    </el-dialog>

    <!-- 撤销 -->
    <el-dialog
      title="确认是否撤销"
      :visible.sync="revoke.dialogFormVisible"
      :close-on-click-modal="false"
      width="60%"
    >
      <div class="app-add">
        <el-form
          ref="revoketemp"
          :rules="revoke.rules"
          :model="revoke.temp"
          label-position="right"
          label-width="150px"
          style="width: 80%; margin: 0 auto 50px"
        >
          <el-form-item label="撤销原因：" prop="revokeReason">
            <el-input
              ref="remark"
              v-model="revoke.temp.revokeReason"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8 }"
              :rows="8"
              placeholder="请输入备注，最多200个字"
              maxlength="200"
              class="filter-item"
              style="width: 100%"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="cancelClose"
            @click="
              revoke.dialogFormVisible = false;
              get_table_data();
            "
            >关闭</el-button
          >
          <el-button class="success" @click="form_revoke_save()"
            >确认</el-button
          >
        </div>
      </div>
    </el-dialog>

    <!-- 查看/反馈 -->
    <el-dialog
      title="发票详情"
      :visible.sync="createSeeNums.dialogFormVisible"
      :close-on-click-modal="false"
      width="75%"
    >
      <div class="app-add">
        <el-row>
          <el-col :span="6" v-for="(item, index) in tableInvocieList">
            <el-col :span="24">
              <el-image
                style="width: 350px; height: 350px; display: inline-block"
                :src="item"
              ></el-image>
            </el-col>
          </el-col>
        </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="cancelClose"
            @click="createSeeNums.dialogFormVisible = false"
            >关闭</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  GetDataByName,
  PostDataByName,
  failproccess,
  ExecDataByConfig,
  GetDataByNames,
  checkButtons,
  calculativeWidth,
  wxpush,
} from "@/api/common";
import Cookies from "js-cookie";
import { parseTime, json2excel } from "@/utils/index.js";
import Pagination from "@/components/Pagination";
import { MessageBox } from "element-ui";
import { getToken } from "@/utils/auth";
import TravelDetail from "@/componentView/TravelDetail.vue";

import printJS from "print-js";

export default {
  name: "ExpensesApply",
  components: { Pagination, TravelDetail },
  data() {
    return {
      myHeight: document.documentElement.clientHeight - 85 - 160,
      sumPriceAll1: 0,
      sumPriceAll2: 0,
      dialogImageUrl: "",
      dialogVisible: false,
      //图片请求地址
      uploadImageUrl: process.env.VUE_APP_BASE_API + "authdata/uploaderimage",
      //图片请求头
      headers: {
        optname: "insertcustompic",
        id: 1,
        token: getToken(), // 从cookie里获取token，并赋值token
      },
      //图片路径
      fileList: [],

      employeid: Cookies.get("employeid"),

      isRoleEdit: [],
      isExpensesapplyAdd: [],

      send_select_list: [
        {
          name: "getUserFuzzy",
          offset: 0,
          pagecount: 0,
          parammaps: { inputvalue: "" },
        },
      ],
      customerNameList: [], // 客户名称
      loading: false,
      groupNameList: [], // 集团
      visiterNameList: [],
      receiverNameList: [],
      nextNameList: [],

      //1 出差，2 采购  3其它
      declareType: 1,
      declareTypeLength: 8,

      // 下拉框 - 申报人

      empNameList: [],
      // 下拉框 - 申报类型
      declareTypeList: [
        { name: "出差", id: "出差" },
        { name: "物流费", id: "物流费" },
        { name: "交通费", id: "交通费" },
        { name: "办公费", id: "办公费" },
        { name: "通讯费", id: "通讯费" },
        { name: "业务招待费", id: "业务招待费" },
        { name: "房租及业务管理费", id: "房租及业务管理费" },
        { name: "水电费", id: "水电费" },
        { name: "社保", id: "社保" },
        { name: "公积金", id: "公积金" },
        { name: "工资", id: "工资" },
        { name: "手续费", id: "手续费" },
        { name: "采购", id: "采购" },
        { name: "其他费用", id: "其他费用" },
      ],

      // 下拉框 - 出差单
      statusNameList: [
        { name: "草稿", id: "草稿" },
        { name: "一审中", id: "一审中" },
        { name: "二审中", id: "二审中" },
        { name: "三审中", id: "三审中" },
        { name: "审核通过", id: "审核通过" },
        { name: "已撤销", id: "已撤销" },
        { name: "被驳回", id: "被驳回" },
      ],

      // 下拉框 - 出差单
      returnMoneyList: [
        { name: "已回款", id: "已回款" },
        { name: "未回款", id: "未回款" },
      ],

      // 下拉框 - 采购类型
      buyTypeList: [
        { name: "原材料", id: "原材料" },
        { name: "外购", id: "外购" },
      ],

      //表格请求参数~~
      tableObj: {
        getdataListParm: {
          name: "getReimbursement",
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get("pagecount")),
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            reimbursementCode: "",
            employeeId: "",
            statusName: "",
            declareTypeName: "",
            costStatus: "",
            postCode: "",
            beginServiceCost: "",
            endServiceCost: "",

            beginDeclareDate: "",
            endDeclareDate: "",
            inputDatetime1: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      download: {
        getdataListParm: {
          name: "getReimbursement",
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            reimbursementCode: "",
            employeeId: "",
            statusName: "",
            declareTypeName: "",
            costStatus: "",
            postCode: "",
            beginServiceCost: "",
            endServiceCost: "",

            beginDeclareDate: "",
            endDeclareDate: "",
            inputDatetime1: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {
          employeeId: "",
          declareTypeName: "",
          serviceCost: "",
          billDate: parseTime(new Date(), "{y}-{m}-{d}"),
          postName: "",
          postCode: "",
          declareReason: "",
          remark: "",
          scenePhoto1: -1,
          scenePhoto2: -1,
          scenePhoto3: -1,
          scenePhoto4: -1,
          scenePhoto5: -1,
          scenePhoto6: -1,
          scenePhoto7: -1,
          scenePhoto8: -1,
          scenePhoto9: -1,
          scenePhoto10: -1,
          picname1: "",
          picname2: "",
          picname3: "",
          picname4: "",
          picname5: "",
          picname6: "",
          picname7: "",
          picname8: "",
          picname9: "",
          picname10: "",
        },
        rules: {
          declareTypeName: [
            { required: true, message: "必填", trigger: "blur" },
          ],
          serviceCost: [{ required: true, message: "必填", trigger: "blur" }],
          scenePhoto1: [{ required: true, message: "必填", trigger: "blur" }],
          // receiverId: [{ required: true, message: '必填', trigger: 'blur' }],
          // receiverTel: [{ required: true, message: '必填', trigger: 'blur' }],
          // content: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          // scenePhoto1: [{ required: true, message: '必填', trigger: 'blur' }],
        },
        // 出差小表格
        getTableTravelListParm: {
          name: "getReimbursementBusiness",
          returntype: "Map",
          parammaps: { id: "" },
        },
        //  采购小表格
        getTableBuyListParm: {
          name: "getReimbursementPurchase",
          returntype: "Map",
          parammaps: { id: "" },
        },
      },

      //发票信息
      tableInvocieList: [],

      createSeeNums: {
        dialogFormVisible: false,
      },

      selectList1: [],

      //出差小表格
      tableTravelList: [
        // {id:1,NoEdit:true,Edit:false},
        // {id:2,NoEdit:false,Edit:true},
      ],
      //z这里表格初始ID
      tableTravelId: 91,

      //采购小表格
      tableBuyList: [
        // {id:1,NoEdit:true,Edit:false},
        // {id:2,NoEdit:false,Edit:true},
      ],
      //z这里表格初始ID
      tableBuyId: 91,

      //出差单组件
      travelData: {},
      seeTravel: {
        dialogFormVisible: false,
      },

      travelExpenId: 0,

      // 撤销
      revoke: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: { revokeReason: "", id: "" },
        rules: {
          revokeReason: [{ required: true, message: "必填", trigger: "blur" }],
        },
      },

      textMap: {
        create: "新增",
        see: "查看",
        update: "编辑",
      },

      requestParam: {},
      isokDisable: false,

      autoWidth: 130,

      rowStyle: { maxHeight: 50 + "px", height: 45 + "px" },
      cellStyle: { padding: 0 + "px" },
    };
  },

  created() {
    this.get_table_data();
    this.get_select_list();
    this.get_auto_buttons();

    console.log("isRoleEdit", sessionStorage.getItem("buttons"));
    console.log(Cookies.get("employeid"));
  },

  watch: {
    tableTravelList: {
      deep: true,
      handler: function (item) {
        //计算总价格
        var sum = 0;
        this.tableTravelList.forEach(function (i) {
          var toll = parseFloat(i.toll);
          var oilCost = parseFloat(i.oilCost);
          var hotelCost = parseFloat(i.hotelCost);
          var serviceCost = parseFloat(i.serviceCost);
          var otherCost = parseFloat(i.otherCost);
          if (toll == "" || toll == undefined || toll == null || isNaN(toll)) {
            toll = 0;
          }
          if (
            oilCost == "" ||
            oilCost == undefined ||
            oilCost == null ||
            isNaN(oilCost)
          ) {
            oilCost = 0;
          }
          if (
            hotelCost == "" ||
            hotelCost == undefined ||
            hotelCost == null ||
            isNaN(hotelCost)
          ) {
            hotelCost = 0;
          }
          if (
            serviceCost == "" ||
            serviceCost == undefined ||
            serviceCost == null ||
            isNaN(serviceCost)
          ) {
            serviceCost = 0;
          }
          if (
            otherCost == "" ||
            otherCost == undefined ||
            otherCost == null ||
            isNaN(otherCost)
          ) {
            otherCost = 0;
          }

          sum = toll + oilCost + hotelCost + serviceCost + otherCost + sum;
        });

        this.sumPriceAll1 = sum;
      },
    },
    tableBuyList: {
      deep: true,
      handler: function (item) {
        //计算总价格
        var sum = 0;
        this.tableBuyList.forEach(function (i) {
          var goodsNum = parseFloat(i.goodsNum);
          var goodsPrice = parseFloat(i.goodsPrice);

          if (
            goodsNum == "" ||
            goodsNum == undefined ||
            goodsNum == null ||
            isNaN(goodsNum)
          ) {
            goodsNum = 0;
          }
          if (
            goodsPrice == "" ||
            goodsPrice == undefined ||
            goodsPrice == null ||
            isNaN(goodsPrice)
          ) {
            goodsPrice = 0;
          }

          sum = goodsNum * goodsPrice + sum;
        });

        this.sumPriceAll2 = sum;
      },
    },
  },

  methods: {
    getSummaries1(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        console.log(column.property);
        console.log(values);
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          // sums[index] += ' 元';
        } else {
          sums[index] = "-";
        }
      });

      return sums;
    },

    getSummaries2(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }

        if (index === 6) {
          sums[index] = "-";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        console.log(column.property);
        console.log(values);
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          // sums[index] += ' 元';
        } else {
          sums[index] = "-";
        }
      });

      return sums;
    },

    // 查看
    form_see_nums(row) {
      console.log(row);

      var tableInvocieList = [];

      if (row.scenePhoto1 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname1;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto2 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname2;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto3 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname3;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto4 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname4;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto5 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname5;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto6 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname6;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto7 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname7;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto8 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname8;
        tableInvocieList.push(url);
      }
      if (row.scenePhoto9 !== "-1") {
        var url = process.env.VUE_APP_BASE_API + row.picname9;
        tableInvocieList.push(url);
      }

      this.tableInvocieList = tableInvocieList;
      console.log(this.tableInvocieList);

      this.createSeeNums.dialogFormVisible = true;
    },

    //图片展示
    handlePicPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handlePicChange(file, fileList) {},
    //文件上传成功后的操作
    handlePicSuccess(response, file, fileList) {
      console.log("文件上传成功时的钩子response", response);
      console.log("文件上传成功时的钩子file", file);
      console.log("fileList", fileList);

      //3张图片时，关闭新增的按钮
      if (fileList.length == 9) {
        document.getElementById("uploadPic").lastChild.style.display = "none";
      } else {
        document.getElementById("uploadPic").lastChild.style.display =
          "inline-block";
      }

      if (
        this.create.temp.scenePhoto1 === undefined ||
        this.create.temp.scenePhoto1 == -1
      ) {
        console.log("111");
        this.create.temp.scenePhoto1 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto2 === undefined ||
        this.create.temp.scenePhoto2 == -1
      ) {
        console.log("222");
        this.create.temp.scenePhoto2 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto3 === undefined ||
        this.create.temp.scenePhoto3 == -1
      ) {
        console.log("333");
        this.create.temp.scenePhoto3 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto4 === undefined ||
        this.create.temp.scenePhoto4 == -1
      ) {
        console.log("444");
        this.create.temp.scenePhoto4 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto5 === undefined ||
        this.create.temp.scenePhoto5 == -1
      ) {
        console.log("555");
        this.create.temp.scenePhoto5 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto6 === undefined ||
        this.create.temp.scenePhoto6 == -1
      ) {
        console.log("666");
        this.create.temp.scenePhoto6 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto7 === undefined ||
        this.create.temp.scenePhoto7 == -1
      ) {
        console.log("777");
        this.create.temp.scenePhoto7 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto8 === undefined ||
        this.create.temp.scenePhoto8 == -1
      ) {
        console.log("888");
        this.create.temp.scenePhoto8 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto9 === undefined ||
        this.create.temp.scenePhoto9 == -1
      ) {
        console.log("999");
        this.create.temp.scenePhoto9 = response.execresult.LastInsertId;
      } else if (
        this.create.temp.scenePhoto10 === undefined ||
        this.create.temp.scenePhoto10 == -1
      ) {
        console.log("999");
        this.create.temp.scenePhoto10 = response.execresult.LastInsertId;
      }
      console.log("this.picArr1", this.picArr1);

      console.log("this.create.temp", this.create.temp);
    },
    //图片文件删除
    handlePicRemove(file, fileList) {
      console.log(file, "文件列表移除文件时的钩子file---");
      console.log(fileList, "文件列表移除文件时的钩子fileList--");
      // this.$set(this.create.temp, "scenePhoto1", -1)
      // this.$set(this.create.temp, "scenePhoto2", -1)
      // this.$set(this.create.temp, "scenePhoto3", -1)
      //10张图片时，关闭新增的按钮
      if (fileList.length == 10) {
        document.getElementById("uploadPic").lastChild.style.display = "none";
      } else {
        document.getElementById("uploadPic").lastChild.style.display =
          "inline-block";
      }
      this.create.temp.scenePhoto1 = -1;
      this.create.temp.scenePhoto2 = -1;
      this.create.temp.scenePhoto3 = -1;
      this.create.temp.scenePhoto4 = -1;
      this.create.temp.scenePhoto5 = -1;
      this.create.temp.scenePhoto6 = -1;
      this.create.temp.scenePhoto7 = -1;
      this.create.temp.scenePhoto8 = -1;
      this.create.temp.scenePhoto9 = -1;
      this.create.temp.scenePhoto10 = -1;

      if (fileList.length == 10) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
        this.create.temp.scenePhoto5 =
          fileList[4].response.execresult.LastInsertId;
        this.create.temp.scenePhoto6 =
          fileList[5].response.execresult.LastInsertId;
        this.create.temp.scenePhoto7 =
          fileList[6].response.execresult.LastInsertId;
        this.create.temp.scenePhoto8 =
          fileList[7].response.execresult.LastInsertId;
        this.create.temp.scenePhoto9 =
          fileList[8].response.execresult.LastInsertId;
        this.create.temp.scenePhoto10 =
          fileList[9].response.execresult.LastInsertId;
      } else if (fileList.length == 9) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
        this.create.temp.scenePhoto5 =
          fileList[4].response.execresult.LastInsertId;
        this.create.temp.scenePhoto6 =
          fileList[5].response.execresult.LastInsertId;
        this.create.temp.scenePhoto7 =
          fileList[6].response.execresult.LastInsertId;
        this.create.temp.scenePhoto8 =
          fileList[7].response.execresult.LastInsertId;
        this.create.temp.scenePhoto9 =
          fileList[8].response.execresult.LastInsertId;
      } else if (fileList.length == 8) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
        this.create.temp.scenePhoto5 =
          fileList[4].response.execresult.LastInsertId;
        this.create.temp.scenePhoto6 =
          fileList[5].response.execresult.LastInsertId;
        this.create.temp.scenePhoto7 =
          fileList[6].response.execresult.LastInsertId;
        this.create.temp.scenePhoto8 =
          fileList[7].response.execresult.LastInsertId;
      } else if (fileList.length == 7) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
        this.create.temp.scenePhoto5 =
          fileList[4].response.execresult.LastInsertId;
        this.create.temp.scenePhoto6 =
          fileList[5].response.execresult.LastInsertId;
        this.create.temp.scenePhoto7 =
          fileList[6].response.execresult.LastInsertId;
      } else if (fileList.length == 6) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
        this.create.temp.scenePhoto5 =
          fileList[4].response.execresult.LastInsertId;
        this.create.temp.scenePhoto6 =
          fileList[5].response.execresult.LastInsertId;
      } else if (fileList.length == 5) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
        this.create.temp.scenePhoto5 =
          fileList[4].response.execresult.LastInsertId;
      } else if (fileList.length == 4) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
        this.create.temp.scenePhoto4 =
          fileList[3].response.execresult.LastInsertId;
      } else if (fileList.length == 3) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
        this.create.temp.scenePhoto3 =
          fileList[2].response.execresult.LastInsertId;
      } else if (fileList.length == 2) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
        this.create.temp.scenePhoto2 =
          fileList[1].response.execresult.LastInsertId;
      } else if (fileList.length == 1) {
        this.create.temp.scenePhoto1 =
          fileList[0].response.execresult.LastInsertId;
      }
      console.log(this.create.temp);
    },
    //获取按钮权限
    get_auto_buttons() {
      const Edit = "visitRecord";

      const isRoleEdit = checkButtons(
        JSON.parse(sessionStorage.getItem("buttons")),
        Edit
      );

      this.isRoleEdit = isRoleEdit;

      const ExpensesapplyAdd = "business:expensesapply:add";
      const isExpensesapplyAdd = checkButtons(
        this.$store.state.user.buttons,
        ExpensesapplyAdd
      );
      this.isExpensesapplyAdd = isExpensesapplyAdd;

      //操作的宽度
      // var widthCount = calculativeWidth(isExpensesapplyAdd,isExpensesapplyAdd)
      // this.autoWidth = widthCount
    },
    //获取所有下拉框的内容
    get_select_list() {
      GetDataByNames(this.send_select_list).then((response) => {
        this.empNameList = response.data.getUserFuzzy.list;
        console.log("出差人下拉框", this.empNameList);
      });
    },

    //加载表格
    get_table_data() {
      var me = this;
      this.tableObj.listLoading = true;
      console.log(
        "this.tableObj.getdataListParm======>",
        this.tableObj.getdataListParm
      );
      GetDataByName(this.tableObj.getdataListParm).then((response) => {
        console.log("table数据======>", response.data.list);
        if (response.data.list !== null) {
          this.tableObj.list = response.data.list;
          this.tableObj.pageNum = response.data.pageNum;
          this.tableObj.pageSize = response.data.pageSize;
          this.tableObj.total = response.data.total;
          //计算操作栏宽度
          var btnNum = 0;
          var arrList = response.data.list;
          arrList.forEach(function (row) {
            var itemBtnNum = 0;
            if (me.isExpensesapplyAdd && row.isModify == "1") {
              itemBtnNum = itemBtnNum + 1;
            }
            if (me.isExpensesapplyAdd && row.isDel == "1") {
              itemBtnNum = itemBtnNum + 1;
            }
            if (me.isExpensesapplyAdd && row.isRevoke == "1") {
              itemBtnNum = itemBtnNum + 1;
            }

            console.log(itemBtnNum);
            if (itemBtnNum > btnNum) {
              btnNum = itemBtnNum;
            }
          });
          console.log("btnNum=============", btnNum);
          me.autoWidth = btnNum * 90;
        } else {
          this.tableObj.list = [];
        }
        setTimeout(() => {
          this.tableObj.listLoading = false;
        }, 100);
      });
    },
    form_search() {
      console.log("点击了查询");

      if (
        this.tableObj.getdataListParm.parammaps.inputDatetime1 !== "" &&
        this.tableObj.getdataListParm.parammaps.inputDatetime1 !== null
      ) {
        this.tableObj.getdataListParm.parammaps.beginDeclareDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime1[0],
          "{y}-{m}-{d}"
        );
        this.tableObj.getdataListParm.parammaps.endDeclareDate = parseTime(
          this.tableObj.getdataListParm.parammaps.inputDatetime1[1],
          "{y}-{m}-{d}"
        );
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime1 = "";
        this.tableObj.getdataListParm.parammaps.beginDeclareDate = "";
        this.tableObj.getdataListParm.parammaps.endDeclareDate = "";
      }
      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },
    form_clear() {
      console.log("点击了重置");
      this.tableObj.getdataListParm.parammaps.reimbursementCode = "";
      this.tableObj.getdataListParm.parammaps.employeeId = "";
      this.tableObj.getdataListParm.parammaps.statusName = "";
      this.tableObj.getdataListParm.parammaps.declareTypeName = "";
      this.tableObj.getdataListParm.parammaps.postCode = "";
      this.tableObj.getdataListParm.parammaps.beginServiceCost = "";
      this.tableObj.getdataListParm.parammaps.costStatus = "";
      this.tableObj.getdataListParm.parammaps.endServiceCost = "";

      this.tableObj.getdataListParm.parammaps.beginDeclareDate = "";
      this.tableObj.getdataListParm.parammaps.endDeclareDate = "";
      this.tableObj.getdataListParm.parammaps.inputDatetime1 = "";
      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },

    // 新增
    form_reset() {
      (this.create.temp = {
        employeeId: "",
        declareTypeName: "",
        serviceCost: "",
        billDate: parseTime(new Date(), "{y}-{m}-{d}"),
        postName: "",
        postCode: "",
        declareReason: "",
        remark: "",
        scenePhoto1: -1,
        scenePhoto2: -1,
        scenePhoto3: -1,
        scenePhoto4: -1,
        scenePhoto5: -1,
        scenePhoto6: -1,
        scenePhoto7: -1,
        scenePhoto8: -1,
        scenePhoto9: -1,
        scenePhoto10: -1,
        picname1: "",
        picname2: "",
        picname3: "",
        picname4: "",
        picname5: "",
        picname6: "",
        picname7: "",
        picname8: "",
        picname9: "",
        picname10: "",
      }),
        (this.tableTravelList = []);
      this.tableBuyList = [];
      this.fileList = [];
    },

    //监听 - 申报类型
    change_declare(item) {
      console.log(item);
      //1 出差，2 采购  3其它
      //declareType:1,
      if (item == "出差") {
        this.declareType = 1;
        this.declareTypeLength = 8;
      } else if (item == "采购") {
        this.declareType = 2;
        this.declareTypeLength = 8;
      } else {
        this.declareType = 3;
        this.declareTypeLength = 24;
      }

      this.$forceUpdate();
    },

    //新增
    form_add() {
      console.log("点击了新增");

      this.create.dialogStatus = "create";
      this.create.dialogFormVisible = true;
      this.form_reset();

      this.$nextTick(() => {
        //子组件更新
        this.$refs.childtravel.form_clear();
      });
    },

    //新增保存
    add_dialog_save() {
      console.log("点击了新增保存");
      var me = this;
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.$refs["tempTableForm"].validate((valid) => {
        if (valid) {
          this.isokDisable = true;
          setTimeout(() => {
            this.isokDisable = false;
          }, 1000);

          this.create.temp.createrId = Cookies.get("employeid");
          this.create.temp.employeeId = Cookies.get("employeid");

          var tableTravelList = this.tableTravelList;
          if (tableTravelList.length != 0) {
            tableTravelList.forEach(function (item) {
              item.createrId = Cookies.get("employeid");
            });
          }

          var tableBuyList = this.tableBuyList;
          if (tableBuyList.length != 0) {
            tableBuyList.forEach(function (item) {
              item.createrId = Cookies.get("employeid");
            });
          }

          var send_data1 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "insertReimbursementBusiness",
                resultmaps: { list: tableTravelList },
                children: [
                  {
                    name: "insertReimbursementBusiness",
                    type: "e",
                    parammaps: {
                      reimbursementId: "@insertReimbursement.LastInsertId",
                      businessDate: "@insertReimbursementBusiness.businessDate",
                      businessAdress:
                        "@insertReimbursementBusiness.businessAdress",
                      clienter: "@insertReimbursementBusiness.clienter",
                      toll: "@insertReimbursementBusiness.toll",
                      oilCost: "@insertReimbursementBusiness.oilCost",
                      hotelCost: "@insertReimbursementBusiness.hotelCost",
                      serviceCost: "@insertReimbursementBusiness.serviceCost",
                      otherCost: "@insertReimbursementBusiness.otherCost",
                      businesstravelId:
                        "@insertReimbursementBusiness.businesstravelId",
                      travelCode: "@insertReimbursementBusiness.travelCode",
                      createrId: "@insertReimbursementBusiness.createrId",
                    },
                  },
                ],
              },
            ],
          };

          var send_data2 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "insertReimbursementPurchase",
                resultmaps: {
                  list: tableBuyList,
                },
                children: [
                  {
                    name: "insertReimbursementPurchase",
                    type: "e",
                    parammaps: {
                      reimbursementId: "@insertReimbursement.LastInsertId",
                      company: "@insertReimbursementPurchase.company",
                      goodsType: "@insertReimbursementPurchase.goodsType",
                      goodsName: "@insertReimbursementPurchase.goodsName",
                      purchaseDate: "@insertReimbursementPurchase.purchaseDate",
                      goodsNum: "@insertReimbursementPurchase.goodsNum",
                      goodsPrice: "@insertReimbursementPurchase.goodsPrice",
                      createrId: "@insertReimbursementPurchase.createrId",
                    },
                  },
                ],
              },
            ],
          };

          var send_data3 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
            ],
          };

          var isTravelCode = false;
          tableTravelList.forEach(function (item) {
            if (item.travelCode == "") {
              isTravelCode = true;
            }
          });

          console.log("新增保存发送参数 - 出差 ", send_data1);
          console.log("新增保存发送参数 - 采购 ", send_data2);

          if (this.create.temp.scenePhoto1 == "-1") {
            var isEmpty = true;
          } else {
            var isEmpty = false;
          }

          if (isEmpty) {
            this.$message({
              type: "error",
              message: "请添加照片！",
              duration: 2000,
            });
          } else {
            //1 出差，2 采购  3其它

            //declareType:1,
            if (me.declareType == 1) {
              if (isTravelCode) {
                this.$message({
                  type: "error",
                  message: "出差报销单必须选择出差单号！",
                  duration: 2000,
                });
              } else {
                ExecDataByConfig(send_data1).then((response) => {
                  if (response.msg !== "fail") {
                    this.$notify({
                      title: "成功",
                      message: "保存成功",
                      type: "success",
                      duration: 2000,
                    });
                    this.create.dialogFormVisible = false;
                    this.get_table_data();

                    var rowId = response.data[0].resultmaps.LastInsertId;
                    this.get_wxPush(58, "报销", rowId);
                  } else {
                    this.$notify({
                      title: "失败",
                      message: "保存失败" + response.data,
                      type: "error",
                      duration: 2000,
                    });
                  }
                });
              }
            } else if (me.declareType == 2) {
              ExecDataByConfig(send_data2).then((response) => {
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "保存成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.create.dialogFormVisible = false;
                  this.get_table_data();

                  var rowId = response.data[0].resultmaps.LastInsertId;
                  this.get_wxPush(58, "报销", rowId);
                } else {
                  this.$notify({
                    title: "失败",
                    message: "保存失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            } else {
              ExecDataByConfig(send_data3).then((response) => {
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "保存成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.create.dialogFormVisible = false;
                  this.get_table_data();

                  var rowId = response.data[0].resultmaps.LastInsertId;
                  this.get_wxPush(58, "报销", rowId);
                } else {
                  this.$notify({
                    title: "失败",
                    message: "保存失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            }
          }
        }
      });
    },

    //监听 - 出差表格 - 勾选
    change_table_selection1(val) {
      console.log("勾选数据", val);
      this.selectList1 = val;
    },

    //新增 - 出差单小表格
    add_travel_expenses() {
      console.log("点击了新增", this.tableTravelList);

      //因为虚拟表格，所有每次都绑定一个ID
      var tableTravelId = this.tableTravelId + 1;
      this.tableTravelId = tableTravelId;

      this.tableTravelList.unshift({
        businessDate: parseTime(new Date(), "{y}-{m}-{d}"),
        businessAdress: "",
        clienter: "",
        toll: "",
        oilCost: "",
        hotelCost: "",
        serviceCost: "",
        otherCost: "",
        sumPrice: 0,
        travelCode: "",
        businesstravelId: "",
        tableTravelId: tableTravelId,
        NoEdit: false,
        Edit: true,
      });

      console.log("点击了新增", this.tableTravelList);
    },

    //关联出差单
    choose_travel() {
      console.log("查看 - 出差单详情");
      if (this.selectList1.length == 0) {
        this.$message({
          type: "error",
          message: "请选择出差明细！",
          duration: 2000,
        });
      } else {
        this.seeTravel.dialogFormVisible = true;
      }
    },

    //确认出差单
    add_travel_save() {
      console.log("查看出差单子组件传递的信息", this.travelData);
      console.log("出差明细勾选数据", this.selectList1);

      var travelCode = this.travelData.selectList[0].travelCode;
      var businesstravelId = this.travelData.selectList[0].id;

      var tableTravelList = this.tableTravelList;
      var selectList1 = this.selectList1;

      tableTravelList.forEach(function (item) {
        selectList1.forEach(function (items) {
          if (item.tableTravelId == items.tableTravelId) {
            item.travelCode = travelCode;
            item.businesstravelId = businesstravelId;
          }
        });
      });

      this.tableTravelList = tableTravelList;

      this.$refs.childtravel.form_clear();
      this.seeTravel.dialogFormVisible = false;
    },

    add_travel_close() {
      this.$refs.childtravel.form_clear();
      this.seeTravel.dialogFormVisible = false;
      this.get_table_data();
    },

    //删除 - 出差小表格
    form_delete1(row) {
      console.log("小表格中的删除单号", row);
      var tableTravelId = row.tableTravelId;
      console.log("小表格中的删除tableTravelList", this.tableTravelList);
      var index = this.tableTravelList.findIndex(
        (obj) => obj.tableTravelId == tableTravelId
      );
      console.log("index", index);
      this.tableTravelList.splice(index, 1);
    },

    change_sumPrice1(row) {
      var toll = parseFloat(row.toll);
      var oilCost = parseFloat(row.oilCost);
      var hotelCost = parseFloat(row.hotelCost);
      var serviceCost = parseFloat(row.serviceCost);
      var otherCost = parseFloat(row.otherCost);

      if (toll == "" || toll == undefined || toll == null || isNaN(toll)) {
        toll = 0;
      }
      if (
        oilCost == "" ||
        oilCost == undefined ||
        oilCost == null ||
        isNaN(oilCost)
      ) {
        oilCost = 0;
      }
      if (
        hotelCost == "" ||
        hotelCost == undefined ||
        hotelCost == null ||
        isNaN(hotelCost)
      ) {
        hotelCost = 0;
      }
      if (
        serviceCost == "" ||
        serviceCost == undefined ||
        serviceCost == null ||
        isNaN(serviceCost)
      ) {
        serviceCost = 0;
      }
      if (
        otherCost == "" ||
        otherCost == undefined ||
        otherCost == null ||
        isNaN(otherCost)
      ) {
        otherCost = 0;
      }

      row.sumPrice = toll + oilCost + hotelCost + serviceCost + otherCost;
    },

    change_sumPrice2(row) {
      var goodsNum = parseFloat(row.goodsNum);
      var goodsPrice = parseFloat(row.goodsPrice);

      if (
        goodsNum == "" ||
        goodsNum == undefined ||
        goodsNum == null ||
        isNaN(goodsNum)
      ) {
        goodsNum = 0;
      }
      if (
        goodsPrice == "" ||
        goodsPrice == undefined ||
        goodsPrice == null ||
        isNaN(goodsPrice)
      ) {
        goodsPrice = 0;
      }

      row.sumPrice = goodsNum * goodsPrice;
    },

    //新增 - 采购单小表格
    add_buy_expenses() {
      console.log("点击了新增");

      //因为虚拟表格，所有每次都绑定一个ID
      var tableBuyId = this.tableBuyId + 1;
      this.tableBuyId = tableBuyId;

      this.tableBuyList.unshift({
        purchaseDate: parseTime(new Date(), "{y}-{m}-{d}"),
        goodsType: "",
        goodsName: "",
        goodsNum: "",
        company: "",
        goodsPrice: "",
        sumPrice: 0,
        tableBuyId: tableBuyId,
        NoEdit: false,
        Edit: true,
      });

      console.log("this.tableBuyList", this.tableBuyList);
    },
    //删除 - 采购单小表格
    form_delete2(row) {
      console.log("小表格中的删除单号", row);
      var tableBuyId = row.tableBuyId;
      console.log("小表格中的删除tableBuyList", this.tableBuyList);
      var index = this.tableBuyList.findIndex(
        (obj) => obj.tableBuyId == tableBuyId
      );
      console.log("index", index);
      this.tableBuyList.splice(index, 1);
    },

    // 查看
    form_see(row) {
      console.log("点击了查看", row);
      // this.$nextTick(() => {
      //   this.$refs.temp.resetFields()
      // })

      this.create.temp = Object.assign({}, row);

      this.create.temp.id = row.id;

      if (row.declareTypeName == "出差") {
        this.declareType = 1;
        this.declareTypeLength = 8;
        this.create.getTableTravelListParm.parammaps.id = row.id;
        this.getTableTravelList();
      } else if (row.declareTypeName == "采购") {
        this.declareType = 2;
        this.declareTypeLength = 8;
        this.create.getTableBuyListParm.parammaps.id = row.id;
        this.getTableBuyList();
      } else {
        this.declareType = 3;
        this.declareTypeLength = 24;
      }

      // 现场照片
      const urlArray = [];
      const urlArrayId = [];
      const fileList = [];

      if (this.create.temp.picname1 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname1);
        urlArrayId.push(this.create.temp.scenePhoto1);
      }
      if (this.create.temp.picname2 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname2);
        urlArrayId.push(this.create.temp.scenePhoto2);
      }
      if (this.create.temp.picname3 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname3);
        urlArrayId.push(this.create.temp.scenePhoto3);
      }
      if (this.create.temp.picname4 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname4);
        urlArrayId.push(this.create.temp.scenePhoto4);
      }
      if (this.create.temp.picname5 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname5);
        urlArrayId.push(this.create.temp.scenePhoto5);
      }
      if (this.create.temp.picname6 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname6);
        urlArrayId.push(this.create.temp.scenePhoto6);
      }
      if (this.create.temp.picname7 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname7);
        urlArrayId.push(this.create.temp.scenePhoto7);
      }
      if (this.create.temp.picname8 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname8);
        urlArrayId.push(this.create.temp.scenePhoto8);
      }
      if (this.create.temp.picname9 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname9);
        urlArrayId.push(this.create.temp.scenePhoto9);
      }
      if (this.create.temp.picname10 != undefined) {
        urlArray.push(
          process.env.VUE_APP_BASE_API + this.create.temp.picname10
        );
        urlArrayId.push(this.create.temp.scenePhoto10);
      }

      console.log("urlArray", urlArray);
      console.log("urlArrayId", urlArrayId);

      for (let i = 0; i < urlArray.length; i++) {
        var urlObj = {
          url: "",
          response: { execresult: { LastInsertId: "" } },
        };
        urlObj.url = urlArray[i];
        // this.$set(urlObj, 'url', urlArray[i])
        // this.$set(urlObj, 'response', 15)
        urlObj.response.execresult.LastInsertId = urlArrayId[i];
        fileList.push(urlObj);
      }

      this.fileList = fileList;

      console.log("fileList", fileList);

      this.create.dialogStatus = "see";
      this.create.dialogFormVisible = true;
    },

    getTableTravelList() {
      GetDataByName(this.create.getTableTravelListParm).then((response) => {
        if (response.data.list !== null) {
          if (this.create.dialogStatus == "see") {
            for (let i = 0; i < response.data.list.length; i++) {
              this.$set(response.data.list[i], "Edit", false); // 编辑
              this.$set(response.data.list[i], "NoEdit", true); // 不可编辑/输入
            }
          } else {
            for (let i = 0; i < response.data.list.length; i++) {
              this.$set(response.data.list[i], "Edit", true); // 编辑
              this.$set(response.data.list[i], "NoEdit", false); // 不可编辑/输入
              this.$set(response.data.list[i], "tableTravelId", i);
            }
          }
          this.tableTravelList = response.data.list;
        } else {
          this.tableTravelList = [];
        }

        console.log("出差小表格", this.tableTravelList);
      });
    },
    getTableBuyList() {
      GetDataByName(this.create.getTableBuyListParm).then((response) => {
        if (response.data.list !== null) {
          if (this.create.dialogStatus == "see") {
            for (let i = 0; i < response.data.list.length; i++) {
              this.$set(response.data.list[i], "Edit", false); // 编辑
              this.$set(response.data.list[i], "NoEdit", true); // 不可编辑/输入
            }
          } else {
            for (let i = 0; i < response.data.list.length; i++) {
              this.$set(response.data.list[i], "Edit", true); // 编辑
              this.$set(response.data.list[i], "NoEdit", false); // 不可编辑/输入
              this.$set(response.data.list[i], "tableBuyId", i);
            }
          }
          this.tableBuyList = response.data.list;
        } else {
          this.tableBuyList = [];
        }
        console.log("采购小表格", this.tableBuyList);
      });
    },

    // 编辑
    form_edit(row) {
      console.log("点击了编辑", row);

      this.create.dialogStatus = "update";

      this.create.temp = Object.assign({}, row);
      this.create.temp.id = row.id;

      if (row.declareTypeName == "出差") {
        this.declareType = 1;
        this.declareTypeLength = 8;
        this.create.getTableTravelListParm.parammaps.id = row.id;
        this.getTableTravelList();

        this.$nextTick(() => {
          //子组件更新
          this.$refs.childtravel.form_clear();
        });
      } else if (row.declareTypeName == "采购") {
        this.declareType = 2;
        this.declareTypeLength = 8;
        this.create.getTableBuyListParm.parammaps.id = row.id;
        this.getTableBuyList();
      } else {
        this.declareType = 3;
        this.declareTypeLength = 24;
      }

      // 现场照片
      const urlArray = [];
      const urlArrayId = [];
      const fileList = [];

      if (this.create.temp.picname1 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname1);
        urlArrayId.push(this.create.temp.scenePhoto1);
      }
      if (this.create.temp.picname2 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname2);
        urlArrayId.push(this.create.temp.scenePhoto2);
      }
      if (this.create.temp.picname3 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname3);
        urlArrayId.push(this.create.temp.scenePhoto3);
      }
      if (this.create.temp.picname4 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname4);
        urlArrayId.push(this.create.temp.scenePhoto4);
      }
      if (this.create.temp.picname5 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname5);
        urlArrayId.push(this.create.temp.scenePhoto5);
      }
      if (this.create.temp.picname6 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname6);
        urlArrayId.push(this.create.temp.scenePhoto6);
      }
      if (this.create.temp.picname7 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname7);
        urlArrayId.push(this.create.temp.scenePhoto7);
      }
      if (this.create.temp.picname8 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname8);
        urlArrayId.push(this.create.temp.scenePhoto8);
      }
      if (this.create.temp.picname9 != undefined) {
        urlArray.push(process.env.VUE_APP_BASE_API + this.create.temp.picname9);
        urlArrayId.push(this.create.temp.scenePhoto9);
      }
      if (this.create.temp.picname10 != undefined) {
        urlArray.push(
          process.env.VUE_APP_BASE_API + this.create.temp.picname10
        );
        urlArrayId.push(this.create.temp.scenePhoto10);
      }

      console.log("urlArray", urlArray);
      console.log("urlArrayId", urlArrayId);

      for (let i = 0; i < urlArray.length; i++) {
        var urlObj = {
          url: "",
          response: { execresult: { LastInsertId: "" } },
        };
        urlObj.url = urlArray[i];
        // this.$set(urlObj, 'url', urlArray[i])
        // this.$set(urlObj, 'response', 15)
        urlObj.response.execresult.LastInsertId = urlArrayId[i];
        fileList.push(urlObj);
      }

      this.fileList = fileList;

      console.log("fileList", fileList);

      this.create.dialogFormVisible = true;

      console.log("点击了编辑", this.create.dialogStatus);
    },

    // 编辑保存
    form_edit_save() {
      var me = this;
      this.isokDisable = true;
      setTimeout(() => {
        this.isokDisable = false;
      }, 1000);
      this.$refs["tempTableForm"].validate((valid) => {
        if (valid) {
          this.isokDisable = true;
          setTimeout(() => {
            this.isokDisable = false;
          }, 1000);

          this.create.temp.createrId = Cookies.get("employeid");
          this.create.temp.employeeId = Cookies.get("employeid");

          var id = this.create.temp.id;

          var tableTravelList = this.tableTravelList;
          if (tableTravelList.length != 0) {
            tableTravelList.forEach(function (item) {
              item.createrId = Cookies.get("employeid");
            });
            tableTravelList.forEach(function (item) {
              item.id = id;
            });
          }

          var tableBuyList = this.tableBuyList;
          if (tableBuyList.length != 0) {
            tableBuyList.forEach(function (item) {
              item.createrId = Cookies.get("employeid");
            });
            tableBuyList.forEach(function (item) {
              item.id = id;
            });
          }

          var send_data1 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "updateReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "delReimbursementPurchase",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "delReimbursementBusiness",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "insertReimbursementBusiness",
                resultmaps: {
                  list: tableTravelList,
                },
                children: [
                  {
                    name: "insertReimbursementBusiness",
                    type: "e",
                    parammaps: {
                      reimbursementId: this.create.temp.id,
                      businessDate: "@insertReimbursementBusiness.businessDate",
                      businessAdress:
                        "@insertReimbursementBusiness.businessAdress",
                      clienter: "@insertReimbursementBusiness.clienter",
                      toll: "@insertReimbursementBusiness.toll",
                      oilCost: "@insertReimbursementBusiness.oilCost",
                      hotelCost: "@insertReimbursementBusiness.hotelCost",
                      serviceCost: "@insertReimbursementBusiness.serviceCost",
                      otherCost: "@insertReimbursementBusiness.otherCost",
                      businesstravelId:
                        "@insertReimbursementBusiness.businesstravelId",
                      travelCode: "@insertReimbursementBusiness.travelCode",
                      createrId: "@insertReimbursementBusiness.createrId",
                    },
                  },
                ],
              },
            ],
          };

          var send_data2 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "updateReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "delReimbursementPurchase",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "delReimbursementBusiness",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "insertReimbursementPurchase",
                resultmaps: {
                  list: tableBuyList,
                },
                children: [
                  {
                    name: "insertReimbursementPurchase",
                    type: "e",
                    parammaps: {
                      reimbursementId: "@insertBusinessTravel.LastInsertId", //
                      company: "@insertReimbursementPurchase.company",
                      goodsType: "@insertReimbursementPurchase.goodsType",
                      goodsName: "@insertReimbursementPurchase.goodsName",
                      purchaseDate: "@insertReimbursementPurchase.purchaseDate",
                      goodsNum: "@insertReimbursementPurchase.goodsNum",
                      goodsPrice: "@insertReimbursementPurchase.goodsPrice",
                      createrId: "@insertReimbursementPurchase.createrId",
                    },
                  },
                ],
              },
            ],
          };
          var send_data22 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "updateReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "delReimbursementPurchase",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "delReimbursementBusiness",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "insertReimbursementPurchase",
                resultmaps: {
                  list: tableBuyList,
                },
                children: [
                  {
                    name: "insertReimbursementPurchase",
                    type: "e",
                    parammaps: {
                      reimbursementId: this.create.temp.id,
                      company: "@insertReimbursementPurchase.company",
                      goodsType: "@insertReimbursementPurchase.goodsType",
                      goodsName: "@insertReimbursementPurchase.goodsName",
                      purchaseDate: "@insertReimbursementPurchase.purchaseDate",
                      goodsNum: "@insertReimbursementPurchase.goodsNum",
                      goodsPrice: "@insertReimbursementPurchase.goodsPrice",
                      createrId: "@insertReimbursementPurchase.createrId",
                    },
                  },
                ],
              },
            ],
          };

          var send_data3 = {
            common: { returnmap: "0" },
            data: [
              {
                name: "updateReimbursement",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "delReimbursementPurchase",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
              {
                name: "delReimbursementBusiness",
                type: "e",
                parammaps: { id: this.create.temp.id },
              },
            ],
          };

          console.log("编辑保存发送参数 - 出差 ", send_data1);
          console.log("编辑保存发送参数 - 采购 ", send_data2);

          if (this.create.temp.scenePhoto1 == "-1") {
            var isEmpty = true;
          } else {
            var isEmpty = false;
          }

          var isTravelCode = false;
          tableTravelList.forEach(function (item) {
            if (item.travelCode == "") {
              isTravelCode = true;
            }
          });

          if (isEmpty) {
            this.$message({
              type: "error",
              message: "请添加照片！",
              duration: 2000,
            });
          } else {
            //1 出差，2 采购  3其它

            //declareType:1,
            if (me.declareType == 1) {
              if (isTravelCode) {
                this.$message({
                  type: "error",
                  message: "出差报销单必须选择出差单号！",
                  duration: 2000,
                });
              } else {
                ExecDataByConfig(send_data1).then((response) => {
                  if (response.msg !== "fail") {
                    this.$notify({
                      title: "成功",
                      message: "保存成功",
                      type: "success",
                      duration: 2000,
                    });
                    this.create.dialogFormVisible = false;
                    this.get_table_data();

                    var rowId = this.create.temp.id;
                    var statusName = this.create.temp.statusName;

                    this.get_wxPush(58, "报销", rowId);
                  } else {
                    this.$notify({
                      title: "失败",
                      message: "保存失败" + response.data,
                      type: "error",
                      duration: 2000,
                    });
                  }
                });
              }
            } else if (me.declareType == 2) {
              ExecDataByConfig(send_data22).then((response) => {
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "保存成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.create.dialogFormVisible = false;
                  this.get_table_data();
                } else {
                  this.$notify({
                    title: "失败",
                    message: "保存失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            } else {
              ExecDataByConfig(send_data3).then((response) => {
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "保存成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.create.dialogFormVisible = false;
                  this.get_table_data();
                } else {
                  this.$notify({
                    title: "失败",
                    message: "保存失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            }
          }
        }
      });
    },

    // 删除
    form_delete(row) {
      MessageBox.confirm("是否确认删除此信息?", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var send_data = {
            name: "delReimbursement",
            parammaps: {
              id: row.id,
            },
          };

          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.get_table_data();
            }
          });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消删除" });
        });
    },

    // 撤销
    form_revoke(row) {
      console.log("点击了撤销", row);
      this.reset_revoke();
      this.revoke.temp.statusName = row.statusName;
      this.revoke.temp.id = row.id;
      this.revoke.dialogFormVisible = true;
    },
    // 撤销 - 重置
    reset_revoke() {
      this.revoke.temp.revokeReason = "";
    },

    // 撤销 - 确认
    form_revoke_save() {
      this.$refs["revoketemp"].validate((valid) => {
        if (valid) {
          var send_data = {
            name: "revokeReimbursement",
            parammaps: this.revoke.temp,
          };

          this.$confirm("是否撤销该条记录?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              PostDataByName(send_data).then((response) => {
                console.log("撤销发送参数", send_data);
                if (response.msg !== "fail") {
                  this.$notify({
                    title: "成功",
                    message: "撤销成功",
                    type: "success",
                    duration: 2000,
                  });
                  this.revoke.dialogFormVisible = false;
                  this.get_table_data();

                  var rowId = this.revoke.temp.id;
                  var statusName = this.revoke.temp.statusName;

                  if (statusName == "一审中") {
                    this.get_wxPush(65, "报销", rowId);
                  } else if (statusName == "二审中") {
                    this.get_wxPush(66, "报销", rowId);
                  } else if (statusName == "三审中") {
                    this.get_wxPush(67, "报销", rowId);
                  } else if (statusName == "审核通过") {
                    this.get_wxPush(68, "报销", rowId);
                  }
                } else {
                  this.$notify({
                    title: "失败",
                    message: "撤销失败" + response.data,
                    type: "error",
                    duration: 2000,
                  });
                }
              });
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消删除",
              });
            });
        }
      });
    },

    // 导出
    form_export(item) {
      this.download.getdataListParm.parammaps =
        this.tableObj.getdataListParm.parammaps;

      GetDataByName(this.download.getdataListParm).then((response) => {
        if (response.data.list !== null) {
          this.download.list = response.data.list;
        } else {
          this.download.list = [];
        }
        var excelDatas = [
          {
            tHeader: [
              "序号",
              "报销申请单号",
              "申请单状态",
              "回款状态",
              "申报人",
              "申报类型",
              "申报金额（元）",
              "申报时间",
              "申报原因",
              "寄送发票快递单号",
              "备注",
            ],
            filterVal: [
              "sort",
              "reimbursementCode",
              "statusName",
              "costStatus",
              "employeeName",
              "declareTypeName",
              "serviceCost",
              "declareDate",
              "declareReason",
              "postData",
              "remark",
            ],
            tableDatas: this.download.list,
            sheetName: "Sheet1",
          },
        ];
        json2excel(excelDatas, "报销申请", true, "xlsx");
      });
    },

    // 导入
    form_inport() {
      console.log("点击了导入");
    },

    printTable1() {
      console.log(this.tableTravelList);

      var table = [
        //  {"name1":0,"name2":944.39,"name3":314.8,"sumlweight":128.66},
        //  {"name1":10,"name2":944.39,"name3":314.8,"sumlweight":128.66},
      ];

      var table = JSON.parse(JSON.stringify(this.tableTravelList));

      var dataTable = [
        { field: "businessDate", columnSize: 0, displayName: "日期" },
        { field: "businessAdress", columnSize: 1, displayName: "出差地" },
        { field: "clienter", columnSize: 2, displayName: "拜见人" },
        { field: "toll", columnSize: 3, displayName: "交通费（差旅）" },
        { field: "oilCost", columnSize: 4, displayName: "油费（差旅）" },
        { field: "hotelCost", columnSize: 5, displayName: "住宿费（差旅）" },
        { field: "serviceCost", columnSize: 6, displayName: "业务招待费" },
        { field: "otherCost", columnSize: 7, displayName: "其他费用" },
        { field: "sumPrice", columnSize: 8, displayName: "合计" },
        { field: "travelCode", columnSize: 9, displayName: "出差单号" },
      ];

      var new_data = {
        businessDate: "合计",
        businessAdress: "",
        clienter: "",
        toll: 0,
        oilCost: 0,
        hotelCost: 0,
        serviceCost: 0,
        otherCost: 0,
        sumPrice: 0,
        travelCode: "",
        businesstravelId: "",
        tableTravelId: "",
        NoEdit: false,
        Edit: true,
      };

      table.forEach(function (item) {
        new_data.toll = new_data.toll + parseFloat(item.toll);
        new_data.oilCost = new_data.oilCost + parseFloat(item.oilCost);
        new_data.hotelCost = new_data.hotelCost + parseFloat(item.hotelCost);
        new_data.serviceCost =
          new_data.serviceCost + parseFloat(item.serviceCost);
        new_data.otherCost = new_data.serviceCost + parseFloat(item.otherCost);
        new_data.sumPrice = new_data.sumPrice + parseFloat(item.sumPrice);
      });

      table.push(new_data);
      printJS({
        printable: table,
        properties: dataTable,
        type: "json",
        header: `<div style="display: flex;flex-direction: column;text-align: center">
                        <h3>上海科湃腾信息科技有限公司出差费用报销表</h3>
                        <p style="margin-bottom: 20px;font-size: 16px;">
                          <span style="padding-right: 50px;display:inline-block"> 报销人：${this.create.temp.employeeName}</span> 
                          <span style="padding-right: 60px;;padding-left: 50px;display:inline-block"> 时间：${this.create.temp.billDate}<span> 
                          <span style="padding-right: 50px;padding-left: 80px;display:inline-block"> 总价：${this.sumPriceAll1}<span> 
                        </p>
                        <div style="margin-bottom: 20px;font-size: 16px;width:100%;line-height:1">
                          <span style="padding-right: 40px;display:inline-block"> 总经理： </span> 
                          <span style="padding-right: 100px;display:inline-block"> 部门经理： </span> 
                          <span style="padding-right: 40px;display:inline-block"> 审核： </span> 
                          <span style="padding-right: 100px;display:inline-block"> 出纳： </span> 
                          <span style="padding-right: 40px;display:inline-block"> 领款人： </span> 
                        </div>
                    </div>`,
        //样式设置
        gridStyle: "border:1px solid #ccc;text-align:center",
        gridHeaderStyle: "border:1px solid #ccc;text-align:center",
      });
    },
    //微信推送
    get_wxPush(remindId, remindTypeName, rowId) {
      var send_weixin_data1 = {
        name: "getRemindData",
        parammaps: {
          userId: Cookies.get("g_userId"),
          remindId: remindId,
          remindTypeName: remindTypeName,
          rowId: rowId,
        },
      };

      GetDataByName(send_weixin_data1).then((response) => {
        console.log("微信推送(获取参数)======>", response);
        if (response.data.message == "ok") {
          var receiverStr = response.data.list[0].receivers;
          var receiverArr = receiverStr.split(",");
          var value1 = response.data.list[0].value1;
          var value2 = response.data.list[0].value2;
          var value3 = response.data.list[0].value3;
          var value4 = response.data.list[0].value4;
          var send_weixin_data2 = {
            target: receiverArr,
            serviceId: remindId,
            content: [
              { color: "#173177", value: value1 },
              { color: "#173177", value: value2 },
              { color: "#173177", value: value3 },
              { color: "#173177", value: value4 },
            ],
          };

          wxpush(send_weixin_data2).then((response) => {
            console.log("微信推送(获取参数)======>", response);
          });
          // this.tableSumMoney = response.data.list[0].totlePrice
        } else {
          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
        }
      });
    },

    printTable2() {
      console.log(this.tableBuyList);

      var table = [
        //  {"name1":0,"name2":944.39,"name3":314.8,"sumlweight":128.66},
        //  {"name1":10,"name2":944.39,"name3":314.8,"sumlweight":128.66},
      ];

      var table = JSON.parse(JSON.stringify(this.tableBuyList));

      var new_data2 = {
        purchaseDate: "",
        goodsType: "合计",
        goodsName: "",
        goodsNum: 0,
        company: "",
        goodsPrice: 0,
        sumPrice: 0,
        tableBuyId: "",
        NoEdit: false,
        Edit: true,
      };

      table.forEach(function (item) {
        new_data2.goodsNum = new_data2.goodsNum + parseFloat(item.goodsNum);
        // new_data2.goodsPrice = new_data2.goodsPrice + parseFloat(item.goodsPrice)
        new_data2.sumPrice = new_data2.sumPrice + parseFloat(item.sumPrice);
      });

      table.push(new_data2);

      var dataTable = [
        { field: "goodsType", columnSize: 0, displayName: "类型" },
        { field: "goodsName", columnSize: 1, displayName: "名称" },
        { field: "purchaseDate", columnSize: 2, displayName: "购买日期" },
        { field: "goodsNum", columnSize: 3, displayName: "数量" },
        { field: "company", columnSize: 4, displayName: "单位名称" },
        { field: "goodsPrice", columnSize: 5, displayName: "单价" },
        { field: "sumPrice", columnSize: 8, displayName: "合计" },
      ];
      printJS({
        printable: table,
        properties: dataTable,
        type: "json",
        header: `<div style="display: flex;flex-direction: column;text-align: center">
                        <h3>上海科湃腾信息科技有限公司采购费用报销表</h3>
                      
                        <p style="margin-bottom: 20px;font-size: 16px;">
                          <span style="padding-right: 50px;display:inline-block"> 报销人：${this.create.temp.employeeName}</span> 
                          <span style="padding-right: 60px;;padding-left: 50px;display:inline-block"> 时间：${this.create.temp.billDate}<span> 
                          <span style="padding-right: 50px;padding-left: 80px;display:inline-block"> 总价：${this.sumPriceAll2}<span> 
                        </p>
                        <div style="margin-bottom: 20px;font-size: 16px;width:100%;line-height:1">
                          <span style="padding-right: 40px;display:inline-block"> 总经理： </span> 
                          <span style="padding-right: 100px;display:inline-block"> 部门经理： </span> 
                          <span style="padding-right: 40px;display:inline-block"> 审核： </span> 
                          <span style="padding-right: 100px;display:inline-block"> 出纳： </span> 
                          <span style="padding-right: 40px;display:inline-block"> 领款人： </span> 
                        </div>
                    </div>`,
        //样式设置
        gridStyle: "border:1px solid #ccc;text-align:center",
        gridHeaderStyle: "border:1px solid #ccc;text-align:center",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.search {
  padding-top: 10px;
  clear: both;
}
.table {
  margin-top: 10px;
}

/deep/ .el-input.is-disabled .el-input__inner {
  color: #000000 !important;
}
/deep/ .el-textarea.is-disabled .el-textarea__inner {
  color: #000000 !important;
}
/deep/ .el-radio__input.is-disabled + span.el-radio__label {
  color: #000000 !important;
}
/deep/ .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000 !important;
}
</style>
