|
|
@@ -0,0 +1,184 @@
|
|
|
+const _Http = getApp().globalData.http,
|
|
|
+ file = require("../../../utils/FormatTheAttachment");
|
|
|
+import currency from "../../../utils/currency";
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ loading: true,
|
|
|
+ params: {}, //请求体
|
|
|
+ result: [], //返回结果
|
|
|
+ radio: false, //是否为单选
|
|
|
+ idname: "itemid", //idkey
|
|
|
+ showName: "itemname",
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ this.setData({
|
|
|
+ siteid: wx.getStorageSync('userMsg').siteid
|
|
|
+ })
|
|
|
+ if (options.params) {
|
|
|
+ let params = JSON.parse(options.params);
|
|
|
+ if (!params.content.pageNumber || !params.content.pageTotal) {
|
|
|
+ params.content.pageNumber = 1;
|
|
|
+ params.content.pageTotal = 1;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ params
|
|
|
+ });
|
|
|
+ };
|
|
|
+ this.setData({
|
|
|
+ radio: options.radio ? true : false,
|
|
|
+ idname: options.idname || this.data.idname,
|
|
|
+ showName: options.showName || this.data.showName,
|
|
|
+ oldPrice: options.oldprice || "oldprice" //对比老价格
|
|
|
+ });
|
|
|
+ this.getList()
|
|
|
+ getApp().globalData.Language.getLanguagePackage(this, '添加商品');
|
|
|
+ },
|
|
|
+ getList(init = false) {
|
|
|
+ //init 用于初始化分页
|
|
|
+ if (init.detail != undefined) init = init.detail;
|
|
|
+ let params = this.data.params;
|
|
|
+ if (init) params.content.pageNumber = 1
|
|
|
+ if (params.content.pageNumber > params.content.pageTotal) return;
|
|
|
+ for (const key in params.content.where) {
|
|
|
+ if (String(params.content.where[key]).length == 0) delete(params.content.where[key])
|
|
|
+ }
|
|
|
+ _Http.basic(params).then(res => {
|
|
|
+ console.log("选择产品列表", res)
|
|
|
+ this.selectComponent('#ListBox').RefreshToComplete();
|
|
|
+ if (res.code != '1') return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ const CNY = num => currency(num, {
|
|
|
+ symbol: "¥",
|
|
|
+ precision: 2
|
|
|
+ }).format();
|
|
|
+ res.data = res.data.map(value => {
|
|
|
+ if (value.attinfos.length != 0) {
|
|
|
+ value.attinfos = file.fileList(value.attinfos)
|
|
|
+ let image = value.attinfos.find(v => v.fileType == "image");
|
|
|
+ value.cover = image ? image.cover : "";
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ 'params.content.pageNumber': res.pageNumber + 1,
|
|
|
+ 'params.content.pageTotal': res.pageTotal,
|
|
|
+ 'params.content.total': res.total,
|
|
|
+ list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
|
|
|
+ loading: false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 选中 */
|
|
|
+ changeResult(e) {
|
|
|
+ let {
|
|
|
+ id
|
|
|
+ } = e.currentTarget.dataset, result = this.data.result;
|
|
|
+ if (this.data.radio) {
|
|
|
+ result = [id];
|
|
|
+ } else {
|
|
|
+ result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ result
|
|
|
+ });
|
|
|
+ if (this.data.radio) this.submit();
|
|
|
+ },
|
|
|
+ /* 提交 */
|
|
|
+ submit() {
|
|
|
+ let result = this.data.result,
|
|
|
+ obj = this.data.radio ? {
|
|
|
+ id: result,
|
|
|
+ item: this.data.list.find(value => value[this.data.idname] == result),
|
|
|
+ value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
|
|
|
+ } : {
|
|
|
+ result,
|
|
|
+ list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
|
|
|
+ value: [result.map(v => {
|
|
|
+ let data = this.data.list.find(value => value[this.data.idname] == v);
|
|
|
+ return data ? data[this.data.showName] : ""
|
|
|
+ }), result]
|
|
|
+ }
|
|
|
+ getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
|
|
|
+ },
|
|
|
+ /* 预览图片 */
|
|
|
+ viewImage(e) {
|
|
|
+ const {
|
|
|
+ file
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ if (file.length) wx.previewMedia({
|
|
|
+ sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
|
|
|
+ return {
|
|
|
+ url: v.url,
|
|
|
+ type: v.fileType
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ current: 0,
|
|
|
+ showmenu: true
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 开始搜索 */
|
|
|
+ startSearch({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
|
|
|
+ if (detail == condition) return;
|
|
|
+ this.setData({
|
|
|
+ 'content.where.condition': detail,
|
|
|
+ 'params.content.where.condition': detail
|
|
|
+ });
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ /* 取消搜索 */
|
|
|
+ onClear() {
|
|
|
+ this.setData({
|
|
|
+ 'content.where.condition': "",
|
|
|
+ 'params.content.where.condition': ""
|
|
|
+ });
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ onReady() {
|
|
|
+ this.selectComponent("#ListBox").setHeight(".total", this);
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ //回收数据
|
|
|
+ getApp().globalData.handleSelect = null;
|
|
|
+ },
|
|
|
+ /* 打断 */
|
|
|
+ interrupt(e) {
|
|
|
+ let {
|
|
|
+ name,
|
|
|
+ index,
|
|
|
+ item,
|
|
|
+ list
|
|
|
+ } = e.detail;
|
|
|
+ if (name == "sa_brandid") _Http.basic({
|
|
|
+ "id": "20220922110403",
|
|
|
+ "content": {
|
|
|
+ nocache: true,
|
|
|
+ "sa_brandid": item.sa_brandid,
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("分类列表", res)
|
|
|
+ if (res.code != '1') return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ if (!res.data[0].ttemclass) return;
|
|
|
+ list[4] = {
|
|
|
+ label: "分类",
|
|
|
+ index: null,
|
|
|
+ type: "multilevelClass",
|
|
|
+ showName: "itemclassname", //显示字段
|
|
|
+ valueKey: "itemclassid", //返回Key
|
|
|
+ selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
|
|
|
+ value: "", //选中值
|
|
|
+ list: res.data[0].ttemclass
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ filtratelist: list
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+})
|