123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- const _Http = getApp().globalData.http,
- file = require("../../../../utils/FormatTheAttachment");
- let queue = [],
- downCounter = null,
- Counter = null;
- Component({
- properties: {
- disabled: Boolean, //禁用
- isAdd: {
- type: Boolean,
- value: false
- }
- },
- data: {
- sa_orderid: 0,
- "content": {
- nocache: true,
- "pageNumber": 1,
- pageTotal: 1,
- total: null
- },
- toolcount: 1
- },
- lifetimes: {
- detached: function () {
- if (downCounter) {
- clearTimeout(downCounter);
- this.changeItem(queue)
- }
- },
- },
- methods: {
- /* 获取产品列表 */
- getList(obj, init) {
- let content = this.data.content;
- content.sa_orderid = obj.id;
- if (init) content.pageNumber = 1;
- _Http.basic({
- "id": "20230116104102",
- content
- }).then(res => {
- console.log("工具借用列表", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- 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 : "";
- }
- value.amount = value.amount * obj.toolcount;
- value.qty = value.qty * obj.toolcount;
- return value;
- })
- let page = getCurrentPages().find(v => v.__route__ == 'packageA/borrow/detail').data.detail;
- let base = {
- sa_orderid: page.sa_orderid,
- sys_enterpriseid: page.sys_enterpriseid,
- sa_contractid: page.sa_contractid,
- type: page.type,
- };
- this.setData({
- list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
- "content.pageNumber": res.pageNumber + 1,
- "content.pageSize": res.pageSize,
- "content.pageTotal": res.pageTotal,
- "content.total": res.total,
- sa_orderid: obj.id,
- toolcount: obj.toolcount,
- base
- })
- })
- },
- /* 统一交期 */
- dateChange(e) {
- let that = this;
- wx.showModal({
- title: '提示',
- content: `是否确定将当前产品列表交期统一设置为:${e.detail.value}`,
- complete: (res) => {
- if (res.confirm) _Http.basic({
- "id": 20230104143802,
- "content": {
- "sa_orderid": that.data.sa_orderid,
- "needdate": e.detail.value
- }
- }).then(res => {
- console.log('统一设置交期', res)
- wx.showToast({
- title: res.msg == '成功' ? '设置成功' : res.msg,
- icon: "none"
- })
- if (res.msg == '成功') that.setData({
- list: that.data.list.map(v => {
- v.needdate = e.detail.value;
- return v
- })
- })
- })
- }
- })
- },
- /* 修改 */
- changeProduct({
- detail
- }) {
- let obj = detail,
- index = this.data.list.findIndex(v => v.itemid == detail.itemid),
- data = this.data.list[index],
- calculatePrice = data.qty != obj.qty;
- if (data.qty == obj.qty && data.remarks == obj.remarks && data.needdate == obj.needdate) return;
- _Http.basic({
- "id": 20230116101602,
- "content": {
- ...this.data.base,
- "items": [detail]
- }
- }).then(res => {
- console.log("产品修改", res)
- if (res.msg != '成功') {
- wx.showToast({
- title: res.msg,
- icon: "none"
- });
- obj = data;
- };
- data = {
- ...data,
- ...obj
- };
- if (res.msg == '成功' && calculatePrice) {
- let page = getCurrentPages()[getCurrentPages().length - 1];
- if (page) {
- let amount = page.data.detail.amount - data.amount;
- data.amount = ((data.qty - 0) * (data.price - 0)).toFixed(2);
- amount = (amount + (data.amount - 0)).toFixed(2);
- page.setData({
- "detail.amount": amount - 0
- })
- }
- }
- this.setData({
- [`list[${index}]`]: data
- })
- })
- },
- /* 删除 */
- deleteItem({
- detail
- }) {
- let that = this;
- wx.showModal({
- title: '提示',
- content: `是否确认删除“${detail.itemname}”?`,
- complete: (res) => {
- if (res.confirm) _Http.basic({
- "id": 20230116103402,
- "content": {
- sa_orderid: detail.sa_orderid,
- "sa_orderitemsids": [
- detail.sa_orderitemsid
- ]
- }
- }).then(s => {
- if (s.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- });
- that.setData({
- list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
- });
- /* 更新金额 */
- let page = getCurrentPages()[getCurrentPages().length - 1];
- let amount = (page.data.detail.amount - detail.amount).toFixed(2);
- if (page) page.setData({
- "detail.amount": amount - 0
- })
- })
- }
- })
- },
- /* 去添加产品 */
- addProduct() {
- wx.navigateTo({
- url: `/select/product/index?params=${JSON.stringify({
- "id":20230116111602,
- "content": {
- nocache:true,
- "sa_orderid": this.data.sa_orderid, //订单ID
- "pageNumber": 1,
- "pageTotal": 1,
- "total": 0,
- "pageSize": 20,
- "where": {
- "condition": ""
- }
- }
- })}`
- });
- getApp().globalData.handleSelect = this.handleSelect.bind(this);
- },
- /* 处理新增产品 */
- handleSelect(detail) {
- let that = this;
- wx.showModal({
- title: '提示',
- content: `是否确认添加${detail.result.length}件商品?`,
- complete: (res) => {
- if (res.confirm) _Http.basic({
- "id": 20230116101602,
- "content": {
- ...that.data.base,
- "items": detail.list.map(v => {
- return {
- sa_orderitemsid: 0,
- "itemid": v.itemid, //商品ID
- "qty": 1, //数量
- }
- })
- }
- }).then(s => {
- console.log('新增产品', s)
- wx.showToast({
- title: s.msg == '成功' ? '添加成功' : s.msg,
- icon: "none"
- });
- if (s.msg == '成功') setTimeout(() => {
- that.getList(that.data.sa_orderid, true);
- wx.navigateBack();
- that.updateThePrice();
- }, 300)
- })
- }
- });
- },
- /* 步进器数值改变 */
- stepperChange(e) {
- switch (e.type) {
- case 'plus':
- this.data.toolcount += 1;
- break;
- case 'minus':
- this.data.toolcount -= 1;
- break;
- case 'blur':
- this.data.toolcount = e.detail.value;
- break;
- }
- console.log(this.data.toolcount)
- this.setToolcount();
- },
- /* 设置总数 */
- setToolcount() {
- clearTimeout(Counter);
- let page = getCurrentPages().find(v => v.__route__ == 'packageA/borrow/detail');
- Counter = setTimeout(() => {
- _Http.basic({
- "id": 20230116092702,
- "content": {
- "sa_orderid": this.data.sa_orderid,
- "sa_contractid": page.data.detail.sa_contractid,
- toolcount: this.data.toolcount
- }
- }).then(res => {
- console.log("修改套数", res)
- console.log(page.data.detail.toolcount)
- if (res.msg != '成功') {
- wx.showToast({
- title: res.msg,
- icon: "none"
- });
- this.setData({
- toolcount: page.data.detail.toolcount
- })
- } else {
- page.getDetail(true);
- }
- })
- }, 300)
- },
- /* 使用接口更新总价 */
- updateThePrice() {
- _Http.basic({
- "id": 20230105101102,
- "content": {
- "sa_orderid": this.data.sa_orderid
- },
- }).then(res => {
- console.log("获取列表总价", res)
- if (res.msg != '成功') return wx.showToast({
- title: `产品总价更新失败`,
- icon: "none"
- });
- let page = getCurrentPages()[getCurrentPages().length - 1];
- if (page) page.setData({
- "detail.amount": res.data.amount - 0
- })
- })
- }
- }
- })
|