| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- loading: true,
- params: {}, //请求体
- result: [], //返回结果
- radio: true, //是否为单选
- idname: "itemid", //idkey
- showName: "itemname",
- privacyFieldC: [],
- list: [],
- showAll: false
- },
- onLoad(options) {
- let tableid = 985;
- try {
- tableid = wx.getStorageSync('auth').wAccessoriesApplication.tables.swcard.tableid;
- } catch (error) {
- console.error(error)
- }
- if (options.params) {
- let params = JSON.parse(options.params);
- if (!params.content.pageNumber || !params.content.pageTotal) {
- params.content.pageNumber = 1;
- params.content.pageTotal = 1;
- params.content.tableid = tableid;
- params.content.where.tablefilter = {};
- }
- this.setData({
- params
- });
- };
- this.setData({
- idname: options.idname || this.data.idname,
- showName: options.showName || this.data.showName,
- newPrice: options.newprice || "price", //红色价格
- });
- this.getList(true)
- },
- changeShowAll() {
- let that = this;
- this.setData({
- showAll: !this.data.showAll
- })
- setTimeout(() => {
- that.selectComponent("#ListBox").setHeight(!this.data.showAll ? ".total1" : ".total", that);
- }, 350)
- },
- getList(init = false) {
- let that = this;
- //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;
- _Http.basic(params).then(res => {
- console.log("选择保修卡列表", res)
- this.selectComponent('#ListBox').RefreshToComplete();
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- 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
- })
- setTimeout(() => {
- that.selectComponent("#ListBox").setHeight(!this.data.showAll ? ".total1" : ".total", that);
- }, 350)
- })
- },
- customization(e) {
- let {
- item
- } = e.target.dataset;
- item.pitchOn = false;
- this.bindChangeFun()
- if (item) this.selectComponent("#Custom").onClick(item)
- },
- bindChangeFun() {
- getApp().globalData.customizedProduct = (item, custom) => {
- return new Promise((resolve) => {
- item = Object.assign(item, custom)
- item.customText = getCustomText(item);
- let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]);
- if (index != -1) this.data.list[index] = item;
- if (item.pitchOn) this.data.result.push(item[this.data.idname])
- this.setData({
- list: this.data.list,
- result: this.data.result
- })
- resolve(true)
- })
- }
- },
- /* 选中 */
- changeResult(e) {
- let {
- id,
- item
- } = e.currentTarget.dataset, result = this.data.result;
- if (this.data.radio) {
- result = [id];
- } else {
- let isAdd = result.some(v => v == id);
- if (!isAdd) {
- if (item.iscustomsize == 1) {
- if ((item.widthschemeid && item.width == 0) || (item.lengthschemeid && item.length == 0)) {
- item.pitchOn = true;
- this.bindChangeFun()
- if (item) this.selectComponent("#Custom").onClick(item)
- } else {
- result.push(id)
- }
- } else {
- result.push(id)
- }
- } else {
- result = result.filter(v => v != 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.handleSelectCardno && getApp().globalData.handleSelectCardno(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
- })
- },
- onInput(e) {
- let detail = e.detail,
- name = e.currentTarget.dataset.name,
- condition = this.data.params.content.where.tablefilter[name];
- if (detail == condition) return;
- this.data.params.content.where.tablefilter[name] = detail
- },
- /* 开始搜索 */
- startSearch(e) {
- this.getList(true);
- },
- /* 取消搜索 */
- onClear(e) {
- let name = e.currentTarget.dataset.name;
- this.data.params.content.where.tablefilter[name] = ''
- this.setData({
- params: this.data.params
- });
- this.getList(true);
- },
- onReady() {
- this.selectComponent("#ListBox").setHeight(".total", this);
- setTimeout(() => {
- this.selectComponent("#ListBox").setHeight(".total", this);
- }, 350)
- },
- /* 步进器输入框失去焦点 */
- inputBlur(e) {
- const {
- index
- } = e.currentTarget.dataset;
- let item = this.data.list[index];
- 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({
- [`list[${index}].qty`]: 0
- });
- this.setData({
- [`list[${index}].qty`]: qty
- });
- },
- stepperChange(e) {
- const {
- index
- } = e.currentTarget.dataset;
- let item = this.data.list[index];
- if (e.type == 'plus') {
- item.qty += (item.orderaddqty) - 0
- } else {
- item.qty -= item.orderaddqty
- }
- this.setData({
- [`list[${index}]`]: item
- })
- },
- onUnload() {
- getApp().globalData.handleSelectCardno = null;
- }
- })
|