<template>
    <lj-win-common :title="title">
        <template slot="header_right">
            <mu-menu placement="bottom-end" :open.sync="openTitle">
                <mu-button icon>
                    <i class="iconfont icon-more"></i>
                </mu-button>
                <mu-list slot="content">
                    <!-- <mu-list-item button @click="openTitle = false">
                        <mu-list-item-title>转换为中文</mu-list-item-title>
                    </mu-list-item>
                    <mu-list-item button onclick="$lj.toast('功能正在开发中!')">
                        <mu-list-item-title>转换为英文</mu-list-item-title>
                    </mu-list-item> -->
                    <mu-list-item button @click="GetMtrlInfo">
                        <mu-list-item-title>刷新选配项</mu-list-item-title>
                    </mu-list-item>
                </mu-list>
            </mu-menu>
        </template>
        <div slot="body">
            <van-skeleton :row="15" :row-width="rowWidth" :loading="skeletonLoading" class="fff_bg">
                <div class="product-container">
                    <div class="product-swipe-photo">
                        <lj-img :md5="mainObject.picmd5" class="product-swipe-photo-item" />
                    </div>
                    <div class="product-item">
                        <div class="product-introduct">
                            <div class="product-price-monthsale">
                                <div class="product-price">
                                    <span class="price-unit">¥</span>
                                    {{enprice|moneyFilter}}
                                </div>
                                <div class="prodcut-monthsale">月销{{mainObject.noallocqty}}{{mainObject.unit}}</div>
                            </div>
                            <div class="product-name">{{mainObject.mtrlname}}</div>
                            <div class="lj-card-summary-light-text lj-card-quaternary-content">
                                <span v-if="mainObject.mtrlmode !=''" style="padding:0px 5px 0px 0px">规格{{mainObject.mtrlmode}}</span>
                                <span style="padding:0px 5px 0px 0px">净重{{mainObject.net_weight}}KG</span>
                                <span style="padding:0px 5px 0px 0px">毛重{{mainObject.gross_weight}}KG</span>
                            </div>
                            <div class="product-informations">
                                <div class="information-item" @click="handleToastInfo('编码',mainObject.mtrlcode)">
                                    <span class="item-icon"><i class="iconfont icon-batch_number" /></span>
                                    <div class="item-text">{{mainObject.mtrlcode}}</div>
                                    <span class="item-title">编码</span>
                                </div>
                                <div class="information-item" @click="handleToastInfo('英文名称',mainObject.mtrlengname)">
                                    <span class="item-icon"><i class="iconfont icon-English" /></span>
                                    <div class="item-text">
                                        {{mainObject.mtrlengname && mainObject.mtrlengname.length > 0 ? mainObject.mtrlengname : '无'}}
                                    </div>
                                    <span class="item-title">英文名称</span>
                                </div>
                                <div class="information-item" @click="handleToastInfo('条形码',mainObject.barcode)">
                                    <span class="item-icon"><i class="iconfont icon-tiaoma" /></span>
                                    <div class="item-text">
                                        {{mainObject.barcode && mainObject.barcode.length > 0 ? mainObject.barcode : '无'}}
                                    </div>
                                    <span class="item-title">条形码</span>
                                </div>
                            </div>
                        </div>
                        <van-divider>参数</van-divider>
                        <div class="product-configuration">
                            <van-cell-group>
                                <!-- <van-cell title="销售单位" :value="unit" @click="showunit = true" is-link /> -->
                                <van-field v-model="mxdscrp" rows="1" autosize label="明细备注" type="textarea" placeholder="请输入明细备注" input-align="right"/>
                                <van-field v-model="requiredate" is-link readonly label="交货时间" placeholder="点击选择时间" @click="showRqDate = true" input-align="right"/>
                            </van-cell-group>
                        </div>
                        <van-divider>配置</van-divider>
                        <div class="product-configuration">
                            <configure-select v-model="status" :flag="mtrlInfo.statusflag" :option="mtrlInfo.statusop" v-if="mtrlInfo.statusflag" @input="inputStatus"  />
                            <configure-select v-model="woodcode" :flag="mtrlInfo.woodcodeflag" :option="mtrlInfo.woodcodeop" v-if="mtrlInfo.woodcodeflag" @input="inputWoodcode"  />
                            <configure-select v-model="pcode" :flag="mtrlInfo.pcodeflag" :option="mtrlInfo.pcodeop" @input="inputPcode"  />
                        </div>
                        <van-divider>优惠</van-divider>
                        <div class="product-configuration price-configuration">
                            <van-cell-group :border="false">
                                <van-field
                                    v-model="enprice"
                                    class="lj-cell-left"
                                    placeholder="请输入产品单价"
                                    input-align="right"
                                    type="number"
                                    @focus="handleInputFocus($event)"
                                    @input="handleInputPrice"
                                >
                                    <template #label>
                                        <div class="flex">
                                            <span>价格</span>
                                            <template v-if="taxrateCheckbox">
                                                <van-checkbox
                                                    v-model="taxPriceCheckbox"
                                                    class="field-checkbox"
                                                    @change="handleInputPrice"
                                                >(含税)</van-checkbox>
                                            </template>
                                        </div>
                                    </template>
                                </van-field>
                                <van-cell
                                    :title="unitList.length > 1 ? '销售数量和单位' : '销售数量'"
                                >
                                    <template #default>
                                        <div class="flex" style="justify-content: flex-end;">
                                            <van-stepper v-model="saleqty" :min="0" @focus="handleInputFocus($event)" />
                                            <div class="unit-wrap" :class="{'sel_abled': unitList.length > 1}" @click="handleShowActionUnit">
                                                {{ unit }}
                                            </div>
                                        </div>
                                    </template>
                                </van-cell>
                                <van-field
                                    v-model="discount"
                                    ref="discountField"
                                    class="lj-cell-left"
                                    :placeholder="discountCheckbox ? '可选，输入0.8表示打8折' : ''"
                                    input-align="right"
                                    type="number"
                                    :disabled="!discountCheckbox"
                                    @focus="handleInputFocus($event)"
                                    @click="handleClickDiscountSwitch"
                                    @input="handleInputPrice"
                                >
                                    <template #label>
                                        <div class="field-label">
                                            <span v-show="!discountCheckbox">
                                                优惠折扣
                                            </span>
                                            <van-checkbox
                                                v-show="discountCheckbox"
                                                v-model="discountCheckbox"
                                                style="display: inline-flex"
                                                @click="handleChangeDiscountCheckbox"
                                            >优惠折扣</van-checkbox>
                                            <template v-for="(item) in discountTags">
                                                <lj-tag-double
                                                    v-if="item"
                                                    :key="item"
                                                    :value="item | ellipsis(5)"
                                                    :type="discount ? 'default' : 'primary'"
                                                    plain
                                                    @tagclick="handleTagsSetValue('discount', item)"
                                                >
                                                </lj-tag-double>
                                            </template>
                                        </div>
                                    </template>
                                    <template #extra>
                                        <van-switch
                                            v-if="!discountCheckbox"
                                            v-model="discountCheckbox"
                                            size="20px"
                                        />
                                    </template>
                                </van-field>
                                <van-field
                                    v-model="taxrate"
                                    ref="taxrateField"
                                    class="lj-cell-left"
                                    :placeholder="taxrateCheckbox ? '可选，输入税点(0至1)' : ''"
                                    input-align="right"
                                    type="number"
                                    :disabled="!taxrateCheckbox"
                                    @focus="handleInputFocus($event)"
                                    @click="handleClickTaxrateSwitch"
                                    @input="handleInputPrice"
                                >
                                    <template #label>
                                        <div class="field-label">
                                            <span v-show="!taxrateCheckbox">
                                                税率
                                            </span>
                                            <van-checkbox
                                                v-show="taxrateCheckbox"
                                                v-model="taxrateCheckbox"
                                                style="display: inline-flex"
                                                @click="handleChangeRaxrateCheckbox"
                                            >税率</van-checkbox>
                                            <template v-for="(item) in taxrateTags">
                                                <lj-tag-double
                                                    v-if="item"
                                                    :key="item"
                                                    :value="item | ellipsis(5)"
                                                    :type="taxrate ? 'default' : 'primary'"
                                                    plain
                                                    @tagclick="handleTagsSetValue('taxrate', item)"
                                                >
                                                </lj-tag-double>
                                            </template>
                                        </div>
                                    </template>
                                    <template #extra>
                                        <van-switch
                                            v-show="!taxrateCheckbox"
                                            v-model="taxrateCheckbox"
                                            size="20px"
                                            @change="handleInputPrice"
                                        />
                                    </template>
                                </van-field>
                            </van-cell-group>
                        </div>
                        <!-- <div class="product-configuration">
                            <van-cell-group :border="false">
                                <van-field label="原价" input-align="right" type="number" value-class="configuration-value" v-model="enprice" readonly @click-input="handleEditPriceInfo('enprice',enprice)"
                                />
                                <van-field label="折扣" input-align="right" type="number" value-class="configuration-value" v-model="discount" readonly @click-input="handleEditPriceInfo('discount',discount)"/>
                                <van-field label="税率" input-align="right" type="number" value-class="configuration-value" v-model="taxrate" readonly @click-input="handleEditPriceInfo('taxrate',taxrate)"/>
                                <van-field label="折后税后单价" readonly input-align="right" type="number" value-class="configuration-value" v-model="rprice" 
                                @click-input="handleEditPriceInfo('rprice',rprice)" />
                                <van-field label="数量" input-align="right" type="number" value-class="configuration-value" v-model="saleqty" readonly @click-input="handleEditPriceInfo('saleqty',saleqty)" />
                                <van-field label="合计" readonly input-align="right" value-class="configuration-value" :value="sumprice | moneyFilter"/>
                            </van-cell-group>
                        </div> -->
                    </div>
                    <van-popup v-model="showunit" round position="bottom">
                        <van-picker
                            title="销售单位选择"
                            show-toolbar
                            :default-index="defaultUnitIndex"
                            :columns="unitList"
                            @confirm="handleUnitPickerConfirm"
                            @cancel="showunit = false"
                        />
                    </van-popup>
                    <van-popup v-model:show="showRqDate" position="bottom">
                        <van-datetime-picker
                            v-model="currentDate"
                            type="date"
                            title="选择年月日"
                            @confirm="handleRqDatePickerConfirm"
                            @cancel="showRqDate = false"
                        />
                    </van-popup>
                    <product-info-edit-popup 
                        ref="pricePupup"
                        :sign="editsign" 
                        :max="editmax" 
                        :min="editmin" 
                        :value="editValue"
                        @confirm="handleEditPriceConfirm"
                    />

                    <van-action-sheet
                        v-model="showActionUnit"
                        description="选择销售单位"
                        :actions="unitList"
                        @select="handleSelectActionUnit"
                        cancel-text="取消"
                        close-on-click-action
                    />
                </div>
            </van-skeleton>
        </div>
        <template slot="footer">
            <mu-row>
                <mu-col v-if="!isModify" class="popup-footer">
                    <!-- <mu-button full-width large color="primary" @click="handleAddGoodsToCart">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-tongyi"></use>
                        </svg>加入销售订单
                    </mu-button> -->
                    <div class="total flex-1 flex-column">
                        <div class="price">
                                单价:
                                <span class="num">
                                    ￥
                                    <span class="p">{{ unitPrice | moneyFilter }}</span>
                                </span>
                        </div>
                        <div class="other">
                            <div v-if="discountPrice">
                                <span class="subtitle" v-if="discountPrice">优惠{{ discountPrice | moneyFilter }}元</span>
                            </div>
                        </div>
                    </div>
                    <van-button class="confirm-btn" round block @click="handleAddGoodsToCart">
                        加入销售订单
                    </van-button>
                </mu-col>
                <mu-col v-if="isModify">
                    <mu-button full-width large color="primary" @click="handleAddGoodsToCart">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-tongyi"></use>
                        </svg>修改
                    </mu-button>
                </mu-col>
            </mu-row>
        </template>
    </lj-win-common>
