<template>
  <div class="app-container">
    <el-descriptions :column="4" border class="card" :labelStyle="{ width: '110px' }" :contentStyle="{ width: '110px' }"
                     style="margin-top: 10px">
      <el-descriptions-item :label="$t('快递单号') + ':'">
        {{ form.expressNo }}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('发货人') + ':'">
        {{ form.customerNumber }}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('签收时间') + ':'">
        {{ form.signedTime }}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('在仓时间') + ':'">
        ggggg
      </el-descriptions-item>
      <el-descriptions-item :label="$t('商品信息') + ':'">
        {{ form.goodListName }}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('运输方式') + ':'">
        <dict-tag :type="DICT_TYPE.ECW_CUSTOMER_TRANSPORT_TYPE" :value="form.transportId" />
      </el-descriptions-item>
      <el-descriptions-item :label="$t('始发地') + ':'">
        {{ form.startTitleZh }}
      </el-descriptions-item>
      <el-descriptions-item :label="$t('目的地') + ':'">
        {{ form.destTitleZh }}
      </el-descriptions-item>
    </el-descriptions>

    <h2>{{ $t("异常信息") }}</h2>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="异常类型" align="center" prop="exceptionType">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.CONS_EXCEPTION_TYPE" :value="scope.row.exceptionType" />
        </template>
      </el-table-column>
      <el-table-column label="异常说明" align="center" prop="exceptionRemark" />
      <el-table-column label="异常状态" align="center" prop="exceptionStatus">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.CONS_EXCEPTION_STATUS" :value="scope.row.exceptionStatus" />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </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,false)"
                     v-if="scope.row.exceptionStatus ===0">处理
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row,true)" v-if="scope.row.exceptionStatus ===2">查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <ExceptionOtherHandling :showExceptionOther.sync="showExceptionOther" :id="id" :look="look"
                            @determine="getList"></ExceptionOtherHandling>
    <ExceptionHandling :showException.sync="showException" :id="id" :look="look"
                       @determine="getList"></ExceptionHandling>

  </div>
</template>

<script>
import {
  getConsException,
  getConsExceptionPage
} from "@/api/ecw/consException"
import ExceptionHandling from "@/views/ecw/consException/components/ExceptionHandling.vue"
import ExceptionOtherHandling from "@/views/ecw/consException/components/ExceptionOtherHandling.vue"

export default {
  name: "ConsException",
  components: {
    ExceptionOtherHandling,
    ExceptionHandling
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        consId: null,
        consItemId: null,
        exceptionType: null,
        exceptionRemark: null,
        exceptionStatus: null,
        bpmId: null,
        bpmStatus: null
      },
      list: [],
      showExceptionOther: false,
      showException: false,
      form: {},
      total: 0,
      id: null,
      look: false
    }
  },
  created() {
    this.getList()
    console.log(this.$route.query.id)
    getConsException({consId:this.$route.query.id}).then(response => {
      this.form = response.data
    })
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 处理查询参数
      let params = { ...this.queryParams }
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime")
      params.consId = this.$route.query.id
      // 执行查询
      getConsExceptionPage(params).then(response => {
        this.list = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row, look) {
      this.id = row.id
      this.look = look
      if (row.exceptionType === "order_other_exception") {
        this.showExceptionOther = true
      } else if (row.exceptionType === "goods_add_exception") {
        this.showException = true
      }
    }
  }
}
</script>
