
<template>
  <div>
    <basicLayout 
      ref="list" 
      formPath="contractManage"
      tableName="contractListTable" 
      idName="sa_contractid" 
      :apiId="{query:20221121201502,del:20221121202502}"
      :options="options"
      :detailPath="{
        path:'/contractDetail',
        param:{tabIndex:tabIndex}
      }"
      @listData="listdata"
      @listCreate="list">
      <div slot="titleRight" style="display:flex;margin-left:10px">
        <!-- <distribution class="inline-16" v-if="tool.checkAuth($route.name,'distributionAgent')" @onSuccess="$refs.basicLayout.listData()"></distribution> -->
<!--        <el-button size="small" @click="$router.push('/directSelling')">打印</el-button>-->
      </div>
      <template #custom>
        <div class="mt-10">
          <p class="search__label">范围:</p>
          <el-select
            class="inline-24"
            size="small"
            v-model="area"
            placeholder="请选择范围"
            @change="areaChange"
          >
            <el-option
              v-for="item in areaList"
              :key="item.index"
              :label="item.templetname"
              :value="item.templetid"
            ></el-option>
          </el-select>
        </div>
        <div class="mt-10">
          <p class="search__label">合同类型:</p>
          <el-select
            class="inline-24"
            size="small"
            v-model="type"
            placeholder="请选择合同类型"
            clearable
            @change="$refs.list.param.content.pageNumber=1;$refs.list.param.content.where.type=type;$refs.list.param.content.type = area;$refs.list.listData()"
          >
            <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.remarks"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>
        <div class="mt-10">
          <p class="search__label">合同状态:</p>
          <el-select
            class="inline-24"
            size="small"
            v-model="status"
            placeholder="请选择合同状态"
            clearable
            @change="$refs.list.param.content.pageNumber=1;$refs.list.param.content.where.type=type;$refs.list.param.content.type = area;$refs.list.param.content.where.status=status;$refs.list.listData()"
          >
            <el-option label="新建" value="新建" ></el-option>
            <el-option label="审核" value="审核" ></el-option>
            <el-option label="已提交" value="已提交" ></el-option>
            <el-option label="已终止" 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 == '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>
          <span style="color:#000000" v-else>{{scope.data.column.data[[scope.data.column.columnname]]}}</span>
        </div>
        <div v-else-if="scope.data.column.columnname == 'type'">
          <span v-if="scope.data.column.data[[scope.data.column.columnname]] == '框架'">经销商合作协议</span>
          <span v-else-if="scope.data.column.data.typemx == '经销'">经销项目协议</span>
          <span v-else-if="scope.data.column.data.typemx == '直销'">直销项目协议</span>
          <span v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '工具借用'">工具使用协议</span>
          <span v-else-if="scope.data.column.data[[scope.data.column.columnname]] == '居间'">居间协议</span>
        </div>
        <div v-else-if="scope.data.column.columnname == 'signamount'">
          <span>{{ tool.formatAmount(scope.data.column.data.signamount,1) }}</span>
        </div>
        <div  v-else-if="scope.data.column.columnname == 'discountrate'">
<!--          <div v-if="scope.data.column.data"></div>-->
<!--          {{scope.data.column.data[[scope.data.column.columnname]] <1 ?(scope.data.column.data[[scope.data.column.columnname]] * 100).toFixed(2):100}}-->
          <div v-if="scope.data.column.data.type === '框架'">
            {{scope.data.column.data.discountrate<1?Math.round((scope.data.column.data.discountrate * 100)*100)/100:100}}
          </div>
          <div v-else-if="scope.data.column.data.type === '居间'">
            <span v-if="scope.data.column.data.calculatemodel === 1">
              {{scope.data.column.data.orderratio<1?Math.round((scope.data.column.data.orderratio * 100)*100)/100:100}}
            </span>
            <span v-if="scope.data.column.data.calculatemodel === 2">
              {{scope.data.column.data.productdiscount<1?Math.round((scope.data.column.data.productdiscount * 100)*100)/100:100}}
            </span>
          </div>
          <div v-else>--</div>
        </div>
        <div v-else>
          {{scope.data.column.data[[scope.data.column.columnname]]}}
        </div>
        <span v-if="!scope.data.column.data[[scope.data.column.columnname]] && scope.data.column.data[[scope.data.column.columnname]] !== 0">--</span>
      </template>
      <template v-slot:tbOpreation="scope">
<!--        <el-button size="mini" @click="$router.push({path:'/directSelling',query:{id:scope.data.data.sa_contractid,sys_enterpriseid:scope.data.data.sys_enterpriseid}})" type="text" >打印</el-button>-->
      </template>
    </basicLayout>
  </div>
</template>

<script>
import { log } from '@antv/g2plot/lib/utils'
import {mapGetters} from "vuex";

export default {
  data () {
    return {
      DirectSellingShow:false,
      options:[],
      dateSelect:'',
      areaList:[
      ],
      typeList:[],
      area:'1',
      tabIndex:"1",
      type:'',
      condition:'',
      status:'',
      selectParam: {
        status: "",
        type: "",
        begindate:"",
        enddate:""
      },
    }
  },
  created () {
    this.getSystemList()
    this.getAgentList()
    this.queryUserInfo()
    this.querytemplet()
  },
  methods:{
    async getSystemList () {
      /*const res = await this.$store.dispatch('optiontypeselect','dataarea')
      this.areaList = res.data
      console.log(this.areaList);*/
      
      const res2 = await this.$store.dispatch('optiontypeselect','contracttype')
      this.typeList = res2.data
      console.log(res2.data,'项目类型')
    },
    async getAgentList () {
      let res = await this.$api.requested({
        "classname": "webmanage.sale.agents.agents",
        "method": "query_agentList",
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "agenttype":"经销商",
            "where": {
                "condition": ""
            }
        }
      })
      console.log(res.data);
      
    },
    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);
      
      window.sessionStorage.setItem('userInfo',JSON.stringify(this.userInfo))
      
    },
    list (params) {
      params.content.type = 1
      params.content.deleted = 0
    },
    listdata(data) {
      console.log(data);
      
    },
    areaChange(){
      this.tabIndex = this.area
      this.$refs.list.param.content.pageNumber=1;
      this.$refs.list.param.content.type=this.area;
      this.$refs.list.listData()
    },
    selectChange () {
      if (this.dateSelect !== '' && this.dateSelect !== null){
        this.selectParam.begindate = this.dateSelect[0]
        this.selectParam.enddate = this.dateSelect[1]
      }else {
        this.selectParam.begindate = ''
        this.selectParam.enddate = ''
      }
      this.$refs.list.param.content.type = this.area
      this.selectParam.type = this.type
      this.selectParam.status = this.status
      this.$refs.list.param.content.where = this.selectParam
      this.$refs.list.listData()
    },
    async querytemplet () {
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.querytemplet.querytemplet",
        "method":"query",
        "content": {}
      })
      this.areaList = res.data
      this.area = res.data[0].templetid
    }
  }
}

</script>
<style scoped>

</style>