// package-basic-data/pages/test/add/add.js
const mixins = require('@/mixins/index.js')
const app = getApp()
const Constants = require('@/utils/Constants');
Page({
    mixins: [mixins],
    /**
     * 页面的初始数据
     */
    data: {
        draftFlag: false,
        purIdArray: '', //来源单id   
        popupTopObj: [{
            leftTitle:  mixins.$t('storageNum'),//库存量',
            leftCode: 'usableQty',
            rightTitle:  mixins.$t('sellableQuantity'),//'可售量',
            rightCode: 'invQty'
        }],
        popContent: [{
                code: 'itemQty',
                type: 'step',
                title: mixins.$t('countedQuantity'),//'盘点数量', 
                required: true
            },
            {
                code: 'balanceQty',
                title: mixins.$t('profitAndLossQuantity'),//'盈亏数量', 
                type: 'str',
                readonly: true,
            },
            {
                code: 'lossReason',
                name: 'lossReasonName',
                title: mixins.$t('inventoryLossReasons'),//'盘亏原因',
                type: 'choose',
                urlKey: 'openingReason'
            },
            {
                code: 'whId',
                name: 'whName',
                title: mixins.$t('warehouseId'),// '仓库',
                type: 'choose',
            },
            {
                code: 'nonStdCode',
                title: mixins.$t("goodsBatch"), //'商品批次',
                type: 'str',
                readonly: true,
            },
        ],

        cardList: [{
                name: 'main',
                title:  mixins.$t("inventoryInformation"), //'盘点信息 
            },
            {
                name: 'items',
                title: mixins.$t("goodsDetail"), //'商品明细',
                info: '(' + mixins.$t("warehousingProcessing") + ')',
                color: '#E4002B',
                displayNum: 2
            }, {
                name: 'other',
                title: mixins.$t("otherInfo"), // '其他信息'
            }
        ],
        contentObj: {
            main: [{
                    code: 'staffId',
                    name: 'staffName',
                    title:mixins.$t("inventoryEmployees"), //'盘点员工', 
                    type: 'choose',
                    required: true,
                    urlKey: 'chooseStaff'
                }, {
                    code: 'orgId',
                    name: 'orgName',
                    title: mixins.$t("inventoryOrg"), //'盘点部门',  
                    type: 'choose',
                    required: true,
                    urlKey: 'chooseOrg'
                },
                {
                    code: 'whId',
                    name: 'whName',
                    type: 'choose',
                    title:  mixins.$t("inventoryWh"), //'盘点仓库' 
                    urlKey: 'chooseWh'
                }
            ],

            items: [],
            other: [{
                code: 'remarks',
                type: 'textarea',
                title: mixins.$t("remarks"), //'备注',
                readonly: true
            }, {
                code: 'file',
                type: 'uploader',
                title: mixins.$t("uploader"), //'附件'
                readonly: true
            }]
        },
        // 路由
        routeObjName: 'check',
        // 主键Id
        primaryKey: 'checkId',
        readonly: true,
        // inboundProcessingService: app.globalData['inboundProcessingService'],
    },
    /**
     * @desc : 给表单赋值
     * @date : 2024/2/1 15:49
     * @author : 王英杰
     */
    setValuesByEdit(data) { 
        let formData = JSON.parse(this.data.formData)
        formData = data.data
        formData.goodsList = data.dataItem
        formData.goodsList.forEach(element => {
            element.itemQty = element.checkQty
        });
        this.setData({
            formData: JSON.stringify(formData)
        })
        // 刷新商品明细 显示 查看更多
        let card = this.data.cardList.filter(it => it.name == 'items');
        this.selectComponent('#' + this.data.formName).handleContentObj(card[0])
    },
    /**
     * @desc : 详细页面 （编辑）
     * @date : 2024/2/1 15:49
     * @author : 王英杰
     */
    toEdit(e) {
        let formData = JSON.parse(this.data.formData)
        let checkId = formData.checkId
        let that = this
        wx.navigateTo({
            url: this.data.route.add.url,
            events: {
                // 回调后，在这里给页面赋值
                bandData: function (e) {

                }
            },
            success: function (res) {
                res.eventChannel.emit('params', {
                    id: checkId,
                    formMode: Constants.formMode.edit
                })
            }
        })
    },


    /**
     * @desc : 外露设置产品方法 
     * @date : 2024/2/1 15:49
     * @author : 王英杰
     */
    setGoods(e) {

        let formData = JSON.parse(this.data.formData)
        formData.goodsList.forEach(element => {
            element.balanceQty = element.itemQty - element.invQty
        });
        this.setData({
            formData: JSON.stringify(formData)
        })
    },





})