123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- const _Http = getApp().globalData.http;
- let sa_brandid = null,
- sys_enterpriseid = null;
- import {
- fileList
- } from "../../utils/FormatTheAttachment";
- import currency from "../../utils/currency";
- Page({
- data: {
- loading: true
- },
- onLoad(options) {
- if (options.id) this.setData({
- sa_itemgroupid: options.id,
- itemno: options.itemno
- })
- sa_brandid = options.sa_brandid;
- this.setData({
- userrole: wx.getStorageSync('userrole')
- })
- if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = options.sys_enterpriseid
- this.getDetail();
- getApp().globalData.Language.getLanguagePackage(this, '商城');
- },
- /* 获取详情 */
- getDetail() {
- let content = {
- "sa_itemgroupid": this.data.sa_itemgroupid,
- pageSize: 999
- }
- if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
- _Http.basic({
- "id": "20220926142403",
- content
- }).then(res => {
- console.log("商品详情", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- if (res.data.length == 0) {
- wx.showToast({
- title: getApp().globalData.Language.getMapText('未查询到商品'),
- icon: "none",
- mask: true
- })
- setTimeout(() => {
- wx.navigateBack();
- }, 500)
- return;
- }
- let index = res.data.findIndex(v => v.itemno == this.data.itemno);
- if (index == -1) {
- index = 0;
- this.setData({
- itemno: res.data[0].itemno
- })
- }
- this.handleFiles(res.data[index].attinfos)
- const CNY = sum => currency(sum, {
- symbol: "¥",
- precision: 2
- }).format();
- this.setData({
- detail: res.data[index],
- rows: res.data.map(v => {
- v.gradeprice = CNY(v.gradeprice);
- v.marketprice = CNY(v.marketprice);
- return v
- }),
- loading: false
- })
- this.getRep()
- })
- },
- /* 更新库存 */
- getRep() {
- _Http.basic({
- "id": 20220923155302,
- "content": {
- "itemid": this.data.detail.itemid
- }
- }).then(res => {
- console.log("查询库存", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- this.setData({
- "detail.stockstatus": res.data.stockstatus,
- "detail.cansaleqty": res.data.invbal_qty,
- })
- })
- },
- /* 预览媒体 */
- 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 {
- item
- } = e.currentTarget.dataset;
- if (item.itemno == this.data.itemno) return;
- this.handleFiles(item.attinfos)
- this.setData({
- detail: item,
- itemno: item.itemno
- })
- this.getRep()
- },
- clickBut() {
- this.data.detail.tradefield.length >= 2 ? wx.showToast({
- title: getApp().globalData.Language.getMapText('请选择加入产品领域'),
- icon: "none",
- duration: 3000
- }) : this.handleStorage(0);
- },
- /* 打开文档 */
- openDocument(e) {
- const {
- item
- } = e.currentTarget.dataset;
- console.log(item)
- wx.showLoading({
- title: getApp().globalData.Language.getMapText('加载中...'),
- 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: getApp().globalData.Language.getMapText('打开失败'),
- icon: "error",
- mask: true
- })
- }
- })
- },
- fail(e) {
- console.log(e)
- wx.showToast({
- title: getApp().globalData.Language.getMapText('打开失败'),
- icon: "error",
- mask: true
- })
- }
- })
- },
- /* 选择领域 */
- storage(e) {
- this.handleStorage(e.detail.value)
- },
- handleStorage(index) {
- let detail = this.data.detail;
- _Http.basic({
- "id": 20220924095102,
- "content": {
- sa_brandid,
- "itemid": detail.itemid, //货品id
- "qty": detail.orderminqty, //数量
- "itemno": this.data.itemno, //货品编号
- tradefield: detail.tradefield[index].tradefield
- },
- }).then(res => {
- console.log("加入购物车", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- });
- _Http.basic({
- "id": 20220927093202,
- "content": {}
- }, false).then(res => {
- console.log("购物车数量", res)
- getApp().globalData.num = res.data.num;
- if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
- setTimeout(() => {
- getApp().globalData.Language.showToast('加入成功')
- }, 200);
- });
- })
- },
- onShow() {
- if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
- },
- })
|