<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @change="resetSearch" clearable standout="bg-primary text-white" class="col-6 q-pr-lg q-pr-lg"
            v-model="msg.LinkMan" label="联系人" maxlength="20" @clear="resetSearch" />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" standout="bg-primary text-white" class="col-6 q-pr-lg q-pr-lg"
            v-model="msg.DealStatus" :options="DealStatusList" emit-value map-options label="处理状态" />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" standout="bg-primary text-white" class="col-6 q-pr-lg q-pr-lg"
            v-model="msg.Status" :options="ShowOpts" emit-value map-options label="状态" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" :data="data" :columns="columns" row-key="name">
        <template v-slot:top="props">
          <div class="col-2 q-table__title">咨询信息</div>
        </template>
        <template v-slot:body-cell-DealStatusStr="props">
          <q-td>
            <span v-if="props.row.DealStatus==1" style="color:rgb(103, 194, 58)">{{props.row.DealStatusStr}}</span>
            <span v-if="props.row.DealStatus==0" style="color:rgb(233, 82, 82)">{{props.row.DealStatusStr}}</span>
          </q-td>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" v-if="props.row.DealStatus==0" icon="edit" color="accent" style="font-weight:400"
              label="处理" @click="EditConsult(props.row)" />
            <q-btn flat size="xs" icon="iconfont icon-View" color="accent" @click="goView(props.row)"
              style="font-weight:400" label="查看" />
            <q-btn flat size="xs" icon="delete" color="negative" style="font-weight:400" label="删除"
              @click="delConsult(props.row)" />
          </q-td>
        </template>
      </q-table>
      <consult-form v-if="isShowConsultForm" :save-obj="consultObjOption" @close="closeConsultForm"
        @success="refreshPage">
      </consult-form>
    </div>
  </div>
</template>
<script>
  import {
    GetWebAdvisoryPage,
    RemoveWebAdvisoryStatus
  } from '../../api/system/webkit'
  import consultForm from '../../components/system/consult-form'
  export default {
    meta: {
      title: "咨询管理"
    },
    components: {
      consultForm
    },
    data() {
      return {
        columns: [{
            name: 'SourceName',
            label: '项目名称',
            field: 'SourceName',
            align: 'left'
          }
          , {
            name: 'AdvTypeStr',
            label: '类型',
            field: 'AdvTypeStr',
            align: 'left'
          },
          , {
            name: 'LinkMan',
            label: '客户',
            field: 'LinkMan',
            align: 'left'
          },
          {
            name: 'LinkTel',
            label: '客户电话',
            field: 'LinkTel',
            align: 'left'
          },
          {
            name: 'Remark',
            label: '咨询内容',
            field: 'Remark',
            align: 'left'
          },
          {
            name: 'DealStatusStr',
            label: '处理状态',
            field: 'DealStatusStr',
            align: 'left'
          },
          {
            name: 'DealByName',
            label: '处理人',
            field: 'DealByName',
            align: 'left'
          },
          {
            name: 'DealTimeStr',
            label: '处理时间',
            field: 'DealTimeStr',
            align: 'left'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'MenuId'
          }
        ],
        data: [],
        loading: true,
        DealStatusList: [{
          value: -1,
          label: '全部'
        }, {
          value: 0,
          label: '待处理'
        }, {
          value: 1,
          label: '已处理'
        }],
        ShowOpts: [{
            label: '全部',
            value: -1
          },
          {
            label: '正常',
            value: 0
          },
          {
            label: '删除',
            value: 1
          }
        ],
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          LinkMan: '', //联系人
          DealStatus: -1, //处理状态(0-待处理,1-已处理)
          Status: -1
        },
        pageCount: 0,
        isShowConsultForm: false,
        consultObjOption: null,
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList()
      },
      //获取菜单分页列表
      getList() {
        this.loading = true;
        GetWebAdvisoryPage(this.msg).then(res => {
          this.loading = false
          this.data = res.Data.PageData;
          this.pageCount = res.Data.PageCount;
        }).catch(() => {
          this.loading = false
        })
      },
      //刷新页面
      refreshPage() {
        if (!this.consultObjOption) {
          this.msg.pageIndex = 1;
          this.msg.LinkMan = "";
          this.msg.DealStatus = -1;
          this.msg.Status = -1;
        }
        this.getList()
      },
      //新增修改菜单
      EditConsult(obj) {
        if (obj) {
          this.consultObjOption = obj
        } else {
          this.consultObjOption = null
        }
        this.consultObjOption.isView = -1;
        this.isShowConsultForm = true
      },
      //点击预览
      goView(obj) {
        if (obj) {
          this.consultObjOption = obj
        } else {
          this.consultObjOption = null
        }
        this.consultObjOption.isView = 1;
        this.isShowConsultForm = true
      },
      //关闭弹窗
      closeConsultForm() {
        this.isShowConsultForm = false
      },
      //删除
      delConsult(obj) {
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          let delMsg = {
            Id: obj.Id,
            Status: 1
          }
          RemoveWebAdvisoryStatus(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '操作成功',
                position: 'top'
              })
              this.getList();
            }
          })
        })
      }
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
