Newer
Older
miniCreditFactory / pages / detail / detail.js
bello on 29 May 2020 5 KB init

var U = require('../../utils/Urls.js')
var Api = require('../../utils/api.js')

Page({

    /**
     * 页面的初始数据
     */
    data: {
        order: {},
        pic_sfzm: [],
        pic_rhzx: [],
        pic_yhls: [],
        pic_dywzp: [],
        pic_dywzl: [],
        pic_qt: [],
        pic_jyqk: [],
        enableRefresh: true,    // 强制页面刷新数据的开关
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log(options.model)
        // 上一页传递的订单信息
        this.setData({
            order: JSON.parse(decodeURIComponent(options.model))
        })
       
    },

    onShow: function(){
        if(this.data.enableRefresh){
            this.getList()
            this.data.enableRefresh = false
        }
    },

    /**
         * 获取任务列表数据
         */
    getList: function () {
        wx.showLoading({
            title: 'loading...',
        })
        var that = this;

        var info = {
            pid: this.data.order.bussPk
        };

        // 请求图片列表数据
        Api.Request(info, U.URLS['picList'], function (r) {
            wx.hideLoading()
            console.log(r)
            if (r != null && r.length>0) {
                if (typeof r != 'string'){
                    // 先清掉list再添加
                    that.setData({
                        pic_sfzm: [],
                        pic_rhzx: [],
                        pic_yhls: [],
                        pic_dywzp: [],
                        pic_dywzl: [],
                        pic_qt: [],
                        pic_jyqk: []
                    })

                    that.refreshPicList(r);

                } else {
                    that.getList()
                }
            }
        });

    },


    /**
     * 插入图片到list
     */
    refreshPicList: function(list){
        for(var i=0; i< list.length; i++){
            console.log(list[i]['typeId'])
            if (list[i]['isUsable'] == 1){
                if (list[i]['typeId'] == '0101' && list[i]['typeSubId'] ){
                    this.setData({
                        pic_sfzm: this.data.pic_sfzm.concat(list[i])
                    });
                } else if (list[i]['typeId'] == '0102' && list[i]['typeSubId']) {
                    this.setData({
                        pic_rhzx: this.data.pic_rhzx.concat(list[i])
                    });
                } else if (list[i]['typeId'] == '0103' && list[i]['typeSubId']) {
                    this.setData({
                        pic_yhls: this.data.pic_yhls.concat(list[i])
                    });
                } else if (list[i]['typeId'] == '0105' && list[i]['typeSubId']) {
                    this.setData({
                        pic_dywzp: this.data.pic_dywzp.concat(list[i])
                    });
                } else if (list[i]['typeId'] == '0104' && list[i]['typeSubId']) {
                    this.setData({
                        pic_dywzl: this.data.pic_dywzl.concat(list[i])
                    });
                } else if (list[i]['typeId'] == '0106' && list[i]['typeSubId']) {
                    this.setData({
                        pic_qt: this.data.pic_qt.concat(list[i])
                    });
                } else if (list[i]['typeId'] == '0107' && list[i]['typeSubId']) {
                    this.setData({
                        pic_jyqk: this.data.pic_jyqk.concat(list[i])
                    });
                }
            }
        }

        console.log(this.data)
    },

    /**
     * 打开图片匹配页面
     */
    openPicList: function(e) {
        var data = e.currentTarget.dataset.img
        var type = e.currentTarget.dataset.type
        var model = encodeURIComponent(JSON.stringify(data))
        var order = encodeURIComponent(JSON.stringify(this.data.order))
        console.log('type => ' + type)
        var pageName = ''
        if(type == '0101'){
            pageName = 'piclist-sfzm'
        } else if(type == '0102'){
            pageName = 'piclist-rhzx'
        } else if (type == '0103') {
            pageName = 'piclist-yhls'
        } else if (type == '0104') {
            pageName = 'piclist-dywzl'
        } else if (type == '0105') {
            pageName = 'piclist-dywzp'
        } else if (type == '0106') {
            pageName = 'piclist-qt'
        } else if (type == '0107') {
            pageName = 'piclist-jyqk'
        }


        //跳转
        wx.navigateTo({
            url: '/pages/piclist/' + pageName+'?type=' + type + '&model=' + model + '&order=' + order,
        })
    },

    /**
     * 更新任务到信贷系统
     */
    updateMission: function(){
        
        var that = this;

        wx.showModal({
            title: '提示',
            content: '是否更新图片信息到信贷系统',
            confirmText: '更新',
            success(res) {
                if (res.confirm) {
                //     console.log('用户点击确定')
                // 重复操作
                    wx.showLoading({
                        title: 'loading...',
                    })

                    var info = {
                        loanAskInfoPk: that.data.order.bussPk
                    };
                    // 请求图片列表数据
                    Api.Request(info, U.URLS['updateMission'], function (r) {
                        wx.hideLoading()
                        
                        wx.showModal({
                            title: '提示',
                            content: r,
                            showCancel: false,
                            success(res){
                                
                            }
                        })

                    })
                } else if (res.cancel) {
                // console.log('用户点击取消')
                }
            }
        })
       

    }

})