</template>

<script>
    import LjWinCommon from "components/lj-win-common";
    import LjImg from "components/lj-img";
    import ConfigureSelect from "./configure-select-pro";
    import ProductInfoEditPopup from "./product-info-edit-popup";
    export default {
        components: {
            LjWinCommon,
            LjImg,
            ConfigureSelect,
            ProductInfoEditPopup  
        },
        data() {
            return {
                title: "产品浏览",
                openTitle: false,
                status: "",
                woodcode: "",
                pcode: "",
                unit: "",
                cusid: 0,
                moneyid: 0,
                typeid: 0,
                mtrlInfo: {},
                mtrlObject: {},
                showdiscount: false,
                showtaxrate: false,
                discount: 1,
                taxrate: 0,
                unitList: [],
                showunit: false,
                defaultUnitIndex: 0,
                saleqty: 1,
                imgList:[],
                noallocqty: 0,
                winMode: 0,// 0-新建 1-修改
                enprice: 0,
                skeletonLoading: true, // 骨架屏加载
                rowWidth: [240,140,220,270,320,130,240,140,220,270,320,130,240,140,220,270,320,130,240,140],
                productDraft:"saletask-edit-product-draft",
                currentDate: new Date(),
                showRqDate: false,
                requiredate: null,
                mxdscrp: "",
                editsign: "common",
                editmin: -Infinity,
                editmax: Infinity,
                editValue: 0,
                rprice: 0,

                showActionUnit: false, // 单位列表：底部弹起的模态面板
                taxrateCheckbox: false, // 复选框，是否使用税率
                discountCheckbox: false, // 复选框，是否使用优惠
                taxPriceCheckbox: false, // 复选框，原价输入是否含税
                originalPrice: 0, // 底部，原价
                unitPrice: 0, // 底部，单价
                taxPrice: 0, // 底部，税价
                discountPrice: 0, // 底部，共优惠
                taxrateTags: [], // 快捷标签：税率
                discountTags: [], // 快捷标签：折扣
                tagsSize: 2, // 快捷标签, 储存长度
                habitKey: "productInfoEditHabit",
            }
        },
        created() {
            let user = $lj.getStorage("userInfo");

            var pageParm = $lj.getPageParam();
            if (pageParm) {
                this.winMode = pageParm.winMode;
                this.mainObject = pageParm.mainObject;
                this.cusid = pageParm.cusid;
                this.moneyid = pageParm.moneyid;
                this.typeid = pageParm.typeid;

                console.log("mainObject>>>>>>>>>",JSON.stringify(this.mainObject))
            }
        },
        mounted(){
            // 获取产品信息
            this.GetMtrlInfo();
            

            // 赋值默认配置
            if(this.isModify) {
                this.saleqty = this.mainObject.saleqty;
                this.discount = this.mainObject.rebate;
                this.enprice = parseFloat(this.mainObject.enprice);
                this.status = this.mainObject.status;
                this.woodcode = this.mainObject.woodcode;
                this.pcode = this.mainObject.pcode;
                this.unit = this.mainObject.unit;
                this.taxrate = this.mainObject.taxrate;
                this.requiredate = this.mainObject.requiredate;
                this.mxdscrp = this.mainObject.mxdscrp;
                this.rprice = this.handleCalcRPrice(0)
            }else{
                // 生成折扣列表
                this.initDiscount(this.mainObject);
            }

            // 初始化库存
            // this.inputConfigure();
        },
        methods: {
            /**修改时：设置价格办税环境 */
            fnSetTaxPrice() {
                if (this.taxrate) {
                    this.taxrateCheckbox = true;
                }
                this.taxPriceCheckbox = true
            },
            fnGetCache() {
                let habit = $lj.getStorage(this.habitKey) || {};
                if (habit.hasOwnProperty('taxrate')) {
                    this.taxrateTags = habit.taxrate || []
                }
                if (habit.hasOwnProperty('discount')) {
                    this.discountTags = habit.discount || []
                }
            },
            fnSetCache() {
                let habit = $lj.getStorage(this.habitKey) || {};
                if (this.discount) {
                    let index = this.discountTags.findIndex((item) => item == this.discount);
                    // 想要插入的数据已经存在了，那么直接提升它就可以
                    if (index > -1) {
                        this.discountTags.splice(index, 1);
                    }
                    this.discountTags.unshift(this.discount);
                    this.discountTags.length = this.tagsSize;
                    habit.discount = this.discountTags;
                }
                if (this.taxrate) {
                    let index = this.taxrateTags.findIndex((item) => item == this.taxrate);
                    // 想要插入的数据已经存在了，那么直接提升它就可以
                    if (index > -1) {
                        this.taxrateTags.splice(index, 1);
                    }
                    this.taxrateTags.unshift(this.taxrate);
                    this.taxrateTags.length = this.tagsSize;
                    habit.taxrate = this.taxrateTags;
                }

                $lj.setStorage(this.habitKey, habit);
            },
            /**事件：点击快捷标签设置属性 */
            handleTagsSetValue(tag, val) {
                if (tag == 'discount') {
                    this.discount = val;
                    this.discountCheckbox = true;
                } else if (tag == 'taxrate') {
                    this.taxrate = val;
                    this.taxrateCheckbox = true;
                }
                this.fnCalculatePrice();
            },
            /** 原价：输入监听 */
            handleInputPrice(val) {
                console.log('handleInputPrice val :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(val));
                this.fnCalculatePrice()
            },
            /** 方法：计算价格 */
            fnCalculatePrice() {
                let oPrice = this.enprice; // 除税率后原价
                let discount = this.discount && Number(this.discount) > 0 ? Number(this.discount) : 1;
                let disPrice = ($lj.floatMul(oPrice , discount)*100/100).toFixed(2); // 优惠价
                if (this.taxrateCheckbox && this.taxrate) {
                    if (this.taxPriceCheckbox) {
                        // oPrice = $lj.floatDiv(this.enprice , (1 + Number(this.taxrate))); // 除税率后原价
                        this.taxPrice = Number($lj.floatSub(this.enprice, oPrice)); // 共税
                    } else {
                        this.taxPrice = ($lj.floatMulMore([oPrice, this.taxrate, discount])*100/100).toFixed(2); // 共税
                    }
                } else {
                    this.taxPrice = 0;
                }
                this.discountPrice = Number($lj.floatSub(oPrice , disPrice)); // 共优惠

                console.log(' oPrice :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(oPrice));
                this.unitPrice = $lj.floatAdd(disPrice , this.taxPrice);
                this.originalPrice = discount == 1 ? 0 : this.enprice;
            },
            handleClickTaxrateSwitch() {
                if (this.taxrateCheckbox) {
                    this.$refs.taxrateField.focus();
                }
            },
            handleClickDiscountSwitch() {
                if (this.discountCheckbox) {
                    this.$refs.discountField.focus();
                }
            },
            handleInputFocus(ev) {
                ev.currentTarget.select();
            },
            /**点击事件：税率开启与关闭 */
            handleChangeRaxrateCheckbox() {
                console.log(' handleChangeRaxrateCheckbox :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.taxrateCheckbox));
                if (!this.taxrateCheckbox) {
                    this.taxrate = '';
                }
                this.fnCalculatePrice()
            },
            /**点击事件：优惠折扣开启与关闭 */
            handleChangeDiscountCheckbox() {
                if (!this.discountCheckbox) {
                    this.discount = '';
                }
                this.fnCalculatePrice()
            },
            initDiscount(mainObject) {
                // 赋值原价
                this.enprice = parseFloat(mainObject.price) || parseFloat(mainObject.enprice);
                // 赋值单位
                this.unit = mainObject.unit;
                this.saleqty = mainObject.saleqty || 1;
                if (Number(mainObject.rebate) != 1) {
                    this.discountCheckbox = true;
                    // 赋值折扣
                    this.discount = mainObject.rebate;
                }
                console.log(' mainObject.taxrate :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(mainObject.taxrate));
                if (Number(mainObject.taxrate) != 0) {
                    this.taxrateCheckbox = true;
                    // 赋值税率
                    this.taxrate = mainObject.taxrate;
                }
                // 赋值交货日期
                this.requiredate = mainObject.requiredate || '';

                // this.rprice = this.handleCalcRPrice(0);

                this.mxdscrp = mainObject.mxdscrp;
            },
            /**事件：选择多单位 */
            handleSelectActionUnit(action, index) {
                this.unit = action.name;
                this.showActionUnit = false;
                this.inputConfigure();
            },
            /**唤醒弹窗：选择多单位 */
            handleShowActionUnit() {
                if (this.unitList.length <= 1) {
                    return false;
                }
                this.showActionUnit = true
            },
            GetMtrlInfo() {
                this.skeletonLoading = true
                let mtrlcode = this.mainObject.mtrlcode;
                let self = this;
                $lj.postLJRequest("GetMtrlInfo", {
                    token: $lj.getStorage("token"),
                    mtrlcode: mtrlcode
                }, function (ret) {
                    self.mtrlInfo = ret.mainInfo;
                    let pictureList = ret.mainInfo.pics;
                    if (pictureList.length > 0) { //图片
                        for (let i = 0; i < pictureList.length; i++) {
                            var img = {};
                            img.picmd5 = pictureList[i];
                            self.imgList.push(img);
                        }
                    } else {
                        var img = {};
                        img.src = "../../../../../assets/image/default.png"
                        img.noPic = true;
                        self.imgList.push(img);
                    }

                    if(self.isModify){
                        self.handleModifyDefaultValue(self.status,self.mtrlInfo.statusop,self.mtrlInfo.statusflag);
                        self.handleModifyDefaultValue(self.woodcode,self.mtrlInfo.woodcodeop,self.mtrlInfo.woodcodeflag);
                        self.handleModifyDefaultValue(self.pcode,self.mtrlInfo.pcodeop,self.mtrlInfo.pcodeflag);
                    }

                    self.handleAddUnitList(ret.mainInfo.unit);
                    self.handleAddUnitList(ret.mainInfo.unit_buy);
                    self.handleAddUnitList(ret.mainInfo.unit_sale);
                    self.handleAddUnitList(ret.mainInfo.unit_scll);

                    self.skeletonLoading = false;
                })
            },
            handleModifyDefaultValue(value,codeop,flag){
                if(flag == 4 || flag == 5){
                    var valueList = [];
                    if (value) {
                        var splitList = value.split("|");
                        for (let i = 0; i < splitList.length; i++) {
                            var LV = splitList[i].split(":")
                            if (LV[0] != "") {
                                var S = {
                                    lable: LV[0],
                                    value: LV[1]
                                }
                                valueList.push(S)
                            }
                        }
                    }
                    for (let j = 0; j < valueList.length; j++) {
                        for (let k = 0; k < codeop.mtrlcfgcodes.length; k++) {
                            if (valueList[j].lable === codeop.mtrlcfgcodes[k]
                                .name) {
                                for (let l = 0; l < codeop.mtrlcfgcodes[k].opstrings
                                    .length; l++) {
                                    if (codeop.mtrlcfgcodes[k].opstrings[l].valuestr ===
                                        valueList[j].value) {
                                        codeop.mtrlcfgcodes[k].opstrings[l].choice = 1;
                                    } else {
                                        codeop.mtrlcfgcodes[k].opstrings[l].choice = 0;
                                    }
                                }
                            }
                        }
                    }
                }else if(flag == 2){
                    // 组合配置
                    var valueList = [];
                    if (value) {
                        var splitList = value.split("+");
                        for (let i = 0; i < splitList.length; i++) {
                            var LV = splitList[i].split("*")
                            if (LV[0] != "") {
                                var S = {
                                    lable: LV[0],
                                    value: LV[1] || 1
                                }
                                valueList.push(S)
                            }
                        }
                    }
                    for (let j = 0; j < valueList.length; j++) {
                        for (let k = 0; k < codeop.mtrlcfgs.length; k++) {
                            if (valueList[j].lable === codeop.mtrlcfgs[k]
                                .name) {
                                codeop.mtrlcfgs[k].choice = 1;
                                codeop.mtrlcfgs[k].cnt = valueList[j].value;
                            }
                        }
                    }
                }else if(flag == 1){
                    // 严格选择
                    for (let m = 0; m < codeop.opstrings.length; m++) {
                        if (value === codeop.opstrings[m].valuestr) {
                            codeop.opstrings[m].choice = 1;
                        } else {
                            codeop.opstrings[m].choice = 0;
                        }
                    }
                }
            },
            handleAddUnitList(unit){
                if(unit) {
                    this.unitList.push({name: unit})
                }
            },
            // initDiscount() {
            //     // 赋值原价
            //     this.enprice = this.mainObject.price;
            //     // 赋值单位
            //     this.unit = this.mainObject.unit;
            //     // 赋值折扣
            //     this.discount = this.mainObject.rebate;
            //     // 赋值税率
            //     this.taxrate = this.mainObject.taxrate;
            //     // 赋值交货日期
            //     this.requiredate = $lj.dateformat(new Date(),'yyyy-MM-dd')

            //     this.rprice = this.handleCalcRPrice(0)
            // },
            handleUnitPickerConfirm(value,index) {
                this.unit = value;
                this.showunit = false;
                this.inputConfigure();
            },
            calculatePrice(price,discount) {
                return parseFloat(price * discount);
            },
            totalPrice(price,count) {
                return parseFloat(price * count);
            },
            inputStatus(value) {
                this.status = value;
                this.inputConfigure();
            },
            inputWoodcode(value) {
                this.woodcode = value;
                this.inputConfigure();
            },
            inputPcode(value) {
                this.pcode = value
                this.inputConfigure();
            },
            /** 获取物料库存 */
            inputConfigure() {
                let self = this;
                let priceTemp = {};
                priceTemp.cusid = this.cusid;
                priceTemp.moneyid = this.moneyid;
                priceTemp.status = this.status;
                priceTemp.woodcode = this.woodcode;
                priceTemp.pcode = this.pcode;
                priceTemp.mtrlid = this.mtrlInfo.mtrlid;
                priceTemp.qty = this.saleqty;
                priceTemp.unit = this.unit;
                priceTemp.typeid = this.typeid;
                priceTemp.tax = Number(this.taxrate);
                $lj.postLJRequest("GetPriceSaletask", {
                    token: $lj.getStorage("token"),
                    Price: priceTemp
                }, function (ret) {
                    if (ret.price) {
                        self.enprice = ret.price;
                        self.discount = ret.rebate;
                        self.taxrate = ret.tax;
                    } else {
                        self.enprice = 0;
                    };
                })
            },
            handleAddGoodsToCart() {
                console.log('handleConfirm this.mtrlInfo :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.mtrlInfo));
                let addItem = {
                    mtrlid: this.mtrlInfo.mtrlid,
                    mtrlcode: this.mtrlInfo.mtrlcode,
                    mtrlname: this.mtrlInfo.mtrlname,
                    statusflag: this.mtrlInfo.statusflag,
                    woodcodeflag: this.mtrlInfo.woodcodeflag,
                    pcodeflag: this.mtrlInfo.pcodeflag,
                    status: this.status,
                    woodcode: this.woodcode,
                    pcode:this.pcode,
                    saleqty: this.saleqty,
                    taxrate: this.taxrate,
                    unit: this.unit,
                    rebate: this.mtrlInfo.rebate,
                    mxdscrp: this.mxdscrp,
                    requiredate: this.requiredate,
                };
                if (this.taxPriceCheckbox && this.taxrate) {
                    addItem.enprice = this.enprice;
                } else {
                    // 如果使用了不含税的价格，需转换成含税的价格
                    let taxPrice = ($lj.floatMulMore([this.enprice, this.taxrate])*100/100).toFixed(2); // 共税
                    addItem.enprice = $lj.floatAdd(this.enprice, taxPrice) ;
                }
                let discount = this.discount;
                if (Number(this.discount) == 0) {
                    discount = 1;
                }
                // 赋值折扣
                addItem.rebate = Number(discount);

                let taxrate = this.taxrate;
                if (Number(this.taxrate) == 0) {
                    taxrate = 0;
                }
                // 赋值税率
                addItem.taxrate = Number(taxrate);

                // 添加到购物车
                let self = this;
                $lj.postLJRequest("AddGoodsToCart", {
                    token: $lj.getStorage("token"),
                    mtrlid: addItem.mtrlid,
                    status: this.status,
                    woodcode: this.woodcode,
                    pcode: this.pcode,
                    qty: this.saleqty,
                    rebate: addItem.rebate,
                    enprice: addItem.enprice,
                    unit: addItem.unit,
                    taxrate: addItem.taxrate
                }, function (ret) {
                    if(ret && ret.saletaskMx) {

                        var mx = ret.saletaskMx;

                        mx.mxdscrp = self.mxdscrp;
                        mx.requiredate = self.requiredate;

                        mx.mtrlid = mx.MtrlID;
                        mx.saleqty = mx.SaleQty;

                        if(self.isModify) {
                            let task = $lj.getStorage(self.productDraft);
                            var mxItem = task.mxList[self.mainObject.index];
                            Object.keys(mx).forEach(key=>{mxItem[key]=mx[key]})
                            $lj.setStorage(self.productDraft,task);
                            $lj.sendEvent("saletask_edit_refresh");
                        }else{
                            $lj.sendEvent("saletask_edit_add",mx);
                            $lj.toast("成功添加到销售订单明细列表");
                            $lj.sendEvent("cart_refresh");
                        }

                        $lj.closeWin();
                    }
                })
            },
            handleToastInfo(title,value) {
                $lj.toast(`${title}:${value && value.length > 0 ? value : '无'}`)
            },
            handleSelectValue(e) {
                e.currentTarget.select();
            },
            handleRqDatePickerConfirm(value) {
                this.requiredate = $lj.dateformat(value,'yyyy-MM-dd');
                this.showRqDate = false;
            },
            handleEditPriceInfo(flag,value) {
                console.log("flag>>>>",flag,"value>>>",parseFloat(value))
                this.editmin = -Infinity
                this.editmax = Infinity
                if (flag == 'discount' || flag == 'taxrate') {
                    this.editmin = 0
                    this.editmax = 1
                }
                this.editsign = flag;

                this.$refs.pricePupup.open(parseFloat(value));
            },
            handleEditPriceConfirm(value) {
                console.log("sign>>>>>>>",this.editsign,"value>>>>>>>>>>>>",value)
                this[this.editsign] = value;
                if(this.editsign == 'enprice' || this.editsign == 'taxrate' || this.editsign == 'discount') {
                    this.rprice = this.handleCalcRPrice(0)
                }else if(this.editsign == 'rprice') {
                    this.enprice = this.handleCalcRPrice(1)
                }
            },
            handleCalcRPrice(type) {
                if(type == 1) {
                    // 计算原价
                    return $lj.numberFormat(parseFloat(this.rprice) * (1 + parseFloat(this.taxrate)) / parseFloat(this.discount),5);
                }
                return $lj.numberFormat(parseFloat(this.enprice) * parseFloat(this.discount) / (1 + parseFloat(this.taxrate)),5);
            },
        },
        computed: {
            isModify() {
                return this.winMode == 1;
            },
            discountprice() {
                let value = 0
                value = this.calculatePrice(this.enprice,this.discount);
                value = parseFloat(value / (1 + parseFloat(this.taxrate)));
                return value;
            },
            // sumprice() {
            //     return parseFloat(this.discountprice * this.saleqty);
            // }
        },
        filters: {
            ellipsis(value, length) {
                if (!value) return "";
                if (value.toString().length > length) {
                    return value.toString().slice(0, length) + "...";
                }
                return value;
            },
        },
    }
</script>

<style lang="less">
    .my-swipe .van-swipe-item {
        color: #fff;
        font-size: 20px;
        line-height: 200px;
        text-align: center;
        background-color: #39a9ed;
    }
    .goods-icon .van-badge--fixed{
        top: 8px;
    }
    .van-divider{
        margin: 10px;
    }
    .van-skeleton {
        padding-top: 20px;

        .van-skeleton__row, .van-skeleton__title {
            border-radius: 2px;
        }

        &.fff_bg {
            .van-skeleton__row, .van-skeleton__title {
                background-color: #fff;
            }
        }
    }
</style>
<style lang="less">
@import "../../../../assets/css/lj-style-variable";
@import "../../../../assets/css/lj-base";
@import "../../../../assets/css/lj-pda";
    .product-container {

        .sku-popup {
            max-height: 70%;
        }

        .product-swipe-photo {
            width: 100%;
            height: 250px;
            overflow: hidden;
        }

        .product-swipe-photo-item {
            object-fit: cover; 
            width: 100%; 
            height: 100%
        }

        .product-item {
            // padding: 0 10px;
        }
    }
    .product-introduct {
        margin-top: 10px;
        padding: 0 10px 5px 10px;
        border-radius: 8px;
        background-color: @cardItemBackgroundColor;

        .product-price-monthsale {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .product-price {
                font-size: 18px;
                font-weight: 700;
                color: @colorRed;
            }

            .prodcut-monthsale {
                font-size: 10px;
                color: @summaryLightTextColor;
            }
        }

        .product-name {
            font-size: 16px;
            font-weight: 500;
        }

        .product-informations {
            display: flex;
            flex-direction: row;
            flex-wrap: nowrap;
            align-items: center;
            width: 100%;

            .information-item {
                display: flex;
                flex-direction: column;
                padding: 0 3px;
                align-items: center;
                border-right: 1px solid @summaryLightTextColor;
                width: calc(100% / 3);
                font-size: 12px;

                .item-icon > .iconfont {
                    font-size: 12px;
                }

                .item-text {
                    text-align: center;
                    width: 100%;
                    overflow:hidden;
                    text-overflow:ellipsis;
                    white-space:nowrap;
                }

                .item-title {
                    font-size: 10px;
                    color: @summaryLightTextColor;
                }

                &:last-child {
                    border-right: none;
                }
            }
        }
    }
    // .product-configuration {
    //     border-radius: 8px;
    //     background-color: @cardItemBackgroundColor;
    //     overflow: hidden;

    //     .van-cell-group {
    //         border-radius: 8px;

    //         .van-cell {
    //             &:first-child {
    //                 border-radius: 8px 8px 0 0;
    //             }
    //             &:last-child {
    //                 border-radius: 0 0 8px 8px;
    //             }
    //         }
    //     }
    // }
    .product-footer {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: flex-start;
        // padding: 5px 10px;
        
        align-items: center;

        .price-sum {
            font-size: 20px;
            font-weight: 500;
            color: @colorSharpTextRed;
            margin: 0 5px;
        }
    }

    .price-configuration {
        .van-cell-group {
            .van-cell {
                .van-cell__value {
                    max-width: 40%;
                }
            }
            .van-field__label {
                width: auto!important;
            }
        }
    }
    .product-configuration {
        // border-radius: 8px;
        // background-color: @cardItemBackgroundColor;
        // overflow: hidden;

        .van-cell-group {
            border-radius: 8px;

            .van-cell {
                // &:first-child {
                //     border-radius: 8px 8px 0 0;
                // }
                // &:last-child {
                //     border-radius: 0 0 8px 8px;
                // }

                .lj-tag {
                    margin-left: 2px;
                }
                &.van-field--disabled {
                    .van-cell__value {
                        display: none;
                    }
                }
                // .van-cell__value {
                //     max-width: 40%;
                // }
            }
            // .van-field__label {
            //     width: auto!important;
            // }
        }
        .unit-wrap {
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0;
            padding: 0;
            border-radius: 2px;
            box-sizing: border-box;
            width: 28px;
            height: 28px;
            color: #323233;
            margin-left: 8px;
            &.sel_able {
                background-color: #f2f3f5;
            }
        }
        .field-checkbox {
            margin-left: 4px;
        }
        .field-label {
            color: @light-label-primary;

            .subtitle {
                color: @light-label-secondary;
            }
        }
    }
    .popup-footer {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 5px 16px;
        background-color: @cardItemBackgroundColor;

        .confirm-btn {
            width: 40vw;
            // margin: 10px;
            margin-left: 10px;
            border-radius: 18px;
            height: 36px;
            line-height: 36px;
            background-color: @musePrimary;
            color: #fff;
            text-align: center;
            font-size: 14px;
        }
        .total {
            justify-content: flex-end;
            text-align: right;

            del {
                color: @light-label-tertiary;
                line-height: 16px;
            }
            .price {
                display: flex;
                justify-content: flex-end;
                align-items: baseline;
                .num {
                    font-size: 14px;
                    color: @musePrimary;
                }
                .p {
                    font-size: 20px!important;
                    font-weight: 600;
                }
            }
        }
        .other {
            display: flex;
            justify-content: flex-end;
            align-items: flex-end;
            color: @musePrimary;
        }
    }
</style>