<template>
  <base-list>
    <template slot="n_header">
      <el-form v-model="pagerDto" inline>
        <el-form-item label="客户单号">
          <el-input
            v-model="pagerDto._Eq_CustomerOrderNo"
            class="input-with-select"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="pagerSerach(1)"> 搜索 </el-button>
        </el-form-item>
      </el-form>
    </template>
    <template slot="n_option">
      <el-button type="primary" @click="dialogInput = true">
        添加放行单号
      </el-button>
    </template>
    <template>
      <el-table
        v-loading="dataLoading"
        :data="data"
        :highlight-current-row="true"
        :select-on-indeterminate="true"
        width="100%"
      >
        <el-table-column label="客户单号" prop="CustomerOrderNo" />
        <el-table-column label="渠道" prop="ChannelName" />
        <el-table-column label="创建时间" prop="CreateTimeStr" />
        <el-table-column label="创建人" prop="CreateUserName" />
        <el-table-column label="操作" width="250">
          <template slot-scope="scope">
            <el-button size="mini" @click="editInfo(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-sizes="[10, 20, 40, 100, 400]"
        :current-page="pagerDto.PageIndex"
        :page-size.sync="pagerDto.PageSize"
        background
        layout="prev, pager, next ,total ,jumper,sizes,slot "
        :total="pagerDto.total"
        @size-change="changePager"
        @current-change="pagerSerach"
      />
    </template>
    <el-dialog :visible.sync="dialogInput" title="放行记录">
      <el-form :model="row" label-width="120px">
        <el-form-item label="客户单号">
          <el-input v-model="row.CustomerOrderNo" />
        </el-form-item>

        <el-form-item label="渠道">
          <el-select v-model="row.ChannelId" filterable>
            <el-option
              v-for="item in channels"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loading" @click="saveInfo"> 保存 </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </base-list>
</template>
<script>
import BaseList from "@/components/Xyy/baselist";
import { _getDeliverChannel } from "@/api/baseInfo";
import { _getPageResult, _edit, _add } from "@/api/order/AURemoteRelease";
export default {
  name: "AURemote",
  components: { "base-list": BaseList },
  data() {
    return {
      data: [],
      dialogInput: false,
      dataLoading: false,
      loading: false,
      dialogInput: false,
      channels: [],
      row: { Id: 0, CustomerOrderNo: "", ChannelId: 107 },
      pagerDto: { PageIndex: 0, PageSize: 10, total: 0 },
    };
  },
  created() {
    _getDeliverChannel().then((res) => {
      this.channels = res;
    });
  },
  methods: {
    editInfo(row) {
      this.row = row;
      this.dialogInput = true;
    },
    saveInfo() {
      if (!this.row.CustomerOrderNo) {
        this.$message({
          message: "请输入客户单号！",
          type: "warning",
        });
        return;
      }
      this.loading = true;
      if (this.row.Id > 0) {
        _edit(this.row)
          .then(() => {
            this.$message({
              message: "修改成功！",
              type: "success",
            });
            this.dialogInput=false;
            this.pagerSerach(1);
          })
          .finally(() => {
            this.loading = false;
          });
      } else {
        _add(this.row)
          .then(() => {
            this.$message({
              message: "添加成功！",
              type: "success",
            });
            this.dialogInput=false;
            this.pagerSerach(1);
          })
          .finally(() => {
            this.loading = false;
          });
      }
    },
    pagerSerach(index) {
      this.dataLoading = true;
      if (index) {
        this.pagerDto.PageIndex = index;
      }
      _getPageResult(this.pagerDto)
        .then((res) => {
          this.data = res.Result;
          this.pagerDto.total = res.TotalCount;
        })
        .finally((res) => {
          this.dataLoading = false;
        });
    },
    changePager(v) {
      this.PageSize = v;
      this.pagerSerach();
    },
  },
};
</script>
