index.js 8.7 KB
// tabWorkOrder/pages/residentManage/components/accountAllocation/index.js
const IMG_URL =
  "https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/";
import api from '../../api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    nothing: false,
    showModal: false,
    showTimeModal: false,
    isFlag: false,
    total: 0,
    pageNum: 1,
    pageSize: 10,
    keyword:'',
    staffNameOrPhone: "",
    IMG_URL,
    accountList: [],
    businessType: ['会员权益/升级', '轻改'],
    disableObj: {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(e) {
      let {
        index,
        accountIndex
      } = e.currentTarget.dataset, {
        accountList
      } = this.data;
      let {
        deletedState,
        yqMerchantId,
        yqMerchantName
      } = accountList[index].staffAccountList[accountIndex], {
        staffPhone
      } = accountList[index];

      this.setData({
        showModal: true,
        disableObj: {
          index,
          accountIndex,
          yqMerchantId,
          staffPhone,
          accountStatus: deletedState ? 'I' : 'N'
        },
        success: true,
        dialogText: `是否${!deletedState?'启用':'禁用'}该员工${yqMerchantName}${yqMerchantId}登录账号`
      })

    },
    dialogClose() {
      this.setData({
        showModal: false
      })
    },
    dialogConfirm() {
      const {
        success,
        accountList,
        disableObj: {
          index,
          accountIndex,
          yqMerchantId,
          staffPhone,
          accountStatus
        }
      } = this.data;

      if (success) {
        api.updateAccountStatus({
          yqMerchantId,
          staffPhone,
          accountStatus
        }).then(res => {
          let {
            code,
            data,
            message
          } = res;

          if (code == 0) {
            accountList[index].staffAccountList[accountIndex].deletedState = !accountList[index].staffAccountList[accountIndex].deletedState
            this.setData({
              accountList,
              showModal: false
            }, () => {
              wx.$util.showToast('操作成功');
            })
          } else {
            wx.$util.showToast(message);
          }

        })
      }
    },
    updateConfig(e) {
      let {
        index,
        accountIndex,
        storeIndex
      } = e.currentTarget.dataset, {
        accountList
      } = this.data;
      let {
        yqMerchantId
      } = accountList[index].staffAccountList[accountIndex], {
        staffPhone
      } = accountList[index], {
        merchantId,
        deferredOpenState,
        id
      } = accountList[index].staffAccountList[accountIndex].staffConfigList[storeIndex]
      this.setData({
        disableObj: {
          index,
          accountIndex,
          yqMerchantId,
          merchantId,
          staffPhone,
          storeIndex,
          deferredOpenFlag: !deferredOpenState ? 'Y' : 'N',
          id
        },
        // success: true,
        // dialogText: `是否${!deletedState?'启用':'禁用'}该员工${yqMerchantName}${yqMerchantId}登录账号`
      })
      if (!deferredOpenState) {
        this.setData({
          showTimeModal: true,
        })
      } else {
        let e = {
          detail: {
            startEffectiveTime: ''
          }
        }
        this.timeConfirm(e)
      }
    },
    dialogTimeClose() {
      this.setData({
        showTimeModal: false
      })
    },
    timeConfirm(e) {
      const {
        startEffectiveTime
      } = e.detail;
      const {
        accountList,
        disableObj: {
          id,
          index,
          accountIndex,
          yqMerchantId,
          merchantId,
          staffPhone,
          storeIndex,
          deferredOpenFlag
        }
      } = this.data;
      let params = {
        staffPhone,
        yqMerchantId,
        merchantId,
        deferredOpenFlag,
        startEffectiveTime,
        dailyReportConfigId: id
      }
      let item = accountList[index].staffAccountList[accountIndex],
        isFlag = item.staffConfigList[storeIndex].deferredOpenState,
        checkList = item.checkList

      api.updateDailyReportConfig(params).then(res => {
        let {
          code,
          data,
          message
        } = res;

        if (code == 0) {
          this.setData({
            accountList: [],
            pageNum: 1,
            showTimeModal: false,
            staffNameOrPhone: ''
          }, () => {
            this.getData()
          })
          wx.$util.showToast('操作成功');
          // if (checkList.length == 0) {
          //   if (!isFlag) {
          //     checkList.push(item.staffConfigList[storeIndex])
          //   }
          // } else {
          //   if (!isFlag) {
          //     checkList.push(item.staffConfigList[storeIndex])
          //   } else {
          //     checkList.filter(item => {
          //       if (item.merchantId != merchantId) {
          //         return item
          //       }
          //     })

          //   }

          // }

          // accountList[index].staffAccountList[accountIndex].staffConfigList[storeIndex].deferredOpenState = !isFlag
          // accountList[index].staffAccountList[accountIndex].checkList = checkList
          // accountList[index].staffAccountList[accountIndex].unfold=true
          // this.setData({
          //   accountList
          // }, () => {
          //   wx.$util.showToast('操作成功');
          // })
        } else {
          wx.$util.showToast(message);
        }

      })

    },
    clear() {
      this.setData({
        keyword:'',
        staffNameOrPhone: ""
      });
      this.search();
    },
    input(e) {
      let {
        value
      } = e.detail;
      this.setData({
        keyword: value
      });
    },
    search() {
      this.setData({
        staffNameOrPhone:this.data.keyword,
        pageNum: 1,
        accountList: [],
        isFlag: false,
        nothing: false,
      }, () => {
        this.getData()
      });

    },
    getData() {
      let {
        accountList,
        staffNameOrPhone,
        pageNum,
        pageSize
      } = this.data
      let params = {
        staffNameOrPhone,
        pageNum,
        pageSize
      }
      api.getDailyReportConfigList(params).then(res => {
        if (res.code == 0) {
          let {
            list,
            total
          } = res.data;
          res.data.list.forEach(item => {
            item.labelArr = item.staffSceneLabel.split(',')
            item.staffAccountList.forEach(account => {
              account.checkList = []
              account.deletedState = account.deletedFlag == 'N' ? true : false
              account.staffConfigList.forEach(config => {
                if (config.deferredOpenFlag === 'Y') {
                  account.checkList.push(config)
                }
                config.startEffectiveTime = config.startEffectiveTime ? new Date(config.startEffectiveTime).format(`yyyy-MM-dd`) : ''
                config.deferredOpenState = config.deferredOpenFlag == 'Y' ? true : false
              })
              account.unfold = true
            })
          })
          let tempList = pageNum == 1 ? list : [...accountList, ...list]
          this.setData({
            accountList: tempList,
            isFlag: true,
            total: total,
            nothing: pageNum == 1 ? false : total == tempList.length,
          })

        }
      })
    },
    goToStaff(e) {
      let {
        index
      } = e.currentTarget.dataset, {
        accountList
      } = this.data;
      let {
        staffPhone,
        staffName
      } = accountList[index]
      let pageInstance = wx.$router.getPageInstance()

      pageInstance.setData({
        activeIndex: 0
      }, () => {
        let thisPage = pageInstance.selectComponent(`#componet-0`)
        thisPage.setData({
          'staffObj.staffName': staffName,
          'staffObj.staffPhone': staffPhone
        })
      })

    },
    // 触底刷新
    mineReachBottom() {
      console.log('触底')
      let {
        pageNum,
        total,
        pageSize
      } = this.data
      if (pageNum * pageSize >= total) {
        return
      }
      this.setData({
        pageNum: pageNum + 1
      }, () => {
        this.getData()
      })
    },
    packupList(e) {
      let {
        index,
        accountIndex
      } = e.currentTarget.dataset, {
        accountList
      } = this.data;
      let isFlag = accountList[index].staffAccountList[accountIndex].unfold
      accountList[index].staffAccountList[accountIndex].unfold = !isFlag
      this.setData({
        accountList
      })
    },
  },
  lifetimes: {
    attached: function () {
      this.getData()
    }


  },
})