<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="94px">
      <el-form-item label="联系人姓名" prop="linkman">
        <el-input v-model="queryParams.linkman" placeholder="请输入联系人姓名" clearable />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系电话" clearable />
      </el-form-item>
      <el-form-item label="维修时间" prop="repairTime">
        <el-date-picker v-model="queryParams.repairTime" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </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-button type="primary" plain icon="el-icon-download" size="mini" @click="handleGenTable">导出订单</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" width="50" label="序号" align="center">
      </el-table-column>
      <el-table-column prop="linkman" label="联系人" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="phone" label="联系电话" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="repairTime" label="维修时间" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="repairAddress" label="维修地址" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="budget" label="预算金额(元)" :show-overflow-tooltip="true" align="center">

      </el-table-column>
      <el-table-column prop="actualAmount" label="沟通后金额(元)" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <el-input v-if="!scope.row.actualAmount" v-model="scope.row.dataName" placeholder="请输入联系人姓名" clearable />
          <div v-else>{{ scope.row.actualAmount }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="title" label="订单标题" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="address" label="图片说明" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="imageCaption(scope, '1')">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="视频说明" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="imageCaption(scope, '2')">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="语音描述" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="imageCaption(scope, '3')">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="订单状态" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <div>{{scope.row.status | filtersList }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="reasonsForRejection" label="驳回理由" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="remark" label="备注说明" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 0 || scope.row.status == 5" @click="imageCaption(scope.row, '4')" type="text" size="small">生成支付订单</el-button>
          <el-button v-if="scope.row.status == 0" type="text" size="small" @click="imageCaption(scope.row, '5')">驳回</el-button>
          <el-button  v-if="scope.row.status == 0 || scope.row.status == 2" type="text" size="small" @click="modify(scope.row, '1')">修改</el-button>
          <el-button  type="text" size="small" @click="modify(scope.row, '2')">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 其他 -->
    <comindex :dialogVisibl="dialogVisible" @visivie='visivie' :control="control"></comindex>
    <!-- 修改 详情 -->
    <commodify :title="title" :dialogVisibl="dialogVi" @diaisibl="diaisibl" @onSubmit="onSubmit"></commodify>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import comindex from './components/index'
import commodify from './components/modify'
import { listGET } from '@/api/orderform/index'
export default {
  name: "orderform",
  filters: {
    filtersList(val) {
      switch (val) {
        case 0:
          return '已发布'
        case 1:
          return '已驳回'
        case 2:
          return '待支付'
        case 3:
          return '已接单'
        case 4:
          return '已完成'
        case 5:
          return '退款中'
        case 6:
          return '已退款'
      }
    }
  },
  data() {
    return {
      value1: '',
      dialogVisible: false,
      dialogVi: false,
      control: '0',
      total: 0,
      title: '修改订单',
      options: [{
        value: '0',
        label: '已发布'
      }, {
        value: '1',
        label: '已驳回'
      }, {
        value: '2',
        label: '待支付'
      }, {
        value: '3',
        label: '已接单'
      }, {
        value: '4',
        label: '已完成'
      }, {
        value: '5',
        label: '退款中'
      }, {
        value: '6',
        label: '已退款'
      }],
      tableData: [],
      // 日期范围
      dateRange: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: undefined,
        tableComment: undefined,
        dataName: "",
        status: "",
        repairTime: '',
        linkman: '',
        phone: ''
      },
      // 预览参数
      preview: {
        open: false,
        title: "代码预览",
        data: {},
        activeName: "domain.java"
      }
    };
  },
  components: {
    comindex,
    commodify
  },
  created() {
    this.listth()
  },
  methods: {
    // 列表接口
    listth() {
      let params = {
        ...this.queryParams
      }
      listGET(params).then((res) => {
        this.tableData = res.rows
        this.total = res.total
      })
    },
    // 搜索
    handleQuery() {
      this.listth()
    },
    // 重置
    resetQuery() {
      this.queryParams.phone = ''
      this.queryParams.repairTime = ''
      this.queryParams.status = ''
      this.queryParams.dataName = ''
      this.queryParams.linkman = ''
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.listth()
    },
    // 导出订单
    handleGenTable() {
      const tableNames = 'db_Inviter'
      let params = {
        ...this.queryParams
      }
      this.download('/xinrenli/order/export', {
        ...this.queryParams
      }, `role_${new Date().getTime()}.xlsx`)
      // this.$download.zip("/xinrenli/order/export?", params, "ruoyi.zip");
    },
    // 页码切换
    getList() {
      this.listth()
    },
    // 打开查看详情
    imageCaption(sta, val) {
      switch (val) {
        case '1':
          this.control = val
          break;
        case '2':
          this.control = val
          break;
        case '3':
          this.control = val
          break;
        case '4':
          this.control = val
          break;
        case '5':
          this.control = val
          break;
      }
      this.dialogVisible = true
    },
    // 修改详情
    modify(sta, val) {
      if (val == '1') {
        this.title = '修改订单'
      } else {
        this.title = '订单详情'
      }
      this.dialogVi = true

    },
    // 其他 弹窗关闭
    visivie() {
      this.dialogVisible = false
    },
    // 详情 修改 弹窗关闭
    diaisibl() {
      this.dialogVi = false
    },
    // 详情 修改 确认修改
    onSubmit() {
      this.dialogVi = false
    }
  }
};
</script>
