|
@@ -1,161 +1,205 @@
|
|
|
const _Http = getApp().globalData.http;
|
|
|
|
|
|
import {
|
|
|
- fileList
|
|
|
+ fileList
|
|
|
} from "../../utils/FormatTheAttachment";
|
|
|
|
|
|
Page({
|
|
|
- data: {
|
|
|
- loading: true
|
|
|
- },
|
|
|
- onLoad(options) {
|
|
|
- if (options.id) this.setData({
|
|
|
- sa_itemgroupid: options.id,
|
|
|
- itemno: options.itemno
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- userrole: wx.getStorageSync('userrole')
|
|
|
- })
|
|
|
- this.getDetail();
|
|
|
- },
|
|
|
- /* 获取详情 */
|
|
|
- getDetail() {
|
|
|
- _Http.basic({
|
|
|
- "id": "20220926142403",
|
|
|
- "content": {
|
|
|
- "sa_itemgroupid": this.data.sa_itemgroupid,
|
|
|
- // itemno: this.data.itemno
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- console.log("商品详情", res)
|
|
|
- if (res.msg != '成功') return wx.showToast({
|
|
|
- title: res.msg,
|
|
|
- icon: "none"
|
|
|
- })
|
|
|
- if (res.data.length == 0) {
|
|
|
- wx.showToast({
|
|
|
- title: '未查询到商品',
|
|
|
- icon: "none",
|
|
|
- mask: true
|
|
|
- })
|
|
|
- setTimeout(() => {
|
|
|
- wx.navigateBack();
|
|
|
- }, 500)
|
|
|
- return;
|
|
|
- }
|
|
|
- this.handleFiles(res.data[0].attinfos)
|
|
|
- this.setData({
|
|
|
- detail: res.data[0],
|
|
|
- rows: res.data,
|
|
|
- loading: false
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- /* 预览媒体 */
|
|
|
- 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
|
|
|
- })
|
|
|
- },
|
|
|
- clickBut() {
|
|
|
- this.data.detail.tradefield.length >= 2 ? wx.showToast({
|
|
|
- title: '请选择加入产品领域',
|
|
|
- icon: "none",
|
|
|
- duration: 3000
|
|
|
- }) : this.handleStorage(0);
|
|
|
- },
|
|
|
- /* 选择领域 */
|
|
|
- storage(e) {
|
|
|
- this.handleStorage(e.detail.value)
|
|
|
- },
|
|
|
- handleStorage(index) {
|
|
|
- let detail = this.data.detail;
|
|
|
- _Http.basic({
|
|
|
- "id": 20220924095102,
|
|
|
- "content": {
|
|
|
- "sa_brandid": detail.brand, //品牌id
|
|
|
- "itemid": detail.itemid, //货品id
|
|
|
- "qty": 1, //数量
|
|
|
- "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(() => {
|
|
|
- wx.showToast({
|
|
|
- title: '加入成功',
|
|
|
- icon: "none",
|
|
|
- icon: "none"
|
|
|
- });
|
|
|
- }, 200);
|
|
|
- });
|
|
|
- })
|
|
|
- },
|
|
|
- onShow() {
|
|
|
- if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
|
|
|
- },
|
|
|
+ data: {
|
|
|
+ loading: true
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ if (options.id) this.setData({
|
|
|
+ sa_itemgroupid: options.id,
|
|
|
+ itemno: options.itemno
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ userrole: wx.getStorageSync('userrole')
|
|
|
+ })
|
|
|
+ this.getDetail();
|
|
|
+ },
|
|
|
+ /* 获取详情 */
|
|
|
+ getDetail() {
|
|
|
+ _Http.basic({
|
|
|
+ "id": "20220926142403",
|
|
|
+ "content": {
|
|
|
+ "sa_itemgroupid": this.data.sa_itemgroupid,
|
|
|
+ // itemno: this.data.itemno
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("商品详情", res)
|
|
|
+ if (res.msg != '成功') return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ if (res.data.length == 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '未查询到商品',
|
|
|
+ icon: "none",
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.navigateBack();
|
|
|
+ }, 500)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.handleFiles(res.data[0].attinfos)
|
|
|
+ this.setData({
|
|
|
+ detail: res.data[0],
|
|
|
+ rows: res.data,
|
|
|
+ loading: false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 预览媒体 */
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ },
|
|
|
+ clickBut() {
|
|
|
+ this.data.detail.tradefield.length >= 2 ? wx.showToast({
|
|
|
+ title: '请选择加入产品领域',
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ }) : this.handleStorage(0);
|
|
|
+ },
|
|
|
+ /* 打开文档 */
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ /* 选择领域 */
|
|
|
+ storage(e) {
|
|
|
+ this.handleStorage(e.detail.value)
|
|
|
+ },
|
|
|
+ handleStorage(index) {
|
|
|
+ let detail = this.data.detail;
|
|
|
+ _Http.basic({
|
|
|
+ "id": 20220924095102,
|
|
|
+ "content": {
|
|
|
+ "sa_brandid": detail.brand, //品牌id
|
|
|
+ "itemid": detail.itemid, //货品id
|
|
|
+ "qty": 1, //数量
|
|
|
+ "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(() => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '加入成功',
|
|
|
+ icon: "none",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }, 200);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onShow() {
|
|
|
+ if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
|
|
|
+ },
|
|
|
})
|