<template>
  <view>
    <uni-card>
      <uni-search-bar :radius="100" @confirm="search" placeholder="请输入身份证号或手机号搜索" v-model="form.lrZjhm"></uni-search-bar>
      <uni-list>
        <uni-swipe-action>
          <!-- 刷脸激活：['0','3','4','6','9']；无刷脸激活：['1','2','5','7','8']-->
          <uni-swipe-action-item v-for="(item,index) in dataList" :key="index" :right-options="options"
            :disabled="['1','2','5','7','8'].includes(item.lzzt)||isShow" @click="swipeClick(item.id)">
            <uni-list-item :to="'/pages/lr/info?id='+ item.id" :title="item.lrXm"
              :thumb="item.lrTx ? config.baseUrl+item.lrTx : config.baseUrl+config.head" :note="item.lrCydh" thumbSize="lg" :showArrow="false">
              <template v-slot:footer>
                <view v-if="item.lzzt == '0'" class="item-right">
                  <text v-if="item.jssj">{{item.jssj.substring(0,8) }}</text>
                  <text v-else>{{item.createTime.substring(0,8) }}</text>
                  <image class="item-img" src="@/static/images/caogao.png" mode=""></image>
                  <!-- <text>{{item.lrSpyj || '无'}}</text> -->
                </view>
                <view v-else-if="['1','2','5','7','8'].includes(item.lzzt)" class="item-right">
                  <text v-if="item.jssj">{{item.jssj.substring(0,8) }}</text>
                  <text v-else>{{item.createTime.substring(0,8) }}</text>
                  <image class="item-img" src="@/static/images/daishenhe.png" mode=""></image>
                </view>
                <view v-else-if="item.lzzt == '3'" class="item-right">
                  <text v-if="item.jssj">{{item.jssj.substring(0,8) }}</text>
                  <text v-else>{{item.createTime.substring(0,8) }}</text>
                  <image class="item-img" src="@/static/images/tongguo.png" mode=""></image>
                </view>
                <view v-else-if="item.lzzt == '4' || item.lzzt == '9'" class="item-right">
                  <text v-if="item.jssj">{{item.jssj.substring(0,8) }}</text>
                  <text v-else>{{item.createTime.substring(0,8) }}</text>
                  <image class="item-img" src="@/static/images/jujue.png" mode=""></image>
                </view>
              </template>
            </uni-list-item>
          </uni-swipe-action-item>
        </uni-swipe-action>

      </uni-list>
      <uni-load-more status="status" @clickLoadMore="clickLoadMore"></uni-load-more>
    </uni-card>
  </view>
</template>

<script>
  import {
    getToken,
    getUser
  } from '@/common/auth.js'
  import { ListKhjbxx, GetUrl, CheckReturn } from '@/api/kh.js'
  import {
    decryptRowData_ECB
  } from '@/common/sm4.js'

  export default {
    components: {},
    data() {
      return {
        status: 'more',
		isShow:false,
        form: {
          pageNum: 1,
          pageSize: 8,
        },
        dataList: [],
        options: [
          {
            text: '刷脸激活',
            style: {
              backgroundColor: '#28d87d'
            }
          }
        ],
        total: 0,
      }
    },
    onLoad: function(options) {
      if (options.id) {
        this.form.pageNum = 1
        this.form.pageSize = 8
        this.form.id = options.id
      }
      this.userInfo = getUser()
	  console.log(this.userInfo,'<----this.userInfo');
      if (['04', '07'].includes(this.userInfo.userType)) {
        this.form.createUserId = this.userInfo.userId
      }
	  if(['04'].includes(this.userInfo.userType)&&this.userInfo.lrzptype)
	  {
		  if(this.userInfo.lrzptype=='1')
		  {
			  this.isShow=true;
		  }
	  }
      this.getList()
    },
    onPullDownRefresh() {
      this.dataList = []
      this.form.pageNum = 1
      this.form.pageSize = 10
      if (this.userInfo.userType != '07') {
        this.form.id = null
      } else {
        this.form.id = this.userInfo.userId
      }
      this.getList()
    },
    onReachBottom() {
      if (this.dataList.length < this.total) {
        this.form.pageNum += 1
        this.getList()
      }
    },
    methods: {
      swipeClick(id) {
        let param = {
          id: id,
          url: this.config.redirectUrl + id,
        }
		uni.showLoading({
			title: '加载中...',
			mask: true,
		})
        GetUrl(param).then(res => {
			uni.hideLoading();
          if (res.code == 200) {
            window.open(res.data.url, '_self');
          } else {
            toast('该功能暂未开放')
            // uni.navigateBack()
          }
        })
      },
      search() {
        this.dataList = []
        this.form.pageNum = 1
        this.form.pageSize = 10
        this.getList()
      },
      clickLoadMore(e) {
        this.status = 'loading'
        if (this.dataList.length < this.total) {
          this.form.pageNum += 1
          this.getList()
        } else {
          this.status = 'no-more'
        }
      },
      getList() {
        console.log(this.form);
		console.log(this.userInfo.userType,'this.userInfo.userType');
		console.log(this.userInfo.lrzptype,'this.userInfo.lrzptype');
		console.log(this.userInfo,'this.userInfo');
		let parm={}
		// 当前为员工并且lrzptype为可以录入照片且输入身份证号时  才传mchnt
		 if(['04'].includes(this.userInfo.userType)&&this.userInfo.lrzptype&&this.userInfo.lrzptype!='2'&&this.form.lrZjhm)
        {
        	parm={
				...this.form,createUserId:'',mchnt:this.userInfo.mchnt
			}	
        }else{
			parm={
				...this.form,createUserId:this.form.lrZjhm?'':this.form.createUserId,
			}	
		}
		
		ListKhjbxx(parm).then(res => {
          if (res.code == 200) {
            this.total = res.total
            let list = decryptRowData_ECB(res.rows, ["lrZjhm", "lrXm", "lrHjbcxx", "lrXjdzBcxx",
							"lrCydh", "lrPoxm", "lrPoZjmh", "jhrXm", "jhrSjhm", "zlrXm", "zlrDh", "cjzh",
							"yhzh", "khmc"
						], [2, 1, 4, 4, 3, 1, 2, 1, 2, 1, 3, 5, 5, 5])
            this.dataList.push(...list)
            uni.stopPullDownRefresh();
            if (this.dataList.length < this.total) {
              this.status = 'more'
            } else if (this.dataList.length == this.total) {
              this.status = 'no-more'
            }
          }
        })
      }
    },
    watch: {},
  }
</script>

<style lang="scss" scoped>
  .item-right {
    width: 60px;
    display: flex;
    flex-direction: column;
    background-position: left;
    background-size: 58px 58px;
    background-repeat: no-repeat;
    position: relative;
    font-size: 14px;

    .item-img {
      position: absolute;
      right: -5px;
      bottom: -10px;
      height: 40px;
      width: 40px;
    }
  }
</style>