/*******************************************************************************
 * Copyright(c) 2022 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 *		2.销售出库列表
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		于继渤		 2024-3-25	    1.00		   	    
 *******************************************************************************/
const mixins = require('@/mixins/index.js')
const Constants = require('@/utils/Constants.js');
const app = getApp()
Page({
  mixins: [mixins],
  /**
   * 页面的初始数据 
   */
  data: {
    tagList: [{ title: "全部", code: '' }, { title: "待出库", code: '出库状态-待出库' }, { title: "已出库", code: '出库状态-已出库' }],
    // 列表区（脚部金额）
    footerAmount: { name: 'outAmt', title: mixins.$t("totalAmount") },
    // 列表区（脚部信息）
    footerInfo: [{ name: 'outQty', title: mixins.$t("piece"), prefix: mixins.$t("together"), }],
    // 列表区（内容）
    contentList: [
      { name: 'outNo', title: mixins.$t("outOrderNo") },
      { name: 'cusPhone', title: mixins.$t("cusPhone") },
      { name: 'addressFull', title: mixins.$t("adddressFull") },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t("staffId") }], title: mixins.$t("storeInformation") }
    ],
    // 查询条件
    searchContent: [
      { code: 'createtime', title: mixins.$t("pastThirthtyDays"), defaultValue: 5, searchType: Constants.searchType.date },
      { code: 'staff', title: mixins.$t("staffId"), dropType: 'staff' },
      { code: 'org', title: mixins.$t("orgId"), dropType: 'org' },
      { code: 'choose', title: mixins.$t("choose"), searchType: Constants.searchType.pick }
    ],
    contentObj: {
      '待出库': [
        { name: 'outNo', title: mixins.$t("outOrderNo") },
        { name: 'cusPhone', title: mixins.$t("cusPhone") },
        { name: 'addressFull', title: mixins.$t("adddressFull") },
        { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t("staffId") }], title: mixins.$t("storeInformation") }
      ],
      '出库中': [
        { name: 'outNo', title: mixins.$t("outOrderNo") },
        { name: 'cusPhone', title: mixins.$t("cusPhone") },
        { name: 'addressFull', title: mixins.$t("adddressFull") },
        { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t("staffId") }], title: mixins.$t("storeInformation") }
      ],
      '已出库': [
        { name: 'outNo', title: mixins.$t("outOrderNo") },
        { name: 'cusPhone', title: mixins.$t("cusPhone") },
        { name: 'addressFull', title: mixins.$t("adddressFull") },
        { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t("staffId") }], title: mixins.$t("storeInformation") }
      ],
    },
    buttonSaveList: [{ code: 'add', title: mixins.$t("add") }],
    contentSaveList: [{ code: 'need', title: mixins.$t("totalAmount"), type: 'str' }, { code: 'amount', content: 2000, type: 'number' }],

    // 弹出按钮
    buttonList: [
      { name: 'salesOutbound', title: mixins.$t("outProcessing") },
      { name: 'merge', title: mixins.$t("printedBill") },
      { name: 'invalid', title: mixins.$t("invaidOrder") } //作废
    ],
    // 路由
    routeObjName: 'saleOutBound',
    active: 0
  },

 /**
  * @desc :   作废
  * @date : 2024年3月8日
  * @author : 于继渤
  */
 invalid(e) {
  return this.excute(this.data.service, this.data.service.repeal + '/' + e.outId, {}).then(res => {
    if (res.data.code == 200) {
      wx.showToast({
        title: mixins.$t('invalidSuccessfully'),
        image: '/static/image/success.png',
        duration: 1000
      })
    }
  })
},

  /**
 * @desc : 切换
 * @date : 2024/2/1 15:49
 * @author : 于继渤
 */
  onChangeTabs(e) {
    let code = e.detail.detail.code
    console.log(e)
    this.setData({
      outStatus: code,
    })
    this.searchData()
  },

  /**
* @desc : 设置查询参数
* @date : 2024/2/1 15:49
* @author : 于继渤
*/
  setSearchParams(params) {
    //销售状态
    params.outStatus = this.data.outStatus == 'all' ? '' : this.data.outStatus
    return params
  },
  /**
   * @desc : 查询
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  getData(params) {
    console.log(app.globalData.user)
    return this.excute(this.data.service, this.data.service.selectByCond, params);
  },
  /**
   * @desc : 处理查询数据
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  handleSearchData(tableData) {
    if (tableData && tableData.length > 0) {
      tableData.forEach(res => {
        res.collectStatus = 'noCollect'
      })
    }
    this.setData({
      tableData: tableData
    })
  },
  toDetail(e) {
    let outId = e.detail.item.outId
    wx.navigateTo({
      url: this.data.route.edit.url,
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的，实际中，需要从route中读取
        res.eventChannel.emit('params', { id: outId, formMode: Constants.formMode.detail })
      }
    })
  }

})