<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">



      <el-form-item label="医生名称" prop="doctorName">
        <el-input
          v-model="queryParams.doctorName"
          placeholder="请输入医生名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="评价时间" prop="pingTime">
         <el-date-picker v-model="pingTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
      </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-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="['his:inquiryOrderPing: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="['his:inquiryOrderPing: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="['his:inquiryOrderPing:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:inquiryOrderPing:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="pingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="orderSn" />
      <el-table-column label="会员昵称" align="center" prop="nickName" />
       <el-table-column label="会员电话" align="center" prop="phone" />
      <el-table-column label="医生名称" align="center" prop="doctorName" />
      <el-table-column label="评分" align="center" prop="pingStar" width="150px">
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.pingStar"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="pingTime" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['his:inquiryOrderPing:edit']"
          >修改</el-button>
          <el-button
                      size="mini"
                      type="text"
                      @click="handledetails(scope.row)"
                       icon="el-icon-share"
                    >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['his:inquiryOrderPing: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="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
       <el-form-item label="所属用户" prop="userId" v-if="form.pingId==null||form.pingId==''">
         <el-select v-model="form.userId" filterable placeholder="输入名称搜索"  :filter-method="remoteMethod">
              <el-option
                v-for="item in userList"
                :key="item.name"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
       </el-form-item>
        <el-form-item label="医生" prop="doctorId" v-if="form.pingId==null||form.pingId==''">
          <el-select v-model="form.doctorId" filterable placeholder="输入名称搜索" :filter-method="doctorMethod">
            <el-option
              v-for="item in docuser"
              :key="item.name"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="评分" prop="pingStar">
           <el-rate v-model="form.pingStar"></el-rate>
        </el-form-item>
        <el-form-item label="评价内容" prop="pingContent" >
          <el-input v-model="form.pingContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="医生回复" prop="replyContent" >
          <el-input v-model="form.replyContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="评价时间" prop="pingTime">
          <el-date-picker clearable size="small"
            v-model="form.pingTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择评价时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-drawer
         :with-header="false"
         size="75%"
          :title="show.title" :visible.sync="show.open">
      <inquiryOrderDetails  ref="Details" />
    </el-drawer>



  </div>
</template>

<script>
import { listPing, getPing, delPing, addPing, updatePing, exportPing } from "@/api/his/inquiryOrderPing";
import {getUserList,listdocuser} from "@/api/his/doctor";
import Editor from '@/components/Editor/wang';
import inquiryOrderDetails from '../../components/his/inquiryOrderDetails.vue';
export default {
  name: "Ping",
  components: { Editor,inquiryOrderDetails },

  data() {
    return {
      userList:[],
      // 遮罩层
      loading: true,
      show:{

        open:false,
          },
      userName: {name:"1"},
      doctorName: {name:"1"},
      docuser:[],

      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      pingTime:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评价管理表格数据
      pingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        doctorName: null,
        sTime:null,
        eTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {  userId: [
        { required: true, message: '请选择所属用户', trigger: 'blur' }
      ],
      doctorId: [
        { required: true, message: '请选择医生', trigger: 'blur' }
      ],
      pingStar: [
        { required: true, message: '请评分', trigger: 'blur' }
      ],
      pingContent: [
        { required: true, message: '请输入评价内容', trigger: 'blur' }
      ],
      pingTime: [
        { required: true, message: '请选择评价时间', trigger: 'change' }
      ]
      }
    };
  },
  created() {


    this.getList();
  },
  methods: {
     updateText(text){
          this.form.pingContent=text
        },
    getlistdocuser(){
        listdocuser(this.doctorName).then(response => {
          this.docuser=response.rows;
      });
    },

    doctorMethod(rows){
      this.doctorName.name=rows;
      this.getlistdocuser();
    },
    remoteMethod(rows){
      this.userName.name=rows;
      this.getUserList();
    },
    getUserList(){
      getUserList(this.userName).then(response => {
        this.userList=response.rows;
      });
    },
    change(){
      if(this.pingTime!=null){
        this.queryParams.sTime=this.pingTime[0];
        this.queryParams.eTime=this.pingTime[1];
      }else{
        this.queryParams.sTime=null;
        this.queryParams.eTime=null;
      }
    },
    handledetails(row){
      if(row.orderId==null){
        return this.$message('没有此订单');
      }
            this.show.open=true;
            setTimeout(() => {
                 this.$refs.Details.getDetails(row.orderId);
            }, 1);
        },
    /** 查询评价管理列表 */
    getList() {
      this.loading = true;
      listPing(this.queryParams).then(response => {
        this.pingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pingId: null,
        orderId: null,
        pingStar: null,
        pingContent: null,
        pingTime: null,
        userId: null,
        doctorId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.pingTime=null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pingId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加评价管理";

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pingId = row.pingId || this.ids
      getPing(pingId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改评价管理";

      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pingId != null) {
            updatePing(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPing(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pingIds = row.pingId || this.ids;
      this.$confirm('是否确认删除评价管理编号为"' + pingIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPing(pingIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有评价管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportPing(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
