<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" class="delInput" type='number' v-model="scope.row.dataName"
            @change="cc(scope.row)" 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.row, '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" @click="imageCaption(scope.row, '4')" type="text"
            size="small">生成支付订单</el-button>
          <el-button v-if="scope.row.status == 5" @click="imageCaption(scope.row, '9')" 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" :idt="id" @visivie='visivie' @clickDialog="clickDialog" :control="control"
      ref="refIndex" :bindex="bb"></comindex>
    <!-- 修改 详情 -->
    <commodify :title="title" :dialogVisibl="dialogVi" @diaisibl="diaisibl" @onSubmit="onSubmit" :disabled="disabled"
      ref="refModify"></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, createPayPOST, refundGET } 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 '已退款'
        case 7:
          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: '已退款'
      }, {
        value: '7',
        label: '已取消'
      }],
      disabled: false,
      particulars: {},
      tableData: [],
      // 日期范围
      dateRange: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: undefined,
        tableComment: undefined,
        dataName: "",
        status: "",
        repairTime: '',
        linkman: '',
        phone: ''
      },
      id: '',
      ids: '',
      // 预览参数
      bb: [],
      preview: {
        open: false,
        title: "代码预览",
        data: {},
        activeName: "domain.java"
      }
    };
  },
  components: {
    comindex,
    commodify
  },
  watch: {
    //监听器的作用就是用来监听数据是否发生了变化,变化后可以进行一些其他操作
    //只要没有发生变化,就没有办法进行其他的操作
    bb: function (newData, oldData) {
      //newData是更新后的数据
      //oldData是旧数据
      // newData.tel = 1111;
      console.log("监听变化:", newData, oldData);
    },
  },
  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() {
      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) {
      let self = this
      switch (val) {
        case '1':
          if (sta.pictureList && sta.pictureList.length) {
            self.id = sta.pictureList[0].url
            self.dialogVisible = true
          } else {
            this.$message({
              message: '暂无图片',
              type: 'warning'
            });
          }
          this.control = val
          break;
        case '2':
          if (sta.row.videoList && sta.row.videoList.length) {
            self.id = sta.row.videoList[0].url
            self.dialogVisible = true
          } else {
            this.$message({
              message: '暂无视频',
              type: 'warning'
            });
          }
          this.control = val
          break;
        case '3':
          if (sta.row.voiceList && sta.row.voiceList.length) {
            self.id = sta.row.voiceList[0].url
            self.dialogVisible = true
          } else {
            this.$message({
              message: '暂无语音',
              type: 'warning'
            });
          }
          this.control = val
          // this.dialogVisible = true
          break;
        case '4':
          this.id = sta.id
          this.control = val
          this.dialogVisible = true
          break;
        case '5':
          this.id = sta.id
          this.control = val
          this.dialogVisible = true
          break;
        case '9':
          this.id = sta.id
          this.control = val
          this.dialogVisible = true
          break;
      }
    },
    cc(index) {
      console.log("更改后的值:", index);
      this.bb.push(index)
    },
    // 修改详情
    modify(sta, val) {
      let self = this
      if (val == '1') {
        self.disabled = false
        self.title = '修改订单'
        self.$refs['refModify'].partic(sta.id)
      } else {
        self.disabled = true
        self.$refs['refModify'].partic(sta.id)
        self.title = '订单详情'
      }
      self.dialogVi = true
    },
    // 其他 弹窗关闭
    visivie() {
      this.$refs['refIndex'].form.money = ''
      this.$refs['refIndex'].form.name = ''
      this.dialogVisible = false
    },
    // 其他 确认
    clickDialog() {
      if (this.control == '5') {
        var params = {
          reasonsForRejection: this.$refs['refIndex'].form.name,
          status: 1,
          id: this.id
        }
        createPayPOST(params).then((res) => {
          if (res.code == 200) {
            this.$refs['refIndex'].form.name = ''
            this.dialogVisible = false
            this.listth()
          }
        })
      } else if (this.control == '4') {
        if (this.$refs['refIndex'].form.money) {
          var params = {
            actualAmount: this.$refs['refIndex'].form.money,
            status: 2,
            id: this.id
          }
          createPayPOST(params).then((res) => {
            if (res.code == 200) {
              this.$refs['refIndex'].form.money = ''
              this.dialogVisible = false
              this.listth()
            }
          })
        } else {
          this.$message.error('请输入沟通后金额');
        }

      } else if (this.control == '9') {
        if (this.$refs['refIndex'].form.money) {
          var params = {
            refundeAmount: this.$refs['refIndex'].form.money,
            orderId: this.id
          }
          refundGET(params).then((res) => {
            if (res.code == 200) {
              this.$refs['refIndex'].form.money = ''
              this.dialogVisible = false
              this.listth()
            }
          })
        } else {
          this.$message.error('请输入沟通后金额');
        }

      }
    },
    // 详情 修改 弹窗关闭
    diaisibl() {
      console.log('111111111111')
      this.dialogVi = false
    },
    // 详情 修改 确认修改
    onSubmit() {
      this.dialogVi = false
    }
  }
};
</script>

<style  scoped  lang="scss">
::v-deep .delInput input::-webkit-outer-spin-button,
::v-deep .delInput input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}

::v-deep .delInput input[type="number"] {
  -moz-appearance: textfield;
}
</style>