apply.js 4.13 KB
// pages/apply/apply.js
const navStyle = 'background-color: transparent;'
import { IMG_URL } from '~/utils/constantData.js'
import  {getMerchantListApi,addCoProductApi} from '~/api/applyProd.js'
import { behavior as computedBehavior } from '~/utils/lib/miniprogram-computed'
import utils from '~/utils/util.js'
Page({
  /**
   * 页面的初始数据
   */
  behaviors: [computedBehavior],
  data: {
    IMG_URL,
    // navStyle,
    prodName:'',
    cooperativeStore:'',
    storeShow: false,
    actions: [
      // {
      //   "merchantId": 0,
      //   "merchantName": "选项1"
      // },
      // {
      //   "merchantId": 1,
      //   "merchantName": "选项2"
      // },
    ],
    selectStoreItem:{},
    scene:''  //场景值
  },
  computed: {
    selectStoreValue(data) {
      return data.selectStoreItem.name || '请输入合作门店'
    }
  },
  // navbar高度设置
  navbarReady(e) {
    let { height, statusBarHeight } = e.detail
    this.setData({
      tabBarStyle: height / 2 + statusBarHeight
      // headerHeight: height / 2 + statusBarHeight +  88*2
    })
  },
  // 选择门店
  selectStore(){
    this.setData({ storeShow: true });
  },
  onStoreClose() {
    this.setData({ storeShow: false });
  },
  onStoreSelect(event) {
    console.log(event.detail);
    let selectStoreItem = event.detail
    this.setData({ selectStoreItem})
    this.onStoreClose()
  },
  
  // 提交信息
  applyFn() {
    let {prodName,selectStoreItem} = this.data
    if (!prodName) {
      wx.pro.showToast({
        title: '请输入产品名称',
        icon: 'error'
      })
      return
    }
    if(utils.isEmptyObj(selectStoreItem)){
      wx.pro.showToast({
        title: '请选择合作门店',
        icon: 'error'
      })
      return
    }
    this.submitForm()
    // console.log(123)
  },
  async submitForm() {
    let {prodName,selectStoreItem} = this.data
    let userInfo = wx.$storage.get('userInfo')
    let params  = {
      ...selectStoreItem,
      serviceMerchantId:userInfo.merchantId,
      serviceMerchantName:userInfo.merchantName,
      coProduct:prodName
    }
    let {code} = await addCoProductApi(params)
    // console.log('res: ', res);
    if(code == 0){
      wx.$api.showToast('申请成功')
      setTimeout(() => {
        wx.$router.back(page => {
          let node = page.selectComponent('#indexclue')
          node && node.getClueInit()
        })
      }, 1000)
    }
    // // return wx.$api.showToast('申请成功')
    // applyApi
    //   .merchantApply(params)
    //   .then(result => {
    //     console.log(result)
    //     if (result) {
    //       wx.$api.showToast('申请成功')
    //       setTimeout(() => {
    //         wx.$router.back(page => {
    //           let node = page.selectComponent('#indexclue')
    //           node && node.getClueInit()
    //         })
    //       }, 1000)
    //     }
    //   })
    //   .catch(err => {})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 
  },
  onRoute(params) {
    // console.log('params: ', params.scene)
    this.setData({
      scene:params.scene
    })
    this.getMerchantListFn()
  },
  //获取门店
  async getMerchantListFn(){
    let {scene} = this.data
    let userInfo = wx.$storage.get('userInfo')
    let params = {
      // scene,
      serviceMerchantId:userInfo.merchantId
    }
    let {code,data} = await getMerchantListApi(params)
    if(code== 0 && data.length != 0){
      data = data.map(item=>{
        item.name = item.merchantName
        return item
      } )
      // console.log('data: ', data);
      this.setData({ 
        actions:data
      })
    }
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}
})