<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
		<el-form-item :label="$t('table.status3')">
			<el-select v-model="queryParams.status" :placeholder="$t('placeholder.status1')">
				<el-option
					:label="$t('table.noReply')"
					value="0">
				</el-option>
				<el-option
					:label="$t('table.replied')"
					value="1">
				</el-option>
			</el-select>
		</el-form-item>
		<el-form-item :label="$t('table.beginDate')" >
			<el-date-picker clearable
			v-model="queryParams['params[beginDate]']"
			type="date"
			value-format="yyyy-MM-dd"
			:placeholder="$t('placeholder.beginDate')">
			</el-date-picker>
		</el-form-item>
		<el-form-item :label="$t('table.endDate')">
			<el-date-picker clearable
			v-model="queryParams['params[endDate]']"
			type="date"
			value-format="yyyy-MM-dd"
			:placeholder="$t('placeholder.endDate')">
			</el-date-picker>
		</el-form-item>
      <!-- <el-form-item label="客户id" prop="customerId">
        <el-input
          v-model="queryParams.customerId"
          placeholder="请输入客户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单id" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回复管理员id" prop="rebackUserId">
        <el-input
          v-model="queryParams.rebackUserId"
          placeholder="请输入回复管理员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="回复时间" prop="rebackTime">
        <el-date-picker clearable
          v-model="queryParams.rebackTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择回复时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('btn.search')}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{$t('btn.Reset')}}</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="['orderEvaluate:orderEvaluate: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="['orderEvaluate:orderEvaluate: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="['orderEvaluate:orderEvaluate: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="['orderEvaluate:orderEvaluate:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderEvaluateList" @selection-change="handleSelectionChange">
	  <el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
		<template slot-scope="scope">
			{{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
		</template>
	  </el-table-column>
	  <el-table-column :label="$t('table.commodityType')" align="center" prop="typeName" />
      <el-table-column :label="$t('table.commodityName')" align="center" prop="commodityName" />
	  <el-table-column :label="$t('table.customerName2')" align="center" prop="customerName" />
	  <el-table-column :label="$t('table.content1')" align="center" prop="content" />
	  <el-table-column :label="$t('table.createTime2')" align="center" prop="createTime" />
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="客户id" align="center" prop="customerId" />
      <el-table-column label="订单id" align="center" prop="orderId" />
      <el-table-column label="回复评价" align="center" prop="rebackContent" />
      <el-table-column label="回复管理员id" align="center" prop="rebackUserId" />
      <el-table-column label="回复时间" align="center" prop="rebackTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rebackTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column :label="$t('table.status3')" align="center" prop="status">
	  	<template slot-scope="scope">
          <span>{{scope.row.status=='1'?$t('table.replied'):$t('table.noReply')}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column :label="$t('table.operation')" 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="['orderEvaluate:orderEvaluate:edit']"
          >{{$t('table.detail')}}</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['orderEvaluate:orderEvaluate:remove']"
          >删除</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="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
		<el-form-item :label="$t('table.commodityType')">
          <el-input disabled v-model="form.typeName" />
        </el-form-item>
		<el-form-item :label="$t('table.commodityName')">
          <el-input disabled v-model="form.commodityName" />
        </el-form-item>
		<el-form-item :label="$t('table.customerName2')">
          <el-input disabled v-model="form.customerName" />
        </el-form-item>
		<el-form-item :label="$t('table.content1')">
		  <span v-html="form.content" ></span>
        </el-form-item>
		<el-form-item :label="$t('table.createTime2')">
          <el-input disabled v-model="form.createTime" />
        </el-form-item>
        <!-- <el-form-item label="客户id" prop="customerId">
          <el-input disabled v-model="form.customerId" placeholder="请输入客户id" />
        </el-form-item>
        <el-form-item label="订单id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单id" />
        </el-form-item> -->
		<el-divider content-position="center"></el-divider>
        <el-form-item v-if="form.status=='0'" :label="$t('dialog.rebackContent1')"> 
          <editor v-model="form.rebackContent" :min-height="192"/>
        </el-form-item>
		<el-form-item v-if="form.status=='1'" :label="$t('dialog.rebackContent2')"> 
			<editor v-model="form.rebackContent" :min-height="140"/>
			<!-- <span v-html='form.rebackContent'></span> -->
        </el-form-item>
        <!-- <el-form-item label="回复管理员id" prop="rebackUserId">
          <el-input v-model="form.rebackUserId" placeholder="请输入回复管理员id" />
        </el-form-item> -->
        <el-form-item v-if="form.status=='1'" :label="$t('dialog.rebackTime')" prop="rebackTime">
          <el-date-picker clearable disabled
            v-model="form.rebackTime"
            type="date"
            value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
		<el-form-item v-if="form.status=='1'" :label="$t('dialog.rebackUserName')">
          <el-input disabled v-model="form.rebackUserName" />
        </el-form-item>
        <!-- <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item> -->
      </el-form>
      <div v-if="form.status=='0'" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{$t('btn.submit')}}</el-button>
        <el-button @click="cancel">{{$t('btn.cancel')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderEvaluate, getOrderEvaluate, delOrderEvaluate, addOrderEvaluate, updateOrderEvaluate } from "@/api/orderEvaluate/orderEvaluate";

export default {
  name: "OrderEvaluate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单评价信息表格数据
      orderEvaluateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // customerId: null,
        // orderId: null,
        // content: null,
        // rebackContent: null,
        // rebackUserId: null,
        // rebackTime: null,
        status: null,
		'params[beginDate]':null,
		'params[endDate]':null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单评价信息列表 */
    getList() {
      this.loading = true;
      listOrderEvaluate(this.queryParams).then(response => {
        this.orderEvaluateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        customerId: null,
        orderId: null,
        content: null,
        rebackContent: null,
        rebackUserId: null,
        rebackTime: null,
        status: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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 = "新增订单评价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderEvaluate(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = this.$t('dialog.orderEvaluateTitel');
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) { 
            updateOrderEvaluate(this.form).then(response => {
              this.$modal.msgSuccess(this.$t('message.success6'));
              this.open = false;
              this.getList();
            });
          } else {
            addOrderEvaluate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单评价信息编号为"' + ids + '"的数据项？').then(function() {
        return delOrderEvaluate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('orderEvaluate/orderEvaluate/export', {
        ...this.queryParams
      }, `orderEvaluate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
