import ProjectService from '../../../net/api/projectApi' Page({ /** * 页面的初始数据 */ data: { urgent: 0, projTypes: [], //全托管,写材料 type= ALL type =MATERIAL allPrice: 0, materialPrice: 0, isUrgent: false, //是否加急 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.setNavigationBarTitle({ title: '创建软著', }) this.doGetPrice() }, //是否加急 doUrgent(e) { const _self = this _self.setData({ isUrgent: !_self.data.isUrgent }) }, //获取单价 doGetPrice() { wx.showLoading({ title: '加载中...', }) const _self = this ProjectService.doGetPrice() .then(res => { wx.hideLoading() console.log(res) res.projTypes.forEach(el => { if (el.type == 'ALL') { _self.setData({ allPrice: el.price }) } else if (el.type == 'MATERIAL') { _self.setData({ materialPrice: el.price }) } }); _self.setData({ urgent: res.additional.urgent, //加急办理 }) }, err => { wx.hideLoading() wx.showToast({ title: '数据有误,请稍后重试', icon: 'error', success: () => { wx.navigateBack() } }) }) }, //打开项目信息编辑页面 doBuy(e) { //计算价格 const _self = this var price = e.currentTarget.dataset.type == 'ALL' ? _self.data.allPrice : _self.data.materialPrice var type = e.currentTarget.dataset.type if (type == 'ALL' && _self.data.isUrgent) { price += _self.data.urgent } const urgent = _self.data.isUrgent ? 'URGENT' : '' wx.navigateTo({ url: '../createProjectInfo/createProjectInfo?type=' + type + '&price=' + price + '&isUrgent=' + urgent }) } })