<template>
  <div>
    <el-card>
      <el-form v-if="queryList && queryList.length > 0 " :model="filterQuery" class="query-form"
               @submit.native.prevent
               size="mini" label-width="100px">
        <el-row style=" display:flex;  flex-wrap: wrap; ">
          <template v-for="(item, index) in queryList">
            <div v-if="showSearch || item.isImport">
              <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`" :key="item.id">
                <el-input
                  v-model="filterQuery[item.columnName]"
                  :placeholder="item.columnDesc == '模糊查询' ? '单据号/单据类型/收货方/发货方' : item.columnDesc"
                  :disabled="executeEval(null,item.disabledFuc,false)"
                  @keyup.enter.native="executeFuc($event,'5',item.clickFuc)"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'select' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`">
                <el-select v-model="filterQuery[item.columnName]"
                           :placeholder="item.columnDesc"
                           :disabled="executeEval(null,item.disabledFuc,false)"
                           clearable>
                  <el-option
                    v-for="dict in item.lableRuleObj"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>

              </el-form-item>
              <el-form-item v-if="item.columnType == 'selectServer' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`">
                <el-select
                  v-model="filterQuery[item.columnName]"
                  :placeholder="item.columnDesc"
                  @change="executeFuc($event,'5',item.checkRules)"
                  :disabled="executeEval(null,item.disabledFuc,false)"
                  filterable
                  remote
                  clearable>
                  <el-option
                    v-for="item in options[item.clickFuc]"
                    :key="item.code"
                    :label="item.label"
                    :value="item.code"
                  />
                </el-select>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'datePicker' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`">
                <el-date-picker
                  :picker-options="pickerOptions"
                  v-model="actDateRange"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'date' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`">
                <el-date-picker
                  v-model="filterQuery[item.columnName]"
                  :style="`width:${item.width+'px'}`"
                  value-format="yyyy-MM-dd"
                  :disabled="executeEval(null,item.disabledFuc,false)"
                  type="date"
                  :placeholder="item.columnDesc"
                ></el-date-picker>
              </el-form-item>
            </div>
          </template>
        </el-row>
      </el-form>
      <!--      <div class="left-search" v-if="!showSearch">-->
      <!--        &lt;!&ndash; 关键字搜索 按需配置 &ndash;&gt;-->
      <!--        <el-form v-if="queryList && queryList.length > 0" :model="filterQuery" class="query-form" size="mini"-->
      <!--                 label-width="100px">-->
      <!--          <el-row style=" display:flex;  flex-wrap: wrap; ">-->
      <!--            <template v-for="(item, index) in queryList">-->
      <!--              <el-form-item-->
      <!--                v-if="item.columnType == 'input' && executeEval(row,item.expression,true) && item.columnName == 'keywords'"-->
      <!--                class="query-form-item"-->
      <!--                :label="item.columnDesc+`:`" :key="item.id">-->
      <!--                <el-input-->
      <!--                  v-model="filterQuery[item.columnName]"-->
      <!--                  :placeholder="item.columnDesc"-->
      <!--                  :disabled="executeEval(null,item.disabledFuc,false)"-->
      <!--                  @keyup.enter.native="executeFuc($event,'5',item.clickFuc)"-->
      <!--                  clearable-->
      <!--                ></el-input>-->
      <!--              </el-form-item>-->
      <!--            </template>-->
      <!--          </el-row>-->
      <!--        </el-form>-->
      <!--      </div>-->
      <div class="top-right-btn">
        <el-button-group style="display:flex;">
          <el-button icon="el-icon-view" type="primary" @click="hideSearch">高级查询</el-button>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onReset"
          >重置
          </el-button>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit(this)"
          >查询
          </el-button
          >
          <el-upload
            :action="action"
            :headers ="headers"
            accept=".xlsx,.xls"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :on-success="handleSuccess"
            :on-progress="handleProgress"
            :on-error="handleError"
            :before-upload="beforeUpload"
            :limit="1"
            :on-exceed="handleExceed"
            :file-list="fileList"
            :show-file-list="false"
            :data="extraData">
            <el-button  icon="el-icon-upload" type="primary" >手动上传数据</el-button>
          </el-upload>
          <el-button type="primary" icon="el-icon-download" @click="downloadData"
          >下载数据
          </el-button
          >
          <el-button type="primary" icon="el-icon-download" @click="downloadPrescription"
          >初始化演示数据
          </el-button
          >
          <el-button type="primary" icon="el-icon-delete" @click="clearAllOrder"
          >清除演示数据
          </el-button
          >
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>
      <el-tabs type="border-card" style="margin-top: 55px">
        <el-tab-pane label="原始单据">
          <el-table v-loading="loading" :data="list" style="width: 100%;" border highlight-current-row
                    @row-click="(row) => executeFuc(row,'0',tableObj.handleChangeFuc)" ref="multipleTable"
                    :default-sort="defaultSort"
                    :row-style="{ height: '32px' }"
                    @sort-change="handleSortChange">
            <template v-for="(item, index) in tableHeader">
              <el-table-column
                v-if="item.columnType == 'id' && executeEval(row,item.expression,true)"
                type="index" :label="item.columnDesc"></el-table-column>
              <el-table-column
                v-if="item.columnType == 'selection'"
                type="selection"
                :width="item.width"
                :selectable="(row,number) => executeFuc(row,'3',item.clickFuc)"
              ></el-table-column>

              <el-table-column
                v-if="item.columnType == 'radio' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
                  <el-radio :label="scope.row.id" v-model="radioCheck"><span></span></el-radio>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'laber' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
            <span :style="{color: executeFuc(scope.row,'4',item.lableRuleObj[scope.row[item.columnName]])}">{{
                item.lableRuleObj[scope.row[item.columnName]]
              }}</span>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'eltag' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
                  <el-tag
                    :type="executeFuc(scope.row,'4',item,item.lableRuleObj?item.lableRuleObj[scope.row[item.columnName]]:scope.row[item.columnName])">
              <span>{{
                  item.lableRuleObj ? item.lableRuleObj[scope.row[item.columnName]] : scope.row[item.columnName]
                }}</span>
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'button' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :width="item.width"
                :key="item.columnName"
                fixed="right"
              >
                <template slot-scope="scope">
                  <el-button v-for="(buttonItem, buttonIndex) in item.buttonRulObj"
                             :type="buttonItem.type"
                             :size="buttonItem.size"
                             :style="buttonItem.style"
                             :key="buttonItem"
                             v-if="executeEval(scope.row,buttonItem.hasPermi,true)"
                             :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"
                             @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"
                  >{{ buttonItem.name }}
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'text' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
            <span :style="{color: executeFuc(scope.row,'4',item,scope.row[item.columnName])}">{{
                scope.row[item.columnName]
              }}</span>
                </template>
              </el-table-column>
            </template>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :limit.sync="filterQuery.limit"
            :page.sync="filterQuery.page"
            @pagination="handleCurrentChange"
          ></pagination>
        </el-tab-pane>
        <el-tab-pane label="异常单据">
          <el-table v-loading="loading" :data="errList" style="width: 100%;" border highlight-current-row
                    @row-click="(row) => executeFuc(row,'0',tableObj1.handleChangeFuc)" ref="multipleTable"
                    :default-sort="defaultSort"
                    :row-style="{ height: '32px' }"
                    @sort-change="handleSortChange">
            <template v-for="(item, index) in tableHeader1">
              <el-table-column
                v-if="item.columnType == 'id' && executeEval(row,item.expression,true)"
                type="index" :label="item.columnDesc"></el-table-column>
              <el-table-column
                v-if="item.columnType == 'selection'"
                type="selection"
                :width="item.width"
                :selectable="(row,number) => executeFuc(row,'3',item.clickFuc)"
              ></el-table-column>

              <el-table-column
                v-if="item.columnType == 'radio' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
                  <el-radio :label="scope.row.id" v-model="radioCheck"><span></span></el-radio>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'laber' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
            <span :style="{color: executeFuc(scope.row,'4',item.lableRuleObj[scope.row[item.columnName]])}">{{
                item.lableRuleObj[scope.row[item.columnName]]
              }}</span>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'eltag' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
                  <el-tag
                    :type="executeFuc(scope.row,'4',item,item.lableRuleObj?item.lableRuleObj[scope.row[item.columnName]]:scope.row[item.columnName])">
              <span>{{
                  item.lableRuleObj ? item.lableRuleObj[scope.row[item.columnName]] : scope.row[item.columnName]
                }}</span>
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'button' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :width="item.width"
                :key="item.columnName"
                fixed="right"
              >
                <template slot-scope="scope">
                  <el-button v-for="(buttonItem, buttonIndex) in item.buttonRulObj"
                             :type="buttonItem.type"
                             :size="buttonItem.size"
                             :style="buttonItem.style"
                             :key="buttonItem"
                             v-if="executeEval(scope.row,buttonItem.hasPermi,true)"
                             :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"
                             @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"
                  >{{ buttonItem.name }}
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column
                v-if="item.columnType == 'text' && executeEval(row,item.expression,true)"
                :prop="item.columnName"
                :label="item.columnDesc"
                :sortable="item.sort"
                :width="item.width"
                :show-overflow-tooltip="item.tooltip"
                :key="item.columnName"
              >
                <template slot-scope="scope">
            <span :style="{color: executeFuc(scope.row,'4',item,scope.row[item.columnName])}">{{
                scope.row[item.columnName]
              }}</span>
                </template>
              </el-table-column>
            </template>
          </el-table>
          <pagination
            v-show="errTotal>0"
            :total="errTotal"
            :limit.sync="errQuery.limit"
            :page.sync="errQuery.page"
            @pagination="handleCurrentChangeError"
          ></pagination>
        </el-tab-pane>
      </el-tabs>


    </el-card>
    <el-tabs type="border-card" style="margin: 15px">
      <el-tab-pane label="单据明细">
        <PannelOriginOrderDetail
          v-if="panelALive"
          :prescribeData="curRow"
        ></PannelOriginOrderDetail>
      </el-tab-pane>
    </el-tabs>

    <el-dialog
      title="下载单据"
      :visible.sync="downloadPrescriptionVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-if="downloadPrescriptionVisible"
      width="75%"
      append-to-body
    >
      <prescribeDownloadDialog
        :closeDialog="this.closeDialog"
      ></prescribeDownloadDialog>
    </el-dialog>

  </div>
