<template>
  <div>
    <basicLayout
        ref="basicLayout"
        tableName="quotedPriceTable"
        idName="sa_quotedpriceid"
        :apiId="{query:20221020165103,del:''}"
        :autoQuery="false"
        @checkboxCallBack="checkboxCallBack"
    >
      <template #titleLight>
        <batchDeletion v-if="tool.checkAuth($route.name,'batchDeletion')" ref="batchDeletion" :ownerids="selectData" :sys_object="application" @delSuccess="queryData"></batchDeletion>
        <batchRecovery v-if="tool.checkAuth($route.name,'batchRecovery')" ref="batchRecovery" :ownerids="selectData" :sys_object="application" @recoverySuccess="queryData"></batchRecovery>
      </template>
      <template #custom>
        <div class="mt-10">
          <p class="search__label">应用:</p>
          <el-select
              class="inline-24"
              size="small"
              v-model="application"
              placeholder="请选择范围"
              @change="applicationChange"
          >
            <el-option
                v-for="item in applicationList"
                :key="item.index"
                :label="item.label"
                :value="item.value"
            ></el-option>
          </el-select>
        </div>
        <div class="mt-10">
          <label  class="search__label" >报价类型:</label>
          <el-select class="inline-24" v-model="selectParam.isproject" placeholder="请选择报价类型" @change="selectChange" size="small" clearable>
            <el-option
                v-for="item in isprojectList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="mt-10">
          <label  class="search__label" >状态:</label>
          <el-select class="inline-24" v-model="selectParam.status" placeholder="请选择状态" @change="selectChange" size="small" clearable>
            <el-option
                v-for="item in statusList"
                :key="item.value"
                :label="item.value"
                :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="mt-10">
          <label class="search__label" >创建日期:</label>
          <el-date-picker
              style="margin-right: 24px !important;"
              size="small"
              @change="selectChange"
              value-format="yyyy-MM-dd"
              v-model="dateSelect"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              clearable>
          </el-date-picker>
        </div>
      </template>
      <template v-slot:tbList="scope">
        <div v-if="scope.data.column.columnname === 'specialoffer'">
          <div v-if="scope.data.column.data.specialoffer === 0">
            否
          </div>
          <div v-else-if="scope.data.column.data.specialoffer === 1">
            是
          </div>
          <div v-else>--</div>
        </div>
        <div v-else-if="scope.data.column.columnname === 'tag'">
          <div v-for="item in scope.data.column.data.tag" :key="item.index"  style="float: left;margin-left: 5px;margin-bottom: 5px">
            <el-tag type="warning" size="mini">
              <span>{{item}}</span>
            </el-tag>
          </div>
          <div v-for="item in scope.data.column.data.tag_sys" :key="item.index"  style="float: left;margin-left: 5px;margin-bottom: 5px">
            <el-tag  size="mini">
              <span>{{item}}</span>
            </el-tag>
          </div>

        </div>
        <div v-else-if="scope.data.column.columnname === 'status'">
          <span style="color:#3874f6" v-if="scope.data.column.data[[scope.data.column.columnname]] == '新建'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
          <span style="color:#52c41a" v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '提交'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
          <span style="color:#333333" v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '审核'">{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
        </div>
        <div v-else-if="scope.data.column.columnname === 'invaliddate'">
          <p>{{scope.data.column.data.begdate?scope.data.column.data.begdate+ '至' + scope.data.column.data.enddate:'--'}}</p>
        </div>
        <div v-else-if="scope.data.column.columnname === 'salesman'">
          {{issaler?'--':scope.data.column.data.createby}}
        </div>
        <div v-else-if="scope.data.column.columnname === 'distributor'">
          {{issaler?scope.data.column.data.enterprisename:'--'}}
        </div>
        <div v-else>
          {{scope.data.column.data[[scope.data.column.columnname]]?scope.data.column.data[[scope.data.column.columnname]]:'--'}}
        </div>
      </template>
      <template v-slot:tbOpreation="scope">
        <delData class="inline-16" :ownerid="scope.data.data.sa_quotedpriceid" :sys_object="application" @delSuccess="queryData"></delData>
        <recovery class="inline-16" :ownerid="scope.data.data.sa_quotedpriceid" :sys_object="application" @recoverySuccess="queryData"></recovery>
      </template>
    </basicLayout>
  </div>
</template>

<script>
import recovery from "@/HManagement/ecycle/modules/recovery"
import delData from "@/HManagement/ecycle/modules/delData"
import batchDeletion from "@/HManagement/ecycle/modules/batchDeletion";
import batchRecovery from "@/HManagement/ecycle/modules/batchRecovery";
export default {
  name: "index",
  data () {
    return {
      application:'5',
      applicationList:[
        {
          label: '销售线索',
          value: "1",
        },
        {
          label: '客户',
          value: "2",
        },
        {
          label: '合同',
          value: "3",
        },
        {
          label: '项目商机',
          value: "4",
        },
        {
          label: '报价单',
          value: "5",
        }
      ],
      dateSelect:'',
      statusList:[
        {
          value:'新建'
        },
        {
          value:'提交'
        },
        {
          value:'审核'
        }
      ],
      isprojectList:[
        {
          label:'客户报价',
          value:'0'
        },
        {
          label:'项目报价',
          value:'1'
        }
      ],
      selectParam: {
        status:'',
        isproject:'',
        startdate:'',
        enddate:'',
      },
      selectData:[]
    }
  },
  components:{recovery,delData,batchDeletion,batchRecovery},
  methods:{
    queryData(){
      this.$refs.basicLayout.param.content.isAll = 0
      this.$refs.basicLayout.param.content.type = 0
      this.$refs.basicLayout.param.content.deleted = 1
      this.$refs.basicLayout.listData()
    },
    applicationChange(val){
      console.log(val)
      this.$emit("changeApplication",val)
    },
    selectChange(){
      this.tabIndex = this.tabName
      if (this.dateSelect !== '' && this.dateSelect !== null){
        this.selectParam.startdate = this.dateSelect[0]
        this.selectParam.enddate = this.dateSelect[1]
      }else {
        this.selectParam.startdate = ''
        this.selectParam.enddate = ''
      }
      this.$refs.basicLayout.param.content.type = 0
      this.$refs.basicLayout.param.content.where = this.selectParam
      this.$refs.basicLayout.listData()
    },
    /*是否经销商*/
    async isSaler(){
      const res = await this.$api.requested({
        classname: "common.usercenter.usercenter",
        content: {},
        method: "queryUserMsg"
      })
      this.issaler = res.data.hr.issaler
    },
    checkboxCallBack(val){
      this.selectData = []
      val.forEach((item,index) => {
        this.selectData[index] = item.sa_quotedpriceid
      })
      this.$refs.batchDeletion.length = this.selectData.length
      this.$refs.batchRecovery.length = this.selectData.length
      console.log(this.selectData)
    }
  },
  mounted() {
    this.queryData()
    this.isSaler()
  },
}
</script>

<style scoped>

</style>