<template>
  <div>
    <basicLayout
        ref="quotedPriceList"
        formPath="QuotedPrice"
        tableName="quotedPriceTable"
        idName="sa_quotedpriceid"
        :apiId="{query:20221020165103,del:20221020165503}"
        :options="options"
        :detail-path="{path:'/quotedPriceDetail'}"
        @listCreate="list"
        @listData="list2"
      >
      <div slot="titleRight">
<!--        <importExcel style="margin-left:10px" @onSuccess="onSuccess"></importExcel>-->
      </div>
      <template #custom >
        <div class="mt-10">
          <label  class="search__label" >范围:</label>
          <el-select class="inline-24" v-model="tabName" placeholder="请选择数据分类" @change="selectChange" size="small" clearable>
            <el-option
              v-for="item in editableTabs"
              :key="item.index"
              :label="item.templetname"
              :value="item.templetid"
            ></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 === 'name'">
          <span>{{scope.data.column.data.leader.length !== 0?scope.data.column.data.leader[0].name:'--'}}</span>
        </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">
        <el-button size="mini" type="text" @click="$router.push({path:'/quotedPriceDetail',query:{id:scope.data.data.sa_quotedpriceid,rowindex:scope.data.data.rowindex}})">详情</el-button>
      </template>-->
    </basicLayout>

  </div>
</template>

<script>
import importExcel from './modules/importQuotedPrice.vue'
export default {
  name: "index",
  components:{
    importExcel
  },
  data(){
    return {
      issaler:false,
      options:[],
      tabName:"1",
      tabIndex:"1",
      dateSelect:'',
      editableTabs: [],
      statusList:[
        {
          value:'新建'
        },
        {
          value:'提交'
        },
        {
          value:'审核'
        }
      ],
      isprojectList:[
        {
          label:'客户报价',
          value:'0'
        },
        {
          label:'项目报价',
          value:'1'
        }
      ],
      selectParam: {
        status:'',
        isproject:'',
        startdate:'',
        enddate:'',
      },
    }
  },
  methods:{
    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.quotedPriceList.param.content.type = this.tabIndex
      this.$refs.quotedPriceList.param.content.where = this.selectParam
      this.$refs.quotedPriceList.listData()
    },
    /*是否经销商*/
    async isSaler(){
      const res = await this.$api.requested({
        classname: "common.usercenter.usercenter",
        content: {},
        method: "queryUserMsg"
      })
      this.issaler = res.data.hr.issaler
    },
    async queryUserInfo() {
      let res = await this.$api.requested({
        "classname": "common.usercenter.usercenter",
        "method": "queryUserMsg",
        "content": {
        }
      })

      this.userInfo = {
        isAuth : res.data.hr.isleader,
        userid: res.data.hr.userid
      }
      console.log(this.userInfo,'user')
      window.sessionStorage.setItem('userInfo',JSON.stringify(this.userInfo))
      console.log(JSON.parse(window.sessionStorage.getItem('userInfo')));

    },
    list (param) {
      param.content.isAll = 0
      param.content.deleted = 0
      param.content.type = 1
    },
    list2 (data) {


    },
    async querytemplet () {
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.querytemplet.querytemplet",
        "method":"query",
        "content": {}
      })
      this.editableTabs = res.data
      this.tabName = res.data[0].templetid
    }
  },
  mounted() {
    this.isSaler()
  },
  created() {
    this.queryUserInfo()
    this.querytemplet()
  }
}
</script>

<style scoped>

</style>