123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- const _Http = getApp().globalData.http;
- let sa_brandid = null,
- sys_enterpriseid = null;
- import {
- getLabelList
- } from "../../utils/customItemType";
- import {
- fileList
- } from "../../utils/FormatTheAttachment";
- import currency from "../../utils/currency";
- Page({
- data: {
- itemCount: 0,
- selectCount: 0,
- labelList: getLabelList(),
- hidePrice: wx.getStorageSync('hidePrice'),
- badge: getApp().globalData.collectCount,
- favoriteCount: getApp().globalData.favoriteCount,
- loading: true,
- content: {
- sa_itemgroupid: null,
- spec: "", //规格
- color: "", //颜色
- material: "", //材质
- cheek: "" //边框
- },
- detail: {
- spec: ""
- },
- privacyFieldC: [],
- isShowFavorites: false,
- UniqueLine: false
- },
- onLoad(options) {
- let data = JSON.parse(options.params);
- sa_brandid = data.sa_brandid;
- if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = data.sys_enterpriseid
- this.data.content.sa_itemgroupid = data.sa_itemgroupid;
- this.setData({
- userrole: wx.getStorageSync('userrole'),
- isShowFavorites: wx.getStorageSync('auth').wfavorites ? true : false
- })
- try {
- let privacyFieldC = wx.getStorageSync('auth').wmarket.forms.wmarket.formcols.map(v => v.title);
- this.setData({
- privacyFieldC
- })
- console.log("privacyFieldC", privacyFieldC)
- } catch (error) {
- }
- },
- /* 获取详情 */
- getDetail(init = false, getCustom = true) {
- let content = this.data.content;
- if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
- if (this.data.UniqueLine)['spec', 'cheek', 'material', 'color'].forEach(key => content[key] = '')
- _Http.basic({
- "id": "20221223165503",
- content
- }).then(res => {
- wx.hideLoading();
- console.log("商品详情", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- if (res.data.item.length == 0) return wx.showToast({
- title: '未查询到商品',
- icon: "none",
- mask: true
- })
- const item = res.data.item[0];
- this.handleFiles(item.attinfos)
- const CNY = sum => currency(sum, {
- symbol: "¥",
- precision: 2
- }).format();
- item.gradeprice = CNY(item.gradeprice);
- item.marketprice = CNY(item.marketprice);
- item.qty = item.orderaddqty;
- let ros = {
- specRows: res.data.specRows.reverse(),
- cheekRows: res.data.cheekRows,
- materialRows: res.data.materialRows,
- colorRows: res.data.colorRows,
- };
- let obj = {},
- auto = true,
- UniqueLine = true;
- ['spec', 'cheek', 'material', 'color'].forEach(key => obj[key] = ros[key + 'Rows'].filter(v => v.flag))
- for (const key in obj) {
- if (obj[key].length > 1) {
- auto = false
- UniqueLine = false;
- }
- }
- if (auto) {
- for (const key in obj) {
- if (obj[key].length) content[key] = obj[key][0].parm;
- }
- }
- this.setData({
- content,
- detail: item,
- ...ros,
- loading: false,
- itemCount: ['specRows', 'cheekRows', 'materialRows', 'colorRows'].filter(v => res.data[v].length).length,
- selectCount: ['cheek', 'color', 'material', 'spec'].filter(v => content[v].length).length,
- UniqueLine
- });
- //是否定制
- if (getCustom && item.iscustomsize == 1) this.selectComponent("#customMade").init(item);
- })
- },
- /* 预览媒体 */
- viewMedias(e) {
- const {
- index,
- type
- } = e.currentTarget.dataset;
- wx.previewMedia({
- current: index,
- sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
- })
- },
- /* 处理附件 */
- handleFiles(arr) {
- let files = {
- images: [],
- viewImages: [],
- videos: [],
- viewVideos: [],
- files: []
- },
- list = fileList(arr);
- list.forEach(v => {
- switch (v.fileType) {
- case "video":
- files.videos.push(v)
- files.viewVideos.push({
- url: v.url,
- type: "video",
- poster: v.subfiles[0].url
- })
- break;
- case "image":
- files.images.push(v)
- files.viewImages.push({
- url: v.url,
- type: "image"
- })
- break;
- default:
- files.files.push(v)
- break;
- }
- });
- this.setData({
- files
- })
- },
- /* 切换产品 */
- changeItemno(e) {
- const {
- value,
- valuename
- } = e.currentTarget.dataset,
- content = this.data.content;
- if (!value.flag) return;
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- // UniqueLine
- content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
- this.setData({
- selectCount: ['cheek', 'color', 'material', 'spec'].filter(v => content[v].length).length
- })
- this.getDetail(valuename == "spec")
- },
- /* 打开文档 */
- openDocument(e) {
- const {
- item
- } = e.currentTarget.dataset;
- console.log(item)
- wx.showLoading({
- title: '加载中...',
- mask: true,
- })
- wx.downloadFile({
- url: item.url,
- success: function (res) {
- const filePath = res.tempFilePath
- wx.openDocument({
- filePath: filePath,
- showMenu: true,
- fileType: item.postfix,
- success: function (res) {
- wx.hideLoading();
- console.log('打开文档成功')
- },
- fail(e) {
- console.log(e)
- wx.showToast({
- title: '打开失败',
- icon: "error",
- mask: true
- })
- }
- })
- },
- fail(e) {
- console.log(e)
- wx.showToast({
- title: '打开失败',
- icon: "error",
- mask: true
- })
- }
- })
- },
- clickBut(e) {
- if (this.data.itemCount != this.data.selectCount) return wx.showToast({
- title: '请完成产品选项在进行操作',
- icon: "none"
- })
- this.data.detail.tradefield.length >= 2 ? wx.showToast({
- title: '请选择加入产品领域',
- icon: "none",
- duration: 3000
- }) : this[e.target.id](0);
- },
- /* 选择领域 */
- storage(e) {
- this.addToShoppingCart(e.detail.value)
- },
- /* 加入购物车 */
- addToShoppingCart(index) {
- let detail = this.data.detail,
- custom = {
- length: 0,
- width: 0
- };
- //是否为定制项
- if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
- if (typeof custom == "boolean") return;
- let content = Object.assign(this.data.content, {
- sa_brandid,
- itemid: detail.itemid, //货品id
- qty: detail.qty, //数量
- itemno: detail.itemno, //货品编号
- tradefield: detail.tradefield[index].tradefield,
- }, custom);
- _Http.basic({
- "id": 20220924095102,
- content,
- }).then(res => {
- console.log("加入购物车", res)
- wx.showToast({
- title: res.msg == '成功' ? '加入成功' : res.msg,
- icon: "none"
- });
- if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
- badge
- }))
- })
- },
- /* 加入收藏夹 */
- addToFavorites() {
- let detail = this.data.detail,
- iscollection = detail.iscollection == 1 ? false : true,
- custom = {
- width: 0,
- length: 0,
- },
- favorites = {};
- //是否为定制项
- if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
- for (const key in custom) {
- favorites['favorites' + key] = custom[key]
- }
- if (typeof custom == "boolean") return;
- _Http.basic({
- "id": 20231121143403,
- "content": {
- "itemid": this.data.detail.itemid, //货品id
- "qty": detail.qty, //数量
- ...custom,
- iscollection,
- ...favorites
- },
- }).then(res => {
- console.log(iscollection + "收藏夹", res)
- wx.showToast({
- title: res.msg == '成功' ? iscollection ? '收藏成功' : "已取消收藏" : res.msg,
- icon: "none"
- });
- if (res.msg == '成功') {
- getApp().globalData.getFavoriteCount().then(num => {
- this.setData({
- favoriteCount: num
- })
- })
- this.setData({
- "detail.iscollection": iscollection ? 1 : 0
- })
- }
- })
- },
- /* 立即下单 */
- placeAnOrder(index) {
- let detail = this.data.detail,
- content = {
- "type": "标准订单",
- tradefield: detail.tradefield[index].tradefield
- },
- custom = {
- length: 0,
- width: 0
- }
- //是否为定制项
- if (detail.iscustomsize == 1) custom = this.selectComponent("#customMade").getResult(true);
- console.log("custom", custom)
- if (typeof custom == "boolean") return;
- content.items = [Object.assign({
- sa_orderitemsid: 0,
- sa_brandid,
- itemid: detail.itemid, //货品id
- qty: detail.qty, //数量
- itemno: detail.itemno, //货品编号
- }, custom)];
- _Http.basic({
- "id": 20221128183202,
- content,
- }).then(res => {
- console.log("创建订单", res)
- wx.showModal({
- title: '提示',
- content: res.msg == '成功' ? '订单创建成功!是否立即查看' : res.msg,
- showCancel: res.msg == '成功',
- complete: ({
- confirm
- }) => {
- if (res.msg == '成功' && confirm) wx.navigateTo({
- url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
- })
- }
- })
- })
- },
- /* 前往购物车 */
- toCollect(e) {
- getApp().globalData.changeBar({
- detail: "Collect"
- })
- wx.navigateBack();
- },
- onShow() {
- this.setData({
- favoriteCount: getApp().globalData.favoriteCount,
- badge: getApp().globalData.collectCount,
- })
- this.getDetail(true, this.data.loading);
- },
- /* 步进器输入框失去焦点 */
- inputBlur(e) {
- let item = this.data.detail;
- let qty = 0;
- if (item.orderminqty > e.detail.value) {
- wx.showToast({
- title: '输入数量低于最低起订量!',
- icon: "none"
- })
- qty = item.orderminqty;
- } else if (item.orderminqty < e.detail.value) {
- var currencyRounding = value => currency(value, {
- increment: item.orderaddqty
- });
- qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
- } else {
- qty = e.detail.value;
- }
- this.setData({
- "detail.qty": 0
- });
- this.setData({
- "detail.qty": qty
- });
- },
- stepperChange(e) {
- let item = this.data.detail;
- if (e.type == 'plus') {
- item.qty += (item.orderaddqty) - 0 || 1
- } else {
- item.qty -= item.orderaddqty || 1
- }
- this.setData({
- detail: item
- })
- },
- })
|