</template>

<script>
import addOrder from "@/views/inout/DialogCreateOrder";
import errOrder from "@/views/inout/IoCreateErrorOrder";
import {executeFuc, getHead} from "@/utils/customConfig";
import {convertDate} from "@/utils/date";
import {detail} from "@/api/basic/sicker/prescribeApi";
import prescribeDownloadDialog from "@/views/collect/prescribe/prescribeDownloadDialog";
import prescribeOriginPanel from "./PannelOrderBiz";
import PannelOriginOrderDetail from "./PannelOriginOrderDetail"
import {
  clearAllOrder,
  deleteByOrder,
  importOrder,
  downloadOrder,
  errorHandle, errorHandleSubmit, deleteOriginOrder
} from "@/api/collect/collectOrder";
import {
  orderPage,
} from "@/api/collect/collectOriginOrder";
import {filterSubAllOptimize} from "@/api/system/invSubWarehouse";
import {filterWorkOptimize} from "@/api/basic/workPlace/sysWorkplaceManage";
import {getWorkBindBusTypes} from '@/api/basic/workPlace/sysWorkplaceDocuments'
import {getAdminId, getToken} from '@/utils/auth';

export default {
  name: "prescribePanel",
  props: {
    tagStatus: {
      type: Number,
      required: true
    },
    tagStatusList: {
      type: Array,
      required: true
    },
  },
  data() {
    return {
      actDateRange: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      //界面配置相关
      //患者处方
      tableHeader: [],
      queryList: [],
      tableObj: [],
      fromList: [],
      //原始处方明细
      tableHeader1: [],
      queryList1: [],
      tableObj1: [],
      fromList1: [],
      convertDateFun: convertDate,
      //界面配置-------------end

      showSearch: false,
      filterQuery: {
        // tagStatus: this.tagStatus,    //
        tagStatusList: [0, 1, 2,3],    //
        billNo: null,
        busType: null,
        workPlaceCode: null,
        startTime: null,
        endTime: null,
        page: 1,
        limit: 10,
      },

      errQuery: {
        tagStatusList: [4],    //
        page: 1,
        limit: 10,
      },
      DataQuery: {
        busType: null,
        page: 1,
        limit: 10,
      },
      defaultSort: {prop: 'createTime', order: 'desc'},
      loading: false,
      list: [],
      total: 0,


      errList: [],
      errTotal: 0,
      downloadPrescriptionVisible: false,
      deleteData: {
        billNo: null,
      },
      options: {
        sysWorkspace: [],
        findWorkPlace: [],
        getBusType: []
      },

      preLoading: false,
      preDetailList: [],
      preTotal: 0,
      preQuery: {
        prescribeCode: null,
        page: 1,
        limit: 10,
      },
      curRow: null,
      panelALive: false,
      busQuery: {
        busKey: '',
        workplaceCode: null,
        page: 1,
        limit: 100
      },
      errQueryPage: 1,
      headers:{
        ADMINID: getAdminId(),
        ADMINTOKEN: getToken()
      },
      extraData:{"uuid": "upload-xlsx"},
      uploadLoading: false,
      action: process.env.VUE_APP_BASE_API + "/udiwms/collect/order/xlsxUpload",
      fileList: []
    }
  },

  components: {
    addOrder, errOrder, prescribeDownloadDialog, prescribeOriginPanel, PannelOriginOrderDetail
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      // this.$message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      // return this.$confirm(`确定移除 ${ file.name }？`);
    },
    handleSuccess(res, file, fileList) {
      fileList = fileList.filter(item => item.response.code === 20000);
      this.fileList = fileList;
      if (res.code === 20000) {
        this.$message.success(res.message);
        this.fileList = []
      } else {
        this.$message.error(res.message);
      }
      this.uploadLoading.close();
    },
    beforeUpload(file) {
      const isXML = file.name.endsWith('.xls');
      const isXML2 = file.name.endsWith('.xlsx');
      const isLt5M = file.size / 1024 / 1024 < 100;
      if (!isXML &&!isXML2) {
        this.$message.error('上传文件只能是 xls 格式!');
      }
      if (!isLt5M) {
        this.$message.error('上传文件大小不能超过 10MB!');
      }
      return (isXML || isXML2) && isLt5M;
    },
    handleProgress() {
      this.uploadLoading = this.$loading({
        lock: true,
        text: '文件上传中…',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)'
      });
    },
    handleError() {
      this.uploadLoading.close();
      this.$message.error('文件上传失败，请检查文件大小或文件格式');
    },
    //界面配置相关------------
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value);
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression);
      }
      return defaultRet;
    },
    handleSortChange(column, prop, order) {
      if (column.order === 'descending') {
        this.query.sort = 'desc'
      } else {
        this.query.sort = 'asc'
      }
      this.query.orderBy = column.prop;
      this.getList();
    },
    ///界面配置相关------------end

    hideSearch() {
      this.showSearch = !this.showSearch;
      this.$nextTick(() => {
        console.log('组件已刷新');
      });
    },
    onReset() {
      this.filterQuery = {
        tagStatusList: [0, 1, 2,3],
        billNo: null,
        busType: null,
        workPlaceCode: null,
        page: 1,
        limit: 10,
      };
      this.errQuery = {
        tagStatusList: [4],    //
        page: 1,
        limit: 10,
      },
        this.actDateRange = [];
      this.getList();
      this.getErrorList(this);
      this.panelALive = false
    },
    downloadPrescription() {
      this.downloadPrescriptionVisible = true
      // this.loading = true;
      // importOrder().then(res => {
      //     this.loading = false
      //     if (res.code == 20000) {
      //       this.$message.success("下载成功！")
      //       this.getList()
      //     } else {
      //       this.$message.error(res.message)
      //     }
      //   }
      // ).catch(() => {
      //   this.loading = false
      // })
    },
    downloadData() {
      this.downloadPrescriptionVisible = true
      // if (this.filterQuery.workPlaceCode == null) {
      //   return this.$message.error("请先选择工位")
      // }

      // if (this.actDateRange !== null) {
      //   this.filterQuery.startTime = this.actDateRange[0];
      //   this.filterQuery.endTime = this.actDateRange[1];
      // } else {
      //   this.filterQuery.startTime = null;
      //   this.filterQuery.endTime = null;
      // }
      //
      // this.filterQuery.busType = '24'
      // // downloadOrder(this.filterQuery).then(res => {
      //     getThrOrderPage(this.filterQuery).then(res => {
      //   if (res.code == 20000) {
      //     return this.$message.success(res.data)
      //   } else {
      //     return this.$message.error(res.message)
      //   }
      // })
    },
    clearAllOrder() {
      this.loading = true;
      clearAllOrder().then(res => {
        this.loading = false
        if (res.code == 20000) {
          this.$message.success("清除成功！")
          this.getList()
          this.getErrorList(this)
        } else {
          this.$message.error(res.message)
        }
      }).catch(() => {
        this.loading = false
      })
    }
    ,
    closeDialog() {
      this.downloadPrescriptionVisible = false;
      this.getList();
      this.getErrorList(this);
    }
    ,
    onSubmit(_this) {
      if (_this == null)
        _this = this
      _this.filterQuery.page = 1;
      _this.getList();
      _this.getErrorList(_this);
    }
    ,

    getList() {
      this.loading = true;
      if (this.actDateRange !== null) {
        this.filterQuery.startTime = this.actDateRange[0];
        this.filterQuery.endTime = this.actDateRange[1];
      } else {
        this.filterQuery.startTime = null;
        this.filterQuery.endTime = null;
      }
      orderPage(this.filterQuery).then(res => {
        this.loading = false
        this.list = res.data.list || []
        this.total = res.data.total || 0
      }).catch(() => {
        this.loading = false
        this.list = []
        this.total = 0
      })
    },

    getErrorList(_this) {
      Object.assign(_this.errQuery, _this.filterQuery)
      _this.errQuery.page = _this.errQueryPage
      _this.loading = true;
      if (_this.actDateRange !== null) {
        _this.errQuery.startTime = _this.actDateRange[0];
        _this.errQuery.endTime = _this.actDateRange[1];
      } else {
        _this.errQuery.startTime = null;
        _this.errQuery.endTime = null;
      }
      // _this.errQuery = _this.filterQuery
      _this.errQuery.tagStatus = 4;
      _this.errQuery.tagStatusList = [4]
      orderPage(_this.errQuery).then(res => {
        _this.loading = false
        _this.errList = res.data.list || []
        _this.errTotal = res.data.total || 0
      }).catch(() => {
        _this.loading = false
        _this.errList = []
        _this.errTotal = 0
      })
    },

    getList2(_this) {
      _this.loading = true;
      if (_this.actDateRange !== null) {
        _this.filterQuery.startTime = _this.actDateRange[0];
        _this.filterQuery.endTime = _this.actDateRange[1];
      } else {
        _this.filterQuery.startTime = null;
        _this.filterQuery.endTime = null;
      }
      orderPage(_this.filterQuery).then(res => {
        _this.loading = false
        _this.list = res.data.list || []
        _this.total = res.data.total || 0
      }).catch(() => {
        _this.loading = false
        _this.list = []
        _this.total = 0
      })
    }
    ,
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    handleCurrentChangeError(val) {
      this.errQuery.page = val.page;
      this.errQueryPage = val.page
      this.getErrorList(this);
    }
    ,

    prescribeClick(_this, row) {
      _this.curRow = row;
      _this.refreshCodesPanel(_this);
    }
    ,
    refreshCodesPanel(_this) {
      _this.panelALive = false;
      _this.$nextTick(() => {
        _this.panelALive = true;
      });
    }
    ,

    deleteDialog(_this, row) {
      _this.$confirm("此操作将永久删除该订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          _this.deleteOrders(row.billNo);
        })
        .catch(() => {
        });
    }
    ,
    deleteOrders(data) {
      this.loading = true;
      this.deleteData.billNo = data;
      deleteOriginOrder(this.deleteData)
        .then((response) => {
          if (response.code == 20000) {
            this.getList();
            this.getErrorList(this);
            this.panelALive = false
            this.$message({
              type: "success",
              message: "删除成功！",
            });
          } else if (response.code == 520) {
            this.$message.error(response.message);
            this.getList();
            this.getErrorList(this);
          } else {
            this.$message.error(response.message);
            this.getList();
            this.getErrorList(this);
          }

        })
        .catch(() => {
        });
    }
    ,
    findWorkPlace(_this, val) {
      let query = {
        userIdFlag: true,
        key: val,
        page: 1,
        limit: 10
      }
      filterWorkOptimize(query)
        .then((response) => {
          _this.loading = false
          _this.options.findWorkPlace = response.data || []
          if (_this.options.findWorkPlace.length == 1) {
            _this.filterQuery.workPlaceCode = _this.options.findWorkPlace[0].code
            _this.getWorkBindBusTypes(_this, _this.filterQuery.workPlaceCode)
          }
        })
        .catch(() => {
          _this.loading = false
          _this.options.findWorkPlace = []
        })
    },
    changePlace(_this, query) {
      _this.getWorkBindBusTypes(_this, query)
    },
    getWorkBindBusTypes(_this, query) {
      _this.busQuery.workplaceCode = query
      getWorkBindBusTypes(this.busQuery).then(res => {
        if (res.code == 20000) {
          let busTypes = res.data.list || [];
          // _this.options.getWorkPlace = res.data.list || [];
          let getWorkPlace = busTypes.map(busType => {
            return {
              code: busType.documentTypeCode,
              label: busType.busName
            };
          });
          _this.options.getBusType = getWorkPlace
          if (_this.options.getBusType.length == 1) {
            _this.filterQuery.busType = _this.options.getBusType[0].code
          } else {
            _this.filterQuery.busType = null
          }
        }
        return
      })
    },

    submitDialog() {

    },

    errorHandle(_this, row) {
      _this.$confirm("此操作将重新下载该订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.loading = true;
          let params = {
            billNo: row.billNo,
            busType: row.busType,
            workPlaceCode: row.workPlaceCode,
            tagStatus: row.tagStatus,
            fromTpye: row.fromTpye,
          };
          errorHandle(params)
            .then((response) => {
              if (response.code == 20000) {
                this.getErrorList(_this);
                _this.$message.success("处理成功！")
              } else if (response.code == 520) {
                _this.$message.error(response.message);
                this.getErrorList(_this);
              } else {
                _this.$message.error(response.message);
                this.getErrorList(_this);
              }
            })
            .catch(() => {
            });
        })
        .catch(() => {
        });
    },
    errorHandleSubmit(_this, row) {
      _this.$confirm("此操作将提交该订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.loading = true;
          let params = {
            billNo: row.billNo,
            busType: row.busType,
            workPlaceCode: row.workPlaceCode,
            tagStatus: row.tagStatus,
            fromTpye: row.fromTpye,
          };
          errorHandleSubmit(params)
            .then((response) => {
              if (response.code == 20000) {
                _this.getErrorList(_this);
                _this.getList();
                _this.$message.success("处理成功！")
              } else if (response.code == 520) {
                _this.$message.error(response.message);
                this.getErrorList(_this);
              } else {
                _this.$message.error(response.message);
                this.getErrorList(_this);
              }
            })
            .catch(() => {
            });
        })
        .catch(() => {
        });
    },
  },
  created() {
    getHead("prescribeDownloadOrigin", "1").then((re) => {
      // 处理返回的数据
      this.tableObj = re.data;
      this.tableHeader = re.data.tableList;
      this.queryList = re.data.queryList;
      this.fromList = re.data.fromList;
      this.getList();
    });
    getHead("prescribeDownloadError", "1").then((re) => {
      // 处理返回的数据
      this.tableObj1 = re.data;
      this.tableHeader1 = re.data.tableList;
      // this.queryList1 = re.data.queryList;
      this.fromList1 = re.data.fromList;
      this.getErrorList(this);
    });


    // this.filterQuery.tagStatus = String(this.tagStatus)
    // this.filterQuery.tagStatusList = this.tagStatusList
    this.findWorkPlace(this, '')
    this.getWorkBindBusTypes(this, '')
  }

}
</script>

<style scoped>
.query-form {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

.query-form-item {
  margin-right: 5px;
  margin-bottom: 6px;
}
</style>
