<template>
  <el-tabs v-model="activeName" @tab-click="handleClick">

    <el-tab-pane label="投诉消息" name="seventh">
      <!-- <div style="float: right;margin-right:2%;">
        <el-button style='margin: 10px 0;' :disabled="!isAuth('message:push')" size="mini" type="primary"
          icon="document" @click="magNotice">发布消息</el-button>
      </div> -->
      <el-table v-loading="tableDataLoading" :data="tableData.list">
        <el-table-column fixed prop="complaintId" label="编号" width="80">
        </el-table-column>
		<el-table-column prop="shopIllegal" label="投诉类型">
		</el-table-column>
		<el-table-column prop="indentNumber" label="订单号">
		</el-table-column>
        <el-table-column prop="nickName" label="投诉骑手">
          <template slot-scope="scope">
            <div v-if="scope.row.nickName" style="color: #00A0E9;">{{scope.row.nickName}}</div>
            <div v-else>未绑定</div>
          </template>
        </el-table-column>
       
        <el-table-column prop="wrongExplain" label="消息内容" width="280">
        </el-table-column>
		<el-table-column prop="deductMoney" label="扣款金额">
		</el-table-column>
		<el-table-column prop="auditMessage" label="审核说明">
		</el-table-column>
		<el-table-column prop="complaintState" label="状态">
			<template slot-scope="scope">
			  <div v-if="scope.row.complaintState==1">通过投诉</div>
			  <div v-if="scope.row.complaintState==2">申诉中</div>
			  <div v-if="scope.row.complaintState==3">申诉未通过</div>
			  <div v-if="scope.row.complaintState==4">申诉通过</div>
			  <div v-if="scope.row.complaintState==5">审核中</div>
			  <div v-if="scope.row.complaintState==6">拒绝投诉</div>
			</template>
		</el-table-column>
        <el-table-column prop="complaintTime" label="创建时间">
        </el-table-column>
       <!-- <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="updataDetails(scope.row)">用户详情
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <div style="text-align: center;margin-top: 10px;">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30,50,100]" :page-size="limit" :current-page="page" layout="total,sizes, prev, pager, next"
          :total="tableData.totalCount">
        </el-pagination>
      </div>
      <!-- 发布消息 -->
      <el-dialog title="发布消息" :visible.sync="dialogFormVisible2" center>
        <div style="margin-bottom: 10px;">
          <span style="width: 200px;display: inline-block;text-align: right;">选择：</span>
          <el-select v-model="flag" placeholder="请选择类型" style="width:50%">
            <el-option v-for="item in flags" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <div style="margin-bottom: 10px;" v-if="flag == 1">
          <span style="width: 200px;display: inline-block;text-align: right;">用户手机号：</span>
          <el-input style="width: 50%;" v-model="phone" placeholder="请输入用户手机号"></el-input>
        </div>
        <div style="margin-bottom: 10px;">
          <span style="width: 200px;display: inline-block;text-align: right;">消息标题：</span>
          <el-input style="width: 50%;" v-model="title" placeholder="请输入消息标题"></el-input>
        </div>
        <div style="margin-bottom: 10px;">
          <span style="width: 200px;display: inline-block;text-align: right;position: relative;top: -65px;">消息内容：</span>
          <el-input style="width: 50%;" type="textarea" rows="4" v-model="content" placeholder="请输入消息内容"></el-input>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible2 = false">取 消</el-button>
          <el-button type="primary" @click="magNoticeTo()">确 定</el-button>
        </div>
      </el-dialog>
    </el-tab-pane>
	<el-tab-pane label="意见反馈" name="first">
	  <div class="content_item">
	  	<span>QQ/邮箱:</span>
	  	<el-input style="width:50%;" class="margin15" placeholder="方便我们联系你"
	  		v-model="userEmail" autosize></el-input>
	  </div>
	  <div class="content_item">
	  	<span style="position: relative;top: -65px;">问题和意见:</span>
	  	<el-input style="width:50%;"  type="textarea" :rows="4" class="margin15"
	  		placeholder="请详细描述你的问题和意见" v-model="feedbackMessage"></el-input>
	  </div>
	  <div class="shop_item" style="text-align:left;margin-left: 20%;">
	  	
	  		<el-button style="margin-bottom: 20px;" type="primary" @click="saveClick">提交
	  		</el-button>
	  </div>
	</el-tab-pane>
    <!-- <el-tab-pane label="意见反馈" name="first">
      <div style="position: relative;display: inline-block;margin: 10px 0px;">
        <span>类型：</span>
        <el-select v-model="types" style="width:150px;margin-left: 10px;" @change="animeDat(types)">
          <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>&nbsp;&nbsp;&nbsp;
      </div>
      <el-table v-loading="tableDataLoading" :data="tableData.list">
        <el-table-column prop="feedbackId" label="编号" width="80">
        </el-table-column>
        <el-table-column prop="feedbackType" label="类型">
          <template slot-scope="scope">
            <div v-if="scope.row.feedbackType==1">用户反馈</div>
            <div v-if="scope.row.feedbackType==2">商户反馈</div>
          </template>
        </el-table-column>
        <el-table-column prop="userEmail" label="邮箱">
        </el-table-column>
        <el-table-column prop="feedbackMessage" label="内容">
        </el-table-column>
        <el-table-column prop="feedbackTime" label="提交时间" width="160">
        </el-table-column>
      </el-table>
      <div style="text-align: center;margin-top: 10px;">
        <el-pagination @size-change="handleSizeChange1" @current-change="handleCurrentChange1"
          :page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page" layout="total,sizes, prev, pager, next"
          :total="tableData.totalCount">
        </el-pagination>
      </div>
    </el-tab-pane> -->
  </el-tabs>
