<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px">
      <el-form-item label="任务编码" prop="issueNum">
        <el-input
          v-model="queryParams.issueNum"
          placeholder="请输入编码/名称"
          clearable
          size="mini"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="物料编码" prop="signCode">
        <el-input
          v-model="queryParams.signCode"
          placeholder="请输入物料编码"
          clearable
          size="mini"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      -->
      <el-form-item label="物料类型" prop="materialType">
        <el-select
          v-model="queryParams.materialType"
          size="mini"
          clearable
          filterable
          @change="materialTypeChangeQuery">
          <el-option
            v-for="item in materialTypeOption"
            :key="item.signType"
            :label="item.signType"
            :value="item.signType" />
        </el-select>
      </el-form-item>
      <el-form-item label="物料名称" prop="materialName">
        <el-select
          v-model="queryParams.materialName"
          size="mini"
          clearable
          filterable
          @change="onInput()">
          <el-option
            v-for="item in materialNameOptionQuery"
            :key="item.signName"
            :label="item.signName"
            :value="item.signName" />
        </el-select>
      </el-form-item>
      <el-form-item label="任务状态" prop="taskstatus">
        <el-select
          v-model="queryParams.taskstatus"
          placeholder="请选择任务状态"
          clearable
          size="mini"
          @change="onInput()">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>

      <el-form-item label="签收状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择任务状态"
          clearable
          size="mini"
          @change="onInput()">
          <el-option
            v-for="dict in statusOptions2"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="发布时间" prop="issueTime" @change="onInput()" size="mini">
        <el-date-picker
          v-model="issueTime"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="收货时间" prop="signTime" @change="onInput()" size="mini">
        <el-date-picker
          v-model="signTime"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['guide:signuser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['guide:signuser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['guide:signuser:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['guide:signuser:export']"
          >导出</el-button
        >
      </el-col>

      <el-col :span="3">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="addStoreImport"
          >导入快递单号</el-button
        >
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :key="tablenum"
      :data="signuserList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="任务编码" prop="task_code" width="100" />
      <el-table-column label="任务名称" prop="task_name" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span class="linkks" @click="openDetail(scope.row)">{{ scope.row.task_name }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="任务状态" align="center" prop="taskstatus" />-->
      <el-table-column label="任务状态" align="center" prop="taskstatus" width="140">
        <template slot-scope="scope">
          <dicts-tag :options="statusOptions" :value="scope.row.taskstatus" />
        </template>
      </el-table-column>
      <!--
      <el-table-column label="签收职位" align="center" prop="position" />
-->
      <el-table-column
        label="费用中心"
        prop="receive_deptname"
        width="160"
        :show-overflow-tooltip="true" />
      <el-table-column label="收件组织" prop="org_name" width="160" :show-overflow-tooltip="true" />
      <el-table-column
        label="接收人"
        prop="receiveName"
        width="140"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="接收人编码"
        prop="receiveNum"
        width="180"
        :show-overflow-tooltip="true" />
      <el-table-column label="签发号" prop="issue_num" width="140" :show-overflow-tooltip="true" />
      <el-table-column
        label="签发号发布时间"
        align="center"
        prop="create_time"
        width="160"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="发放数量"
        align="right"
        prop="issuing_num"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="发货时间"
        align="center"
        prop="issuing_time"
        width="160"
        :show-overflow-tooltip="true" />
      <el-table-column label="发放人" prop="issuer" width="140" :show-overflow-tooltip="true" />
      <el-table-column
        label="快递单号"
        prop="tracking_num"
        width="140"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="收货数量"
        align="right"
        prop="sign_num"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="剩余数量"
        align="right"
        prop="remaining_num"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column label="收货人" prop="sign_name" width="140" :show-overflow-tooltip="true" />
      <el-table-column
        label="收货时间"
        align="center"
        prop="sign_time"
        width="160"
        :show-overflow-tooltip="true" />
      <!--      <el-table-column label="签收状态" align="center" prop="status" />-->

      <el-table-column label="签收状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <!--                  <span>{{statusFormat2(scope.row)}}</span>-->
          <dicts-tag :options="statusOptions2" :value="scope.row.status.toString()" />
        </template>
      </el-table-column>

      <el-table-column label="签收图片" align="center" prop="signurl" width="100">
        <template slot-scope="scope">
          <!--<img :src="scope.row.signurl" width="90%"/>-->
          <el-image
            style="height: 26px"
            :src="scope.row.signurl"
            :preview-src-list="getSignUrlArray(scope.row.signurl)">
            <div slot="error">
              <span style="color: #999">暂无图片</span>
            </div>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="快递单图片" align="center" prop="tracking_img" width="100">
        <template slot-scope="scope">
          <!--<img :src="scope.row.signurl" width="90%"/>-->
          <el-image
            style="height: 26px"
            :src="scope.row.tracking_img"
            :preview-src-list="getSignUrlArray(scope.row.tracking_img)">
            <div slot="error">
              <span style="color: #999">暂无图片</span>
            </div>
          </el-image>
        </template>
      </el-table-column>
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['guide:signuser:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['guide:signuser:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog
      class="upload"
      :title="upload2.title"
      :visible.sync="upload2.open"
      width="400px"
      append-to-body>
      <div style="margin-bottom: 14px">
        <el-link type="primary" style="font-size: 14px" @click="importTemplate">下载模板</el-link>
      </div>

      <el-upload
        ref="upload2"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload2.headers"
        :action="upload2.url + '?updateSupport=' + upload2.updateSupport"
        :disabled="upload2.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>

        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm" :disabled="upload2.isUploading"
          >确 定</el-button
        >
        <el-button @click="upload2.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改物料签收明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="签发号" prop="issueNum">
          <el-input v-model="form.issueNum" placeholder="请输入签发号" />
        </el-form-item>
        <el-form-item label="发放人" prop="issuer">
          <el-input v-model="form.issuer" placeholder="请输入发放人" />
        </el-form-item>
        <el-form-item label="发放人编码" prop="issuerCode">
          <el-input v-model="form.issuerCode" placeholder="请输入发放人编码" />
        </el-form-item>
        <el-form-item label="接收部门名称" prop="receiveDeptname">
          <el-input v-model="form.receiveDeptname" placeholder="请输入接收部门名称" />
        </el-form-item>
        <el-form-item label="接收部门编码" prop="receiveDeptcode">
          <el-input v-model="form.receiveDeptcode" placeholder="请输入接收部门编码" />
        </el-form-item>
        <el-form-item label="1 有效  0 无效" prop="isValid">
          <el-input v-model="form.isValid" placeholder="请输入1 有效  0 无效" />
        </el-form-item>
        <el-form-item label="快递单号" prop="tracking Num">
          <el-input v-model="form.trackingNum" placeholder="请输入快递单号" />
        </el-form-item>
        <el-form-item label="物料发放数量" prop="issuingNum">
          <el-input v-model="form.issuingNum" placeholder="请输入物料发放数量" />
        </el-form-item>
        <el-form-item label="物料签收数量" prop="signNum">
          <el-input v-model="form.signNum" placeholder="请输入物料签收数量" />
        </el-form-item>
        <el-form-item label="发货时间" prop="issuingTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.issuingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择发货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="签收时间" prop="signTime">
          <el-date-picker
            clearable
            size="small"
            v-model="form.signTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择签收时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="0 未发布 1 待发货 2 已发货 3 已签收 4作废">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="签收人名称" prop="signName">
          <el-input v-model="form.signName" placeholder="请输入签收人名称" />
        </el-form-item>
        <el-form-item label="签收人编码" prop="signCode">
          <el-input v-model="form.signCode" placeholder="请输入签收人编码" />
        </el-form-item>
        <el-form-item label="发货图片id" prop="grantImgid">
          <el-input v-model="form.grantImgid" placeholder="请输入发货图片id" />
        </el-form-item>
        <el-form-item label="签收图片id" prop="signImgid">
          <el-input v-model="form.signImgid" placeholder="请输入签收图片id" />
        </el-form-item>
        <el-form-item label="任务主键id" prop="taskId">
          <el-input v-model="form.taskId" placeholder="请输入任务主键id" />
        </el-form-item>
        <el-form-item label="扩展" prop="extend">
          <el-input v-model="form.extend" placeholder="请输入扩展" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="task_name_title" :visible.sync="dialogTableVisible" width="85%">
      <!-- <el-form
        :model="signUserQueryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="100px">
        <el-form-item label="签收人名称" prop="signName">
          <el-input
            v-model="signUserQueryParams.signName"
            placeholder="请输入签收人名称"
            clearable
            size="mini" />
        </el-form-item>
        <el-form-item label="接收部门名称" prop="receiveDeptname">
          <el-input
            v-model="signUserQueryParams.receiveDeptname"
            placeholder="请输入接收部门名称"
            clearable
            size="mini" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuerySignUser"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuerySignUser">重置</el-button>
        </el-form-item>
      </el-form> -->
      <el-table :data="signUserDetail">
        <el-table-column prop="signName" align="center" label="签收人名称"></el-table-column>
        <el-table-column
          prop="receiveDeptname"
          align="center"
          label="接收部门名称"></el-table-column>
        <el-table-column prop="signNum" align="center" label="签收数量"></el-table-column>
        <el-table-column prop="signTime" align="center" label="签收时间"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSignuser,
  getSignuser,
  delSignuser,
  addSignuser,
  updateSignuser,
  exportSignuser,
  signUserDetails,
} from '@/api/sfa/signuser';
import { listDictype } from '@/api/sfa/dictype';
import { getToken } from '@/utils/auth';
import { importSigntemp } from '@/api/sfa/taskuser';
import { importTemplate } from '@/api/sfa/signuser';

export default {
  name: 'Signuser',
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      tablenum: 0,
      // 物料签收明细表格数据
      signuserList: [],
      materialNameOptionQuery: [],
      materialNameOption: [],
      materialTypeOption: [],
      statusOptions: [],
      statusOptions2: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      issueTime: '',
      signTime: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        issueNum: null,
        issuer: null,
        issuerCode: null,
        receiveDeptname: null,
        receiveDeptcode: null,
        isValid: null,
        trackingNum: null,
        issuingNum: null,
        signNum: null,
        issuingTime: null,
        status: null,
        signName: null,
        signCode: null,
        grantImgid: null,
        signImgid: null,
        taskId: null,
        extend: null,
        createTime: null,
      },
      upload2: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/common/upload',
        loadProgress: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      task_name_title: '',
      dialogTableVisible: false,
      signUserDetail: [],
      signUserQueryParams: {
        signName: null,
        receiveDeptname: null,
      },
      activaSignUser: null,
    };
  },
  created() {
    /*    this.getDicts("guide_item_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("guide_sign_status").then(response => {
      this.statusOptions2 = response.data;
      console.log(this.statusOptions2 )
    });*/
    this.getDicts('task_status').then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts('sign_status').then((response) => {
      this.statusOptions2 = response.data;
      console.log(this.statusOptions2);
    });
    this.getMaterialTypeOption();
    this.name = this.$store.state.user.name;
    this.getList();
  },
  methods: {
    openDetail(row) {
      this.signUserQueryParams = {
        signName: null,
        receiveDeptname: null,
      };
      this.activaSignUser = row;
      this.getSignUserDetails({ issueNum: this.activaSignUser.issue_num }, () => {
        this.task_name_title = row.task_name;
        this.dialogTableVisible = true;
      });
    },
    getSignUserDetails(params, callback) {
      this.loading = true;
      // {
      //   issueNum: row.issue_num, //	string	签发号
      //   sign_name: '', //	string	签收人名称
      //   sign_code: '', //	string	签收人编码
      //   receive_deptname: '', //	string	接收部门名称
      //   receive_deptcode: '', //	string	接收部门编码
      // }
      signUserDetails(params).then((res) => {
        this.signUserDetail = res.rows;
        callback && callback();
        this.loading = false;
      });
    },
    // 搜索
    handleQuerySignUser() {
      this.getSignUserDetails({
        issueNum: this.activaSignUser.issue_num,
        ...this.signUserQueryParams,
      });
    },
    // 重置
    resetQuerySignUser() {
      this.signUserQueryParams = {
        signName: null,
        receiveDeptname: null,
      };
      this.handleQuerySignUser();
    },
    /** 查询物料签收明细列表 */
    getList() {
      this.loading = true;
      listSignuser(this.queryParams).then((response) => {
        this.signuserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getSignUrlArray(url) {
      let urlArray = [];
      urlArray.push(url);
      return urlArray;
    },
    getMaterialTypeOption() {
      let obj = {
        type: 0,
      };
      this.getMaterialNameOption(obj, 'materialTypeOption');
    },
    getMaterialNameOption(obj, str) {
      let that = this;
      listDictype(obj).then((response) => {
        if (str == 'materialNameOptionAll') {
          that.materialNameOptionAll = response.rows;
        } else if (str == 'materialTypeOption') {
          that.materialTypeOption = response.rows;
        } else if (str == 'materialNameOption') {
          that.materialNameOption = response.rows;
        } else if (str == 'materialNameOptionQuery') {
          that.materialNameOptionQuery = response.rows;
        }
        console.log(that.materialNameOption);
      });
    },
    materialTypeChangeQuery(val) {
      console.log(val);
      this.queryParams.materialName = '';
      if (val != '' && val != null) {
        let pid;
        this.materialTypeOption.forEach((item) => {
          if (item.signType == val) {
            console.log(item);
            pid = item.id;
            let obj = {
              type: 1,
              pid,
            };
            this.getMaterialNameOption(obj, 'materialNameOptionQuery');
          }
        });
      } else {
        this.materialNameOptionQuery = [];
      }
      this.$forceUpdate();
    },
    materialTypeChange(val, isUplate) {
      console.log(val);
      if (!isUplate) {
        this.form.materialName = '';
      }

      if (val != '' && val != null) {
        let pid;
        this.materialTypeOption.forEach((item) => {
          if (item.signType == val) {
            console.log(item);
            pid = item.id;
            let obj = {
              type: 1,
              pid,
            };
            this.getMaterialNameOption(obj, 'materialNameOption');
          }
        });
      } else {
        this.materialNameOption = [];
      }
      this.$forceUpdate();
    },
    onInput() {
      this.$forceUpdate();
    },
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    statusFormat2(row) {
      return this.selectDictLabel(this.statusOptions2, row.status);
    },

    addStoreImport() {
      this.upload2.title = '快递单号导入';
      this.upload2.open = true;
    },
    handleFileUploadProgress(event, file, fileList) {
      this.upload2.isUploading = true;
      this.upladLoading = this.$loading({
        lock: true,
        text: '拼命上传中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
      });
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      let that = this;
      let receiveShopCode,
        data = {};
      // this.storeListAdd.forEach((item,index)=>{
      //     if(item.id == -1){
      //         receiveShopCode.push(item.receiveShopCode);
      //     }
      // })
      receiveShopCode = JSON.stringify(this.storeListAdd);
      if (this.form.id || this.form.id == 0) {
        data.taskId = this.form.id;
      }
      data.shopcodes = receiveShopCode;
      if (response.code == 200) {
        data.url = response.fileName;
        importSigntemp(data).then((res) => {
          // that.storeListAdd=[...that.storeListAdd,...res.data.success];
          /*  that.storeListAdd=[...res.data.success];*/
          this.tablenum++;
          this.$forceUpdate();
          this.upload2.open = false;
          this.upload2.isUploading = false;
          this.upladLoading.close();
          this.$refs.upload2.clearFiles();

          if (res.data.error.length == 0) {
            this.$message({
              type: 'success',
              message: '添加成功!',
            });
          } else {
            this.$alert(res.data.error, '导入结果', { dangerouslyUseHTMLString: true });
          }
        });
      } else {
        this.upload2.open = false;
        this.upload2.isUploading = false;
        this.upladLoading.close();
        this.$refs.upload2.clearFiles();
        this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then((response) => {
        window.location.href =
          process.env.VUE_APP_BASE_API +
          '/common/download?fileName=' +
          encodeURI(response.msg) +
          '&delete=' +
          true;

        //this.download(response.msg);
      });
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload2.submit();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        issueNum: null,
        issuer: null,
        issuerCode: null,
        receiveDeptname: null,
        receiveDeptcode: null,
        isValid: null,
        trackingNum: null,
        issuingNum: null,
        signNum: null,
        issuingTime: null,
        signTime: null,
        status: '0',
        signName: null,
        signCode: null,
        grantImgid: null,
        signImgid: null,
        taskId: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        extend: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.issueStartTime = this.issueTime == null ? '' : this.issueTime[0];
      this.queryParams.issueEndTime = this.issueTime == null ? '' : this.issueTime[1];
      this.queryParams.signStartTime = this.signTime == null ? '' : this.signTime[0];
      this.queryParams.signEndTime = this.signTime == null ? '' : this.signTime[1];
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.queryParams.issueStartTime = '';
      this.queryParams.issueEndTime = '';
      this.queryParams.signStartTime = '';
      this.queryParams.signEndTime = '';
      this.issueTime = '';
      this.signTime = '';
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = '添加物料签收明细';
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSignuser(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = '修改物料签收明细';
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateSignuser(this.form).then((response) => {
              this.$modal.msgSuccess('修改成功');
              this.open = false;
              this.getList();
            });
          } else {
            addSignuser(this.form).then((response) => {
              this.$modal.msgSuccess('新增成功');
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除物料签收明细编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return delSignuser(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有物料签收明细数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.exportLoading = true;
          return exportSignuser(queryParams);
        })
        .then((response) => {
          window.location.href =
            process.env.VUE_APP_BASE_API +
            '/common/download?fileName=' +
            encodeURI(response.msg) +
            '&delete=' +
            true;
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.drkddh {
  ::v-deep .el-button--info.is-plain {
    color: #1890ff;
    background: #fff8e6;
    border-color: #1890ff;
  }
}
</style>
