const Constants = require('@/utils/Constants.js');
const util = require('@/utils/util.js')
const mixins = require('@/mixins/index.js')
const app = getApp()
Page({
  mixins: [mixins],
  /**
   * 页面的初始数据
   */
  data: {
    // 查询条件
    searchContent: [{ code: 'createtime', title: mixins.$t("pastThirthtyDays"), defaultValue: 5, searchType: Constants.searchType.date }, { code: 'choose', title: mixins.$t("choose"), searchType: Constants.searchType.pick }],
    // 查询条件-筛选
    pullMenuList: [{ code: 'purchaseStatus', pullType: 'mSelect', typeName: 'purchaseStatus' },
    { code: 'contactName', dataType: '' },
    { code: 'deliveryPhone', dataType: '' },
    { code: 'addressFull', dataType: '' },
    { code: 'makingTime', dataType: 'date' }, { code: 'deliveryTime', dataType: 'date' }],
    // 列表区（脚部金额）
    footerAmount: { name: 'returnAmt', title: mixins.$t("totalAmount") },
    // 列表区（脚部信息）
    footerInfo: [{ name: 'returnQty', title: mixins.$t("piece"), prefix: mixins.$t("together"), }],
    // 列表区（内容）
    contentList: [
      { name: 'intoNo', title: mixins.$t("saleOrderNo") },
      {
        name: [{ name: 'contactName', title: '' },
        { name: 'contactPhone', title: '' }], title: mixins.$t("returnInfo")
      },
      { name: 'returnAddress', title: mixins.$t("returnAddress") },
      {
        name: [{ name: 'orgName', title: '' },
        { name: 'staffName', title: mixins.$t("staffId") }], title: mixins.$t("storeInformation")
      }],
    
    // 弹出按钮
    buttonList: [{ name: 'cancel', title: mixins.$t("invaidOrder") }],
    // 路由
    // routeObjName: 'inbound',
    routeObjName: 'inboundReturn',
    tableData: [],
    active: 0,
    tabsActive: 0,
    buttonSaveList: [{ code: 'add', title: mixins.$t("add") }],
    contentSaveList:[{code:'need',title:mixins.$t("totalAmount"),type:'str'},{code:'amount',content:2000,type:'number'}]
  },

  /**
 * @desc : 跳转明细
 * @date : 2024/2/1 15:49
 * @author : 于继渤
 */
  toDetail(e) {
    console.log(e)
    let item = e.detail.item
    wx.navigateTo({
      url: this.data.route.detail.url,
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的，实际中，需要从route中读取
        res.eventChannel.emit('params', { id: item.intoId, formMode: Constants.formMode.edit,item:item })
      }
    })
  },

  



  /**
   * @desc : 设置查询参数
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  setSearchParams(params) {
    let tabsActive = this.data.tabsActive
    params.intoType = '入库类型-采退入库'
    if (tabsActive == 0) { //出库状态
      params.intoStatus = ''
    } else if (tabsActive == 1) {
      params.intoStatus = mixins.$t("inBoundingIntoStatus")
    } else if (tabsActive == 2) {
      params.intoStatus = mixins.$t("inBoundedIntoStatus")
    }
    return params
  },

  /**
   * @desc :   tab切换事件
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  onChangeTabs(e) {
    this.setData({
      tabsActive: e.detail.index
    })
    //查询
    this.searchData()
  },


  /**
   * @desc :   加载数据源
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  getData(params) {
    return this.excute(this.data.service, this.data.service.selectByCond, params);
  },

    /**
   * @desc :   三个点
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  open(e){
    console.log(e)
    let item = e.detail.item
    if(e.detail && e.detail.name == 'cancel'){
        //调用作废接口
        this.cancel(item.intoId)
    }else{
      wx.navigateTo({
        url: this.data.route.add.url,
        events: {
          // 保存成功后刷新页面
          refresh: function (data) {
            // 刷新一览界面
            _this.searchData();
          }
        },
        success: function (res) {
          let data = {
            formMode: Constants.formMode.add,
            formType: Constants.formMode.add,
          }
          res.eventChannel.emit('params', data);
        }
      })
    }
  },
   /**
   * @desc :   作废
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  cancel(intoId){
    return this.excute(this.data.service, this.data.service.cancel, {
      intoId:intoId
    }).then(res=>{
      if(res.data.code == 200){
        wx.showToast({
          title: '作废成功',
          image: '/static/image/success.png',
          duration: 1000
        })
        this.searchData()
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },


})