</template>

<script>
  export default {
    data() {
      return {
        limit: 10,
        page: 1,
        state: 2,
        url: '',
        title: '',
        type: '',
        id: '',
        types: [{
            value: 'word',
            label: '文字'
          },
          {
            value: 'url',
            label: '链接'
          }
        ],
        form: {
          id: '',
          title: '',
          url: '',
          type: '',
          state: '',
          types: [{
              value: 'word',
              label: '文字'
            },
            {
              value: 'url',
              label: '链接'
            }
          ],
        },
        phone: '',
        content: '',
        flag: '',
        flags: [{
            value: 1,
            label: '单个用户'
          },
          {
            value: 2,
            label: '全部用户'
          }
        ],
        formLabelWidth: '200px',
        activeName: 'seventh',
        tableDataLoading: false,
        dialogFormVisible1: false,
        dialogFormVisible2: false,
        dialogFormVisible: false,
        tableData: [],
        typeList:[
          {
            value:'',
            label:'全部'
          },
          {
            value:1,
            label:'用户反馈'
          },
          {
            value:2,
            label:'商户反馈'
          },
        ],
        types:'',
				shopId:'',
				userEmail:'',
				feedbackMessage:'',
      }
    },
    methods: {
      // 详情跳转
      updataDetails(row) {
        this.$router.push({
          path: '/userDetail',
          query: {
            userId: row.userId
          }
        });
      },
      handleSizeChange(val) {
        this.limit = val;
        this.dataSelect()
      },
      handleCurrentChange(val) {
        this.page = val;
        this.dataSelect()
      },
      handleSizeChange1(val) {
        this.limit = val;
        this.dataSelect1()
      },
      handleCurrentChange1(val) {
        this.page = val;
        this.dataSelect1()
      },
      handleClick(tab, event) {
        if (tab._props.label == '意见反馈') {
          // this.page = 1
          // this.limit = 10
          // this.dataSelect1()
        }
        
        if (tab._props.label == '投诉消息') {
          this.page = 1
          this.limit = 10
          // this.state = 8
          this.dataSelect()
        }
      },
      // 消息推送
      magNotice() {
        this.dialogFormVisible2 = true
      },
      // 消息推送
      magNoticeTo() {
        if (this.flag == '') {
          this.$notify({
            title: '提示',
            duration: 1800,
            message: '请选择类型',
            type: 'warning'
          });
          return
        }
        if (this.title == '') {
          this.$notify({
            title: '提示',
            duration: 1800,
            message: '请输入标题',
            type: 'warning'
          });
          return
        }
        if (this.content == '') {
          this.$notify({
            title: '提示',
            duration: 1800,
            message: '请输入内容',
            type: 'warning'
          });
          return
        }
        if (this.flag == 1) {
          if (this.phone == '') {
            this.$notify({
              title: '提示',
              duration: 1800,
              message: '请输入用户手机号',
              type: 'warning'
            });
            return
          }
          this.$http({
            url: this.$http.adornUrl('/cash/sendMsg'),
            method: 'get',
            params: this.$http.adornParams({
              'title': this.title,
              'content': this.content,
              'phone': this.phone,
              'flag': this.flag
            })
          }).then(({
            data
          }) => {
            this.dialogFormVisible2 = false
            if (data.code == -100) {
              this.$message({
                message: data.msg,
                type: 'error',
                duration: 1500,
                onClose: () => {
                  this.title = ''
                  this.content = ''
                  this.phone = ''
                  this.flag = ''
                  this.dataSelect()
                }
              })
            }
            if (data.code == 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.title = ''
                  this.content = ''
                  this.phone = ''
                  this.flag = ''
                  this.dataSelect()
                }
              })
            }
          })
        }
        if (this.flag == 2) {
          this.$http({
            url: this.$http.adornUrl('/cash/sendMsg'),
            method: 'get',
            params: this.$http.adornParams({
              'title': this.title,
              'content': this.content,
              'flag': this.flag,
            })
          }).then(({
            data
          }) => {
            this.dialogFormVisible2 = false
            if (data.code == 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.title = ''
                  this.content = ''
                  this.flag = ''
                  this.dataSelect()
                }
              })
            }
          })
        }
      },
      // 获取数据列表
      dataSelect() {
        this.tableDataLoading = true
		this.shopId = this.$cookie.get('shopId')
        this.$http({
          url: this.$http.adornUrl('app/shop/selectComplaint'),
          method: 'get',
          params: this.$http.adornParams({
            'page':this.page,
            'limit':this.limit,
			'shopId':this.shopId
          })
        }).then(({
          data
        }) => {
          this.tableDataLoading = false
          let returnData = data.data;
          this.tableData = returnData
        })
      },
      // 获取数据列表
      dataSelect1() {
        this.tableDataLoading = true
        this.$http({
          url: this.$http.adornUrl('admin/dataCentre/selectFeedbackList'),
          method: 'get',
          params: this.$http.adornParams({
            'page':this.page,
            'limit':this.limit,
            'feedbackType':this.types
          })
        }).then(({
          data
        }) => {
          this.tableDataLoading = false
          let returnData = data.data;
          this.tableData = returnData
        })
      },
      animeDat(){
        this.page = 1
        this.dataSelect1()
      },
	  // 提交反馈意见
	  saveClick(){
		  this.$http({
		    url: this.$http.adornUrl('app/shop/userFeedback'),
		    method: 'post',
		    data: this.$http.adornParams({
		      'shopId':this.shopId,
		      'userEmail':this.userEmail,
		      'feedbackMessage':this.feedbackMessage
		    })
		  }).then(({
		    data
		  }) => {
		    if(data.code==0){
				this.$message({
					message: '提交成功！',
					type: 'success',
					duration: 1500,
					onClose: () => {
						this.userEmail = ''
						this.feedbackMessage = ''
					}
				})
			}else{
				this.$message({
					message: data.msg,
					type: 'warning',
					duration: 1500,
					onClose: () => {
					}
				})
			}
		  })
	  }
    },
    mounted() {
      this.dataSelect()
    }
  };
</script>

<style>
.content_item {
		margin-bottom: 20px;
	}

	.content_item span {
		display: inline-block;
		width: 120px;
		text-align: left;
	}
</style>
