123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- const app = getApp()
- const util = require("../../utils/jmsUtil.js");
- const api = require('../../api/jms.js');
- import moment from 'moment'
- Page({
- data: {
- bookno:'',
- showPicker:false,
- currentItem:'',
- supplyList:[{itemName:'',number:1,price:0,difTotalPrice:0}],
- columns:[],
- typeList:[],
- totalAmount:0,
- diffId:0,
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- if(options.bookno){
- this.setData({
- bookno:options.bookno
- });
- this.getSupplyTypeList();
- }
- if(options.id){
- this.setData({
- diffId:options.id
- });
- this.getDiffOrderDetail();
- }
-
-
- },
- getDiffOrderDetail(){
- wx.showLoading({
- title: '加载中...',
- });
- util.request(api.getDiffDetail, {
- diffOrderId:this.data.diffId
-
- }, 'GET').then(res => {
- wx.hideLoading();
- if (res.errno === 0) {
- this.setData({
- orderInfo:res.data,
- supplyList:res.data.itemList,
- totalAmount:res.data.difTotalPrice,
- bookno:res.data.bookDetailId
- });
- this.getSupplyTypeList();
- }
- }).catch(err => {
- wx.hideLoading();
- });
- },
- getSupplyTypeList(){
- wx.showLoading({
- title: '加载中...',
- });
- util.request(api.getDiffTypeList, {
- bookDetailId:this.data.bookno
- }, 'GET').then(res => {
- wx.hideLoading();
- if (res.errno === 0) {
- let list=res.data;
- list=list.map(item=>{return item.itemName});
- this.setData({
- typeList:res.data,
- columns:list
- });
- }
- }).catch(err => {
- wx.hideLoading();
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- minusNum(e){
- let index=e.currentTarget.dataset.index;
- let num=e.currentTarget.dataset.num;
- let price=e.currentTarget.dataset.price;
- if(num<=1){
- wx.showToast({
- title: '数量不能再少了',
- icon: 'none',
- duration: 3000
- });
- return false;
- }else{
- let item1='supplyList['+index+']'+'.number';
- let item2='supplyList['+index+']'+'.difTotalPrice';
- this.setData({
- [item1]:num-1,
- [item2]:Number((num-1)*price).toFixed(2)
- });
-
- }
- let total=0;
- this.data.supplyList.forEach(item=>{
- total+=Number(item.difTotalPrice);
- });
- total=Number(total).toFixed(2);
- this.setData({
- totalAmount:total
- });
- },
- addNum(e){
- let index=e.currentTarget.dataset.index;
- let num=e.currentTarget.dataset.num;
- let price=e.currentTarget.dataset.price;
- let item1='supplyList['+index+']'+'.number';
- let item2='supplyList['+index+']'+'.difTotalPrice';
- this.setData({
- [item1]:num+1,
- [item2]:Number((num+1)*price).toFixed(2)
- });
-
- let total=0;
- this.data.supplyList.forEach(item=>{
- total+=Number(item.difTotalPrice);
-
- });
- total=total.toFixed(2);
- this.setData({
- totalAmount:total
- });
-
- },
- delItem(e){
- let index=e.currentTarget.dataset.index;
- let supplyList=this.data.supplyList;
- supplyList.splice(index, 1);
- this.setData({
- supplyList: supplyList
- });
- },
- addItem(){
- this.setData({
- supplyList: this.data.supplyList.concat({itemName:'',number:1,price:0,difTotalPrice:0}),
- })
- },
- pickerCancel(){
- this.setData({
- showPicker:false
- });
- },
- showTypePicker(e){
- let index=e.currentTarget.dataset.index;
- this.setData({
- currentItem:index,
- showPicker:true
- })
- },
- pickerConfirm(e){
- let value=e.detail.value;
- let index=e.detail.index;
- let item='supplyList['+this.data.currentItem+']';
- let item1='supplyList['+this.data.currentItem+']'+'.itemName';
- let item2='supplyList['+this.data.currentItem+']'+'.price';
- let item3='supplyList['+this.data.currentItem+']'+'.difTotalPrice';
-
- this.setData({
- // [item]:{itemName:this.data.typeList[index].itemName,
- // },
- [item1]:value,
- [item2]:this.data.typeList[index].price,
- [item3]:Number((this.data.typeList[index].price)*(this.data.supplyList[this.data.currentItem].number)).toFixed(2),
- showPicker:false,
- });
- let total=0;
- this.data.supplyList.forEach(item=>{
- total+=Number(item.difTotalPrice);
- console.log(total);
- });
- total=total.toFixed(2);
- this.setData({
- totalAmount:total
- });
- },
- createOrder(){
- let isValid=this.data.supplyList.every(item=>{return item.itemName!=''});
- if(isValid){
- wx.showLoading({
- title: '加载中...',
- });
- util.request(api.createDiffOrder, {
- bookDetailId:this.data.bookno,
- diffId:this.data.diffId,
- diffList:this.data.supplyList
-
- }, 'POST').then(res => {
- wx.hideLoading();
- if (res.errno === 0) {
- app.globalData.diffId=res.data.diffOrder.id;
- app.globalData.diffOrder=res.data.diffOrder;
- app.globalData.diffItem=res.data.diffItem;
- wx.navigateTo({
- url: '/pages/supplyOrder/supplyOrder',
- });
- }else{
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- });
- }
- }).catch(err => {
- wx.hideLoading();
- });
- }else{
- wx.showToast({
- title: '补差项内容不能为空',
- icon:'none'
- })
- }
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- diffId:app.globalData.diffId
- });
- },
-
- onHide: function () {
- },
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- })
|