<template>
  <div class="mod-print-returnDelivery">
    <!-- 搜索相关区域 -->
    <div class="search-bar">
      <el-form :inline="true" class="search-form" ref="searchForm" :model="searchForm" label-width="auto" size="small">
        <div class="input-row">
          <el-form-column label="打印渠道" class="search-form-item" v-if="shopId === 1">
            <el-select v-model="searchForm.printChannel" clearable>
              <el-option key="Lightning" label="闪电" value="Lightning"></el-option>
<!--              <el-option key="GSART" label="广森" value="GSART"></el-option>-->
<!--              <el-option key="WoNiu" label="蜗牛" value="WoNiu"></el-option>-->
            </el-select>
          </el-form-column>
          <el-form-item label="订单号" class="search-form-item">
            <el-input type="text" clearable v-model="searchForm.orderNumber" placeholder="订单号"></el-input>
          </el-form-item>
          <el-form-item label="原运单号" class="search-form-item">
            <el-input type="text" clearable v-model="searchForm.deliveryNo" placeholder="原运单号"></el-input>
          </el-form-item>
          <el-form-item label="收件人信息" class="search-form-item">
            <el-input type="text" clearable v-model="searchForm.receiverInfo" placeholder="收件人信息"></el-input>
          </el-form-item>
          <el-form-item label="状态" class="search-form-item">
            <el-select v-model="searchForm.status" clearable>
              <el-option label="待联系" :value="0"></el-option>
              <el-option label="联系异常" :value="1"></el-option>
              <el-option label="已联系待重发" :value="2"></el-option>
              <el-option label="已重发" :value="3"></el-option>
              <el-option label="地址异常" :value="4"></el-option>
              <el-option label="无需处理" :value="5"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="补交运费" class="search-form-item">
            <el-select v-model="searchForm.isPayed" clearable>
              <el-option label="已补交" :value="1"></el-option>
              <el-option label="未补交" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="default-btn primary-btn" @click="searchChange()">{{$t('crud.searchBtn')}}</div>
            <div class="default-btn" @click="resetSearchForm('searchForm')">{{$t('shop.resetMap')}}</div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <!-- 列表相关区域 -->
    <div class="main-container">
      <div class="operation-bar">
        <div class="default-btn primary-btn" @click="addOrUpdateHandle()">新增退件</div>
      </div>
      <div class="table-con spec-table">
        <el-table
          ref="specListTable"
          :data="dataList"
          header-cell-class-name="table-header"
          row-class-name="table-row"
          style="width: 100%">
          <!-- 订单号 -->
          <el-table-column label="打印渠道" prop="printChannel" align="center">
            <template slot-scope="scope">
<!--              <span v-if="scope.row.printChannel === 'KuaiYin'">快印</span>-->
<!--              <span v-if="scope.row.printChannel === 'GSART'">广森</span>-->
            </template>
          </el-table-column>
          <el-table-column label="订单号" prop="orderNumber" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.orderNumber}}</span>
            </template>
          </el-table-column>
          <!-- 原运单号 -->
          <el-table-column label="原运单号" prop="deliveryNo" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.deliveryNo}}</span>
            </template>
          </el-table-column>
          <!-- 收件人信息 -->
          <el-table-column label="原收件人信息" prop="receiverInfo" align="center" >
            <template slot-scope="scope">
                <el-tooltip placement="top">
                  <div slot="content">{{ scope.row.receiverInfo}}</div>
                  <span v-if="scope.row.receiverInfo && scope.row.receiverInfo.length > 20">{{scope.row.receiverInfo.substr(0, 20) }}</span>
                  <span v-else>{{scope.row.receiverInfo }}</span>
                </el-tooltip>
            </template>
          </el-table-column>
          <!-- 新运单号 -->
          <el-table-column label="新运单号" prop="newDeliveryNo" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.newDeliveryNo}}</span>
            </template>
          </el-table-column>
          <!-- 新收件人信息 -->
          <el-table-column label="新收件人信息" prop="newReceiverInfo" align="center">
            <template slot-scope="scope">
              <el-tooltip placement="top">
                <div slot="content">{{ scope.row.newReceiverInfo}}</div>
                <span v-if="scope.row.newReceiverInfo && scope.row.newReceiverInfo.length > 20">{{scope.row.newReceiverInfo.substr(0, 20) }}</span>
                <span v-else>{{scope.row.newReceiverInfo }}</span>
              </el-tooltip>
            </template>
          </el-table-column>
          <!-- 状态，0：待联系，1：联系异常，2：可重发，3：已重发 -->
          <el-table-column label="状态" prop="status" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === 0" type="primary">待联系</el-tag>
              <el-tag v-if="scope.row.status === 1" type="danger">联系异常</el-tag>
              <el-tag v-if="scope.row.status === 2" type="warning">已联系待重发</el-tag>
              <el-tag v-if="scope.row.status === 3" type="success">已重发</el-tag>
              <el-tag v-if="scope.row.status === 4" type="danger">地址异常</el-tag>
              <el-tag v-if="scope.row.status === 5" type="info">无需处理</el-tag>
            </template>
          </el-table-column>
          <!-- 退件原因 -->
          <el-table-column label="退件原因" prop="remark" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.reason}}</span>
            </template>
          </el-table-column>
          <!-- 备注 -->
          <el-table-column label="备注" prop="remark" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.remark}}</span>
            </template>
          </el-table-column>
          <!-- 登记时间 -->
          <el-table-column label="登记时间" prop="createTime" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.createTime}}</span>
            </template>
          </el-table-column>
          <!-- 是否补交运费，0未补，1已补交 -->
          <el-table-column label="补交运费" prop="isPayed" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.isPayed === 0" type="danger">未补交</el-tag>
              <el-tag v-if="scope.row.isPayed === 1" type="success">已补交</el-tag>
            </template>
          </el-table-column>
          <el-table-column align="center" fixed="right" :label="$t('publics.operating')" width="auto">
            <template slot-scope="scope">
              <div class="text-btn-con">
                <div class="default-btn text-btn" @click="addOrUpdateHandle(scope.row.id)">{{$t("crud.updateBtn")}}</div>
                <div class="default-btn text-btn" @click.stop="deleteHandle(scope.row.id)">{{$t("text.delBtn")}}</div>
                </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
        <el-pagination
          v-if="dataList.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './returnDelivery-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {
        orderNumber: null,
        deliveryNo: null,
        status: null,
        receiverInfo: null,
        isPayed: null,
        newDeliveryNo: null,
      }, // 搜索
      shopId: this.$store.state.user.shopId,
      dataListLoading: false,
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
    this.getDataList(this.page);
  },
  mounted () {
  },
  methods: {
    resetSearchForm (formName) {
      this.$refs[formName].resetFields()
      this.searchForm = {}
    },
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/order/returnDelivery/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign({
            current: page == null ? this.page.currentPage : page.currentPage,
            size: page == null ? this.page.pageSize : page.pageSize,
            orderNumber: this.searchForm.orderNumber,
            deliveryNo: this.searchForm.deliveryNo,
            receiverInfo: this.searchForm.receiverInfo,
            status: this.searchForm.status,
            isPayed: this.searchForm.isPayed,
            printChannel: this.searchForm.printChannel
            },
            this.searchForm
          )
        )
      }).then(({data}) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    deleteHandle (id) {
      this.$confirm(this.$i18n.t('admin.isDeleOper') + '?', this.$i18n.t('text.tips'), {
        confirmButtonText: this.$i18n.t('crud.filter.submitBtn'),
        cancelButtonText: this.$i18n.t('crud.filter.cancelBtn'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/order/returnDelivery/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 30,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    // 刷新回调
    refreshChange () {
      // this.page.currentPage = 1
      this.addOrUpdateVisible = false;
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.getDataList(this.page)
    },
    handleSizeChange (val) {
      this.page.pageSize = val
      this.getDataList()
    },
    handleCurrentChange (val) {
      this.page.currentPage = val
      this.getDataList()
    }
  }
}
</script>
<style lang="scss">
.mod-print-returnDelivery {
}
</style>
