import history from '../../utils/history';
import { getDailyBill } from './service';
Component({
  data: {
    dailyBillList: [],
    tabs: [],
    activeIndex: 0,
    showInventoryDay: 'false',
    admissionShowOther: 'false',
    // 无住院人：押金缴纳与日清单查询的提示
    attention: ''
  },
  props: {
    componentData: {}
  },

  didMount() {
    this.getDailyBillData();
    const {
      inpatientIndexTab,
      showInventoryDay,
      admissionShowOther,
      attention
    } = this.props.componentData.componentExtInfo;
    this.setData({
      tabs: inpatientIndexTab ? JSON.parse(inpatientIndexTab) : [],
      showInventoryDay,
      admissionShowOther,
      attention
    });
  },

  methods: {
    handleTabClick({
      index,
      tabsName
    }) {
      this.setData({
        [tabsName]: index,
        activeIndex: index
      });
    },

    // 获取首页日清列表
    async getDailyBillData() {
      const dailyBillList = await getDailyBill();
      this.setData({
        dailyBillList
      });
    },

    // 功能选项点击
    onClickFunction(e) {
      const {
        itemName,
        pagePath
      } = e.target.dataset.item;
      history.push({
        title: itemName,
        pageType: pagePath,
        query: {
          admissionShowOther: this.data.admissionShowOther,
          attention: this.data.attention
        }
      });
    },

    // 跳转日清单查询
    toDailyBill(e) {
      const {
        inpatientId,
        checkInDate
      } = e.target.dataset.item;
      history.push({
        query: {
          inpatientId,
          billDate: checkInDate.slice(0, 11),
          color: '#000',
          backBtnColor: '#000',
          background: '#fff'
        },
        title: '日清单查询',
        pageType: 'inventory-day'
      });
    }

  }
});