<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="服务人员ID" prop="serverId">
        <el-input
          v-model="queryParams.serverId"
          placeholder="请输入服务人员ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>



      <el-form-item label="服务主题" prop="orderId">
        <el-input
          v-model="queryParams.goodName"
          placeholder="请输入服务主题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="服务人员姓名" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入服务主题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="服务人员手机号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入服务主题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商品评分" prop="score">
        <el-select v-model="queryParams.score" placeholder="请选择" size="mini" style="width: 100px">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        -
        <el-select v-model="queryParams.score" placeholder="请选择" size="mini" style="width: 100px">
          <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 label="评价日期" prop="score">
        <el-input
          v-model="queryParams.score"
          placeholder="请输入商品评分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </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-table :data="commentList"
             style="width: 100%">
     <el-table-column type="expand">
       <template slot-scope="props">
         <el-form label-position="left" inline class="demo-table-expand">

           <el-row>
             <el-col :span="24">
               <el-form-item label="评价内容">
                 <span>{{ props.row.content }}</span>
               </el-form-item>

             </el-col>

             <el-col  :span="24" style="margin-top:20px; ">
               <el-form-item label="视频图片">
                  <el-row>
                    <el-col v-for="item in resourceList" v-if="item.commentId==props.row.commontId" :span="12">
                      <video-play  v-if="item .type=='002'"  ></video-play>
                      <img  v-if="item.type=='001'"    :src=item.url>
                    </el-col>
                  </el-row>
               </el-form-item>
             </el-col>

             <el-col>
               <el-form-item label="追评">
                 <span>{{ props.row.reContent }}  {{props.row.reContentTime}}</span>
               </el-form-item>
             </el-col>

             <el-col>
               <el-form-item label="商家回复">
                 <span>{{ props.row.reply}}  {{ props.row.replyTime}}</span>
               </el-form-item>
             </el-col>

           </el-row>


           <br>
         </el-form>
       </template>
     </el-table-column>
     <el-table-column label="服务 ID" prop=""></el-table-column>
     <el-table-column label="服务主题" prop="goodName"></el-table-column>
     <el-table-column label="服务类型" prop="categoryName"></el-table-column>
     <el-table-column label="服务人员手机号"  prop="phone"></el-table-column>
     <el-table-column label="服务人员姓名" prop="realName"></el-table-column>
     <el-table-column label="评分" prop="goodScore"></el-table-column>
     <el-table-column label="各维度评分" prop="evaluate"></el-table-column>
     <el-table-column label="评价时间" prop="createTime"></el-table-column>
     <el-table-column label="操作">
       <template slot-scope="props">
         <el-button  v-if="props.row.reply==null" @click="handleUpdate(props.row)">回复</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 :visible.sync="open" :title="title" >
      <el-input
        type="textarea"
        placeholder="请输入内容"
        v-model="form.reply"
        maxlength="100"
        show-word-limit
      />

      <el-button @click="submitReply">保存</el-button>
      <el-button @click="cancel">取消</el-button>


    </el-dialog>



    </div>
</template>

<script>
  import { listComment, getComment, delComment, addComment, updateComment, exportComment } from "@/api/system/goodsComment";
  import VideoPlay from './videoPlay'
  import { listResource } from '../../api/system/goodsCommentResource'

  export default {
    name: 'index',
    components: { VideoPlay },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 商品评价表格数据
        commentList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          goodName:null,
          pageNum: 1,
          pageSize: 10,
          memberId: null,
          serverId: null,
          orderId: null,
          merchantId: null,
          goodsId: null,
          content: null,
          score: null,
          reply: null,
          replyTime: null,
          reContent: null,
          reContentTime: null,
          isAnonymous: null,
          column1: null,
          column2: null,
          column3: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          delFlag: [
            { required: true, message: "删除标志不能为空", trigger: "blur" }
          ],
        },
        options: [{
          value: '选项1',
          label: '0'
        }, {
          value: '选项2',
          label: '1'
        }, {
          value: '选项3',
          label: '2'
        }, {
          value: '选项4',
          label: '3'
        }, {
          value: '选项5',
          label: '4'
        }, {
          value: '选项6',
          label: '5'
        }],
        activeNames: [0],
        resourceList:[]

      };
    },

    created() {
      this.ListResource();
      this.getList();

    },
    methods: {
      updateReply(){
        this.open=true;
      },

      /** 获取商品评价资源*/
      ListResource(){
        listResource().then(res=>{
          this.resourceList=res.rows;
        })
      },

      /** 查询商品评价列表 */
      getList() {
        this.loading = true;
        listComment(this.queryParams).then(response => {
          this.commentList = response.rows;
        for(let i in this.commentList){
        if(this.commentList[i].reContentTime!=null){
          var zoneDate = new Date(this.commentList[i].reContentTime).toJSON();
          var date = new Date(+new Date(zoneDate)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
          this.commentList[i].reContentTime=date;
          }
        }
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 修改回复操作*/
      submitReply(){

        let yy = new Date().getFullYear();
        let mm = new Date().getMonth()+1;
        let dd = new Date().getDate();
        let hh = new Date().getHours();
        let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
        let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
        var gettime = yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
        this.form.replyTime=gettime;
        updateComment(this.form).then(res=>{
          this.open=false;
          this.getList();

        })
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          commontId: null,
          memberId: null,
          serverId: null,
          orderId: null,
          merchantId: null,
          goodsId: null,
          content: null,
          score: null,
          reply: null,
          replyTime: null,
          reContent: null,
          reContentTime: null,
          isAnonymous: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          column1: null,
          column2: null,
          column3: null,
          goodName: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.commontId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const commontId = row.commontId || this.ids
        getComment(commontId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改商品评价";
        });
      },

    }
  }
</script>

<style scoped>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }

</style>
