<template>
  <!-- 已拒收订单status: 6, -->
  <div>
    <div ref="grabble">
      <actionBar :formList="formList" :ruleForm="searchRuleForm" @openModel="openModel"
        @searchProtocol="searchProtocol"></actionBar>
    </div>
    <div class="card_content">
      <!-- 表单 -->
      <tables ref="refWaybill" controlswidth="180px" tableHeight="68vh" :suspension="true" :tableList="tableList"
        :tableData="tableData" @buttonData="buttonData">
      </tables>
      <!-- 分页 -->
      <div v-if="Total">
        <pagination :total="Total" :currentPage="Pagination.PageIndex" @changeSize="changeSize"
          @changeCurrent="changeCurrent">
        </pagination>
      </div>
    </div>
    <orderDetails ref="order" :waybillData="waybillData"></orderDetails>
    <prescriptionPicture ref="picture" :srcList="srcList" :fileList="fileList"></prescriptionPicture>
  </div>
</template>

<script>
  import {
    getWaybill
  } from '@/api/waybill'
  import actionBar from '@/components/actionBar'
  import tables from '@/components/tables'
  import pagination from '@/components/pagination'
  import orderDetails from '@/components/orderDetails'
  import prescriptionPicture from '@/components/prescriptionPicture'
  import {
    employee,
  } from "./uncertain.js";
  import {
    WaybillStatus
  } from '@/assets/js/blockSort'
  export default {
    name: 'OrderManagement',
    components: {
      actionBar,
      tables,
      pagination,
      orderDetails,
      prescriptionPicture
    },
    data() {
      return {
        formList: [{
          type: 'input',
          label: '订单编号',
          field: 'waybillNo',
          placeholder: '请输入订单编号',
        }, {
          type: 'input',
          label: '配送员姓名',
          field: 'delivery_name',
          placeholder: '请输入配送员姓名',
        }, {
          type: 'input',
          label: '患者名称',
          field: 'Consignee_address_name',
          placeholder: '请输入患者名称',
        }, {
          type: 'input',
          label: '患者手机号',
          field: 'Consignee_address_phone',
          placeholder: '请输入患者手机号',
        }],
        searchRuleForm: {
          waybillNo: '',
          delivery_name: '',
          Consignee_address_name: '',
          Consignee_address_phone: '',
        },
        searchValue: {},
        Pagination: {
          PageIndex: 1,
          PageSize: 10,
        },
        Total: 0,
        operationType: '',
        tableData: [],
        tableList: [],
        btnData: [{
          type: 'logs',
          label: '详情',
          icon: 'el-icon-tickets',
          style: 'success',
        }, {
          type: 'delOrder',
          label: '删除订单',
          icon: 'el-icon-delete',
          style: 'danger',
        }],
        waybillData: {},
        srcList: [],
        fileList: [],
        receiptsign: {
          field: 'receiptsign',
          label: '客户签字图片',
          align: 'center',
          colWidth: '180px',
        },
        receiptImg: {
          field: 'receiptImg',
          label: '拒收图片',
          align: 'center',
        },
        reasonRejection: {
          field: 'rejectionReason',
          label: '拒收原因',
          align: 'center',
          colWidth: '180px',
        },
      }
    },
    mounted() {
      let arr = employee()
      arr.forEach(item => {
        if (item.field == 'unpackBtn') {
          item.labelButton = this.btnData
        }
      })
      this.tableList = arr
      this.tableList.push(this.receiptsign)
      this.tableList.push(this.receiptImg)
      this.tableList.push(this.reasonRejection)
      this.getList()
    },
    methods: {
      // 搜索
      searchProtocol(value) {
        this.Pagination.PageIndex = 1
        this.searchValue = value
        if (value.time) {
          this.searchValue.orderStartTime = value.time[0]
          this.searchValue.orderEndTime = value.time[1]
        }
        this.getList()
      },
      // 获取运单列表
      getList() {
        var params = {
          status: 6,
          page: this.Pagination.PageIndex,
          pageSize: this.Pagination.PageSize,
          ...this.searchValue
        }
        delete params.time
        getWaybill(params).then(res => {
          if (res.code == 200) {
            this.tableData = res.data.list
            this.tableData.forEach(item => {
              if (item.iceRaftCode) {
                item.iceRaftCode = item.iceRaftCode.toString()
              }
              item.visible = false
            })
            this.Total = res.data.count
          }
        })
      },
      openModel(type) {
        this.operationType = type
      },
      buttonData(row, type) {
        this.operationType = type
        if (type == 'logs') {
          this.$refs.order.staffDialogVisible = true
          this.waybillData = row
          this.waybillData.coolerBoxName = row.coolerBox.name
          this.waybillData.courierName = row.delivery.nickName
          this.waybillData.courierPhone = row.delivery.phone
          this.waybillData.reCheckName = row.reCheck.nickName
          this.waybillData.reCheckPhone = row.reCheck.phone
        } else if (type == 'send') {
          const urls = this.fileList.map(obj => obj.url)
          this.srcList = urls
          this.$refs.picture.prescriptionVisible = true
        }
      },
      changeSize(val) {
        this.Pagination.PageSize = val
        this.getList()
      },
      changeCurrent(val) {
        this.Pagination.PageIndex = val
        this.getList()
      },
    },
  }
</script>

<style>
</style>
