index.js 3.35 KB
// packageWorkspace/pages/residentManage/components/staffSelectPopup/index.js
import api from '../../api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        if (n) {
          this.setData({
            pageNum: 1,
            nothing: false,
            keyword:'',
            staffName:'',
			scrollTop: 0,
			selectedObj: wx.$util.deepClone(this.data.selectedObj),
			staffList: [],
			isFlag: false
          }, () => {
            this.getData()
          })

        }
      }
    },
	sceneLabel: String,
	selectedObj: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    keyword: '',
    staffName: '',
    scrollTop: 0,
    nothing: false,
    isFlag: false,
    total: 0,
    pageNum: 1,
	pageSize: 20,
	selectItem: {},
    staffList: []
  },
  /**
   * 组件的方法列表
   */
  methods: {
    clear() {
      this.setData({
        keyword: "",
        staffName:''
      });
      this.search();
    },
    input(e) {
      let {
        value
      } = e.detail;
      this.setData({
        keyword: value
      });
    },
    search() {
      this.setData({
        staffName:this.data.keyword,
        pageNum:1,
        accountList: [],
        isFlag: false,
        nothing: false,
      }, () => {
        this.getData()
      });

    },
    getData() {
      let {
        staffList,
        staffName,
        pageNum,
        pageSize
      } = this.data
      let params = {
		staffName,
		workingStatus: 2,
        pageNum,
        pageSize
	  }
	  if (pageNum == 1) wx.$util.showLoading()
	  if (this.data.requestLoading) return
	  this.setData({
		requestLoading: true
	  })
      api.getEmployeeOnTheJobList(params).then(res => {
		wx.$util.hideLoading()
		this.setData({requestLoading: false})
        if (res.code == 0) {
          let {
            list,
			total,
			pages
		  } = res.data;
		  res.data?.list?.forEach(val => {
			  val.staffId = val.id
		  })
          let tempList = pageNum == 1 ? list : [...staffList, ...res.data.list];
          this.setData({
            staffList: tempList,
            isFlag: true,
            total: total,
            nothing: pageNum == pages
          })

        }
      })
    },
    // 触底刷新
    mineReachBottom() {
      let {
        pageNum,
        total,
        pageSize
	  } = this.data
	  if (this.data.requestLoading) return
      if (pageNum * pageSize >= total) {
        return
      }
      this.setData({
        pageNum: pageNum + 1
      }, () => {
        this.getData()
      })
    },
    choose(e) {
      let {item} = e.currentTarget.dataset,
      {
        staffList
      } = this.data
      this.setData({
		selectItem: item,
		staffList
      })
    },
    confirm() {
      if (this.data.staffList.length == 0) return
      let {
		selectItem
      } = this.data;
      if(!Object.keys(selectItem).length) {
        wx.$util.showToast('请选择员工');
        return 
      }
      let {
        staffPhone,
		staffName,
		staffId
      } = selectItem;
      this.setData({
        show: false
      }, () => {
		this.triggerEvent("confirm",{ staffPhone, staffName, staffId})
      })

    },
    hidePopup() {
      let pageInstance = wx.$router.getPageInstance()
      let thisPage = pageInstance.selectComponent(`#componet-0`)
      thisPage.setData({
        staffSelectBox: false,
      })
    },
  }
})