<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item :label="$t('systemuser.组织名称')" prop="nameThe">
        <el-input
          v-model="queryParams.nameThe"
          :placeholder="$t('systemuser.请输入社会组织名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('systemuser.卖家名称')" prop="sellersName">
        <el-input
          v-model="queryParams.sellersName"
          :placeholder="$t('systemuser.请输入卖家名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('systemuser.审核状态')" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" :placeholder="$t('systemuser.请选择审核状态')" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_audit"
            :key="dict.value"
            :label="generateTitle(dict.label)"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('systemuser.反馈时间')" prop="feedbackTime">
        <el-date-picker clearable
          v-model="queryParams.feedbackTime"
          type="date"
          value-format="yyyy-MM-dd"
          :placeholder="$t('systemuser.请选择反馈时间')">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('systemuser.搜索')}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{$t('systemuser.重置')}}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['feeds:feedbacks:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['feeds:feedbacks:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['feeds:feedbacks:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['feeds:feedbacks:export']"
        >{{$t('systemuser.导出')}}</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="feedbacksList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column :label="$t('systemuser.社会组织名称')" align="center" prop="nameThe" />
      <el-table-column :label="$t('systemuser.电话/邮箱')" align="center" prop="contactDetails" />
      <el-table-column :label="$t('systemuser.卖家名称')" align="center" prop="sellersName" />
      <el-table-column :label="$t('systemuser.审核状态')" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.auditStatus==0" type="info">{{generateTitle('未审核')}}</el-tag>
          <el-tag v-if="scope.row.auditStatus==1" type="primary">{{generateTitle('已审核')}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="$t('systemuser.反馈时间')" align="center" prop="feedbackTime"/>
      <el-table-column :label="$t('systemuser.操作')" 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)"
            v-hasPermi="['feeds:feedbacks:edit']"
          >{{$t('systemuser.审核')}}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['feeds:feedbacks:remove']"
          >{{$t('systemuser.删除')}}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改社会反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="670px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :label-width="$t('message.language')=='语言'?'80px':$t('message.language')=='語言'?'80px':'210px'">
        <el-form-item :label="$t('systemuser.组织名称')" prop="nameThe">
          <el-input v-model="form.nameThe" :disabled="true" :placeholder="$t('systemuser.请输入社会组织名称')" />
        </el-form-item>
        <el-form-item :label="$t('systemuser.地址')" prop="address">
          <el-input v-model="form.address" :disabled="true" :placeholder="$t('systemuser.请输入地址')" />
        </el-form-item>
        <el-form-item :label="$t('systemuser.电话/邮箱')" prop="contactDetails">
          <el-input v-model="form.contactDetails" :disabled="true" :placeholder="$t('systemuser.请输入电话/邮箱')" />
        </el-form-item>
        <el-form-item :label="$t('systemuser.卖家名称')" prop="sellersName">
          <el-input v-model="form.sellersName" :disabled="true" :placeholder="$t('systemuser.请输入卖家名称')" />
        </el-form-item>
        <el-form-item :label="$t('systemuser.反馈内容')" prop="feedback">
          <el-input v-model="form.feedback" :disabled="true" type="textarea" :placeholder="$t('systemuser.请输入内容')" />
        </el-form-item>
        <el-form-item :label="$t('systemuser.附件')" prop="annexes">
          <image-upload v-model="form.annexes"/>
        </el-form-item>
        <el-form-item :label="$t('systemuser.审核状态')" prop="auditStatus">
          <el-radio-group v-model="form.auditStatus">
            <el-radio
              v-for="dict in dict.type.sys_user_audit"
              :key="dict.value"
              :label="dict.value"
            >{{generateTitle(dict.label)}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{$t('systemuser.确定')}}</el-button>
        <el-button @click="cancel">{{$t('systemuser.取消')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFeedbacks, getFeedbacks, delFeedbacks, addFeedbacks, updateFeedbacks } from "@/api/feeds/feedbacks";
import {generateTitle} from '../../../utils/i18.js'
export default {
  name: "Feedbacks",
  dicts: ['sys_user_audit'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 社会反馈表格数据
      feedbacksList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nameThe: null,
        sellersName: null,
        auditStatus: null,
        feedbackTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    generateTitle,
    /** 查询社会反馈列表 */
    getList() {
      this.loading = true;
      listFeedbacks(this.queryParams).then(response => {
        this.feedbacksList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nameThe: null,
        address: null,
        contactDetails: null,
        sellersName: null,
        feedback: null,
        annexes: null,
        auditStatus: null,
        feedbackTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = this.$t('systemuser.添加');
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFeedbacks(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = this.$t('systemuser.审核');
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFeedbacks(this.form).then(response => {
              this.$modal.msgSuccess(this.$t('systemuser.修改成功'));
              this.open = false;
              this.getList();
            });
          } else {
            addFeedbacks(this.form).then(response => {
              this.$modal.msgSuccess(this.$t('systemuser.新增成功'));
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm(this.$t('systemuser.是否确认删除编号为')+'"' + ids + '"'+this.$t('systemuser.的数据项')).then(function() {
        return delFeedbacks(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess(this.$t('systemuser.删除成功'));
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('feeds/feedbacks/export', {
        ...this.queryParams
      }, `feedbacks_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
