<template>
  <div class="app-container">
    <el-form class="mediaQueryForm" :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="90px" v-show="showSearch" :rules="rules">
      <el-row>
        <el-col :span="8">
          <el-form-item class="treeselectForm treeselectForm2" label="组织架构" prop="deptIds">
            <tree @treeselectFn="treeselectFn" :treeval="deptIds" style="width: 203px;"></tree>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="起止时间" prop="datetimerange">
            <el-date-picker
              style="width: 203px;"
              v-model="queryParams.datetimerange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="datetimeRangeChange">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="任务名称" prop="summaryTaskName">
            <el-input
              v-model="queryParams.summaryTaskName"
              placeholder="请输入任务名称"
              clearable
              style="width: 203px;"
              @input="onInput()"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="销售员" prop="userId">
            <user :userId="queryParams.userId" :orgIds="deptIds" @userIdFn="userIdFn" style="width: 203px;"></user>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
          >导出</el-button>
        </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-row :gutter="10" v-show="imgList.length>0">
      <el-col :span="4" v-for="(item,index) in imgList" :key="index">
        <el-card class="imgCard" :body-style="{ padding: '0px' }">
          <el-image
            style="width: 100%;height:200px;"
            :src="item.fileUrl"
            :preview-src-list="previewsrcList">
          </el-image>
          <div style="padding: 14px;">
            <div class="info">
              <el-tooltip :content="item.userName" placement="top-start">
                <templete>
                  <span>销售员：</span>{{item.userName}}
                </templete>
              </el-tooltip>
            </div>
            <div class="info">
              <el-tooltip :content="item.shootTime" placement="top-start">
                <templete>
                  <span>拍摄日期：</span>{{item.shootTime}}
                </templete>
              </el-tooltip>
            </div>
            <div class="info">
              <el-tooltip :content="item.deptName" placement="top-start">
                <templete>
                  <span>组织架构：</span>{{item.deptName}}
                </templete>
              </el-tooltip>
            </div>
            <div class="info">
              <el-tooltip :content="item.customName" placement="top-start">
                <templete>
                  <span>任务名称：</span>
                  {{item.summaryTaskName}}
                </templete>
              </el-tooltip>
            </div>
            <div class="info">
              <el-tooltip :content="item.customName" placement="top-start">
                <templete>
                  <span>问题名称：</span>
                  {{item.customName}}
                </templete>
              </el-tooltip>
            </div>
<!--            <div class="info"><span>描述：</span>{{item.remark}}</div>-->
          </div>
        </el-card>
      </el-col>
    </el-row>
    <div v-show="imgList.length<=0">
      <el-empty :image-size="200"></el-empty>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listSummaryImg,packImg } from "@/api/sfa/summaryImg";
import tree from "@/views/components/sfa/treeselectParent";
import user from "@/views/components/sfa/user";
export default {
  name: "Media",
  components: { tree,user },
  data() {
    return {
      // 查询参数
      queryParams: {
        code: null,
        name: null,
        brandCode: null,
        spec: null,
        level1: null,
        summaryTaskName:"",
        isValid: null,
          deptIds:[],
          userId:null,
          datetimerange:[],
          pageNum: 1,
          pageSize: 30,
      },
        total: 0,
        deptIds:[],
        mediaTypeOptions:[],
        mediaType:'',
        imgList:[],
        previewsrcList: [],
        storeTypeOptions:[],
        showSearch: true,
        rules:{
            datetimerange: [ { required: true, message: '请选择起止时间', trigger: 'change' }],
        },
    };
  },
  created() {
      // 是否
      this.getDicts("is_not").then(response => {
          this.isNotOptions = response.data;
      });
      // 层次一
      this.getDicts("sfa_level1").then(response => {
          this.level1Options = response.data;
      });
      // 品牌
      this.getDicts("sfa_product_brand").then(response => {
          this.brandIdOptions = response.data;
      });
      // 媒体类型
      this.getDicts("sfa_task_photo_type").then(response => {
          this.mediaTypeOptions = response.data;
      });
      // 门店类型
      if(this.$store.state.user.type == '2'){
          this.getDicts("ysl_store_type").then(response => {
              this.storeTypeOptions = response.data;
          });
      }else{
          this.getDicts("sfa_store_type").then(response => {
              this.storeTypeOptions = response.data;
          });
      }
      this.queryParams.datetimerange[0] = this.dateInit();
      this.queryParams.datetimerange[1] = this.dateInit();
    this.getList();
  },
  methods: {
      dateInit(){
          let date = new Date();
          let year = date .getFullYear();
          let month = date.getMonth() + 1;
          let day = date.getDate();
          if (month < 10) {
              month = "0" + month;
          }
          if (day < 10) {
              day = "0" + day;
          }
          let nowDate = year + "-" + month + "-" + day;
          return nowDate;
      },
      onInput(){
          this.$forceUpdate();
      },
    /** 查询产品信息列表 */
    getList() {
        // let url = '';
        // process.env.NODE_ENV == 'development' ? url = process.env.VUE_APP_Target : url = process.env.VUE_APP_BASE_API;
        this.previewsrcList = [];
        let { summaryTaskName, userId, pageSize,pageNum} = this.queryParams;
        let queryParams = { summaryTaskName, userId , pageSize,pageNum};
        queryParams.deptIds= this.deptIds.join(",");
        queryParams.startTime = this.queryParams.datetimerange[0];
        queryParams.stopTime = this.queryParams.datetimerange[1];
        listSummaryImg(queryParams).then(response => {
          this.imgList =  response.rows;
          this.total = response.total;
          this.imgList.forEach((item,index)=>{
            item.fileUrl = item.fileUrl;
            this.previewsrcList.push(item.fileUrl);
          })
      });
    },
      treeselectFn(val){
          this.deptIds = val;
      },
      userIdFn(val){
          this.queryParams.userId = val;
      },
    /** 搜索按钮操作 */
    handleQuery() {
        this.$refs['queryForm'].validate((valid) => {
            if (valid) {
                this.getList();
            }
        })

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    datetimeRangeChange(val){

    },
    handleExport(){
        let queryParams = this.queryParams;
        queryParams.deptIds= this.deptIds.join(",");
        queryParams.startTime = this.queryParams.datetimerange[0];
        queryParams.stopTime = this.queryParams.datetimerange[1];
        packImg(queryParams).then(response => {
            if(response.code ==200){
                this.$modal.msgSuccess(response.msg);
            }
        })
    }
  }
};
</script>
<style lang="scss" scoped>
  .imgCard{
    margin-top: 10px;
    .info{
      font-size: 14px;
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
      line-height: 30px;
      span{
        font-weight: bold;
      }
    }
  }
</style>
<style lang="scss">
  .mediaQueryForm .el-form-item{
    height: 29px;
  }
</style>
