| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- const _Http = getApp().globalData.http,
- file = require("../../../../utils/matchingFeilType"),
- currency = require("../../../../utils/currency"),
- CNY = value => currency(value, {
- symbol: "¥",
- precision: 2
- }).format();
- let queue = [],
- downCounter = null;
- Component({
- options: {
- addGlobalClass: true
- },
- properties: {
- disabled: {
- type: Boolean
- }, //禁用
- synchronous: {
- type: Boolean
- }, //是否同步按钮显示
- },
- data: {
- directAddition: false,
- actionSheet: false,
- sa_contractid: 0,
- "content": {
- nocache: true,
- pageNumber: 1,
- pageTotal: 1,
- total: null
- },
- actions: [{
- name: getApp().globalData.Language.getMapText('自报价单添加'),
- value: 0
- }, {
- name: getApp().globalData.Language.getMapText('自产品档案添加'),
- value: 1
- }],
- },
- lifetimes: {
- detached: function () {
- if (downCounter) {
- clearTimeout(downCounter);
- if (queue.length) this.changeItem(queue)
- }
- },
- attached: function () {
- getApp().globalData.Language.getLanguagePackage(this)
- }
- },
- methods: {
- openSynchronous() {
- this.selectComponent("#synchronous").onOpen();
- },
- confirm({
- detail
- }) {
- _Http.basic({
- "id": 20231204153904,
- "content": {
- "sa_contractid": this.data.sa_contractid,
- "isadd": detail
- }
- }).then(res => {
- wx.showToast({
- title: res.code == '1' ? getApp().globalData.Language.getMapText('设置成功') : res.msg,
- icon: "none"
- })
- if (res.code == '1') {
- this.selectComponent("#synchronous").onCancel();
- this.getList(this.data.sa_contractid, true)
- } else {
- this.selectComponent("#synchronous").setData({
- loading: false
- })
- }
- })
- },
- /* 获取产品列表 */
- getList(id, init) {
- let content = this.data.content;
- content.sa_contractid = id;
- content.sys_enterpriseid = getCurrentPages().find(v => v.__route__ == 'packageA/contract/detail').data.detail.sys_enterpriseid;
- if (init) content.pageNumber = 1
- _Http.basic({
- "id": "20221122165302",
- content
- }).then(res => {
- console.log("项目产品清单列表", res)
- if (res.code != '1') return wx.showToast({
- title: res.data,
- 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.showMarketprice = CNY(value.marketprice)
- value.showAmount = CNY(value.amount)
- value.className = value.itemclass.length == 0 ? getApp().globalData.Language.getMapText('暂无类目') : value.itemclass.map(v => v.itemclassname);
- value.brandName = value.brand.length == 0 ? getApp().globalData.Language.getMapText('暂无品牌') : value.brand.map(v => v.brandname);
- value.discountrate = (value.discountrate * 100).toFixed(2);
- value.price = (value.price - 0).toFixed(2);
- return value;
- })
- 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_contractid: id
- })
- })
- },
- /* 去选择产品 */
- addProduct() {
- let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/detail');
- if (page.data.detail.typemx) {
- wx.navigateTo({
- url: '/packageA/select/offers/select?params=' + JSON.stringify({
- "id": 20221222151302,
- "content": {
- nocache: true,
- "sa_projectid": page.data.detail.sa_projectid,
- "where": {
- "condition": ""
- }
- }
- }) + '&radio=true'
- })
- getApp().globalData.handleSelect = this.selectOffers.bind(this);
- } else {
- wx.navigateTo({
- url: '/packageA/select/product/select?params=' + JSON.stringify({
- "id": 20221124093602,
- "version": 1,
- "content": {
- nocache: true,
- sa_contractid: this.data.sa_contractid,
- total: null,
- where: {
- condition: "",
- "istool": 1 //是否是工具
- }
- }
- })
- });
- getApp().globalData.handleSelect = this.handleSelectProduct.bind(this);
- }
- },
- actionSheetOnSelected({
- detail
- }) {
- if (detail.value == 0) {
- this.addProduct();
- } else {
- wx.navigateTo({
- url: '/packageA/select/product/select?params=' + JSON.stringify({
- "id": 20221124093602,
- "version": 1,
- "content": {
- nocache: true,
- sa_contractid: this.data.sa_contractid,
- total: null,
- where: {
- condition: "",
- "istool": 0 //是否是工具
- }
- }
- })
- });
- getApp().globalData.handleSelect = this.handleSelectProduct.bind(this);
- }
- this.closeActionSheet()
- },
- openActionSheet() {
- this.setData({
- actionSheet: true
- })
- },
- closeActionSheet() {
- this.setData({
- actionSheet: false
- })
- },
- selectOffers({
- item
- }) {
- wx.redirectTo({
- url: '/packageA/select/product/select?params=' + JSON.stringify({
- "id": 20221123162902,
- "content": {
- nocache: true,
- sa_quotedpriceid: item.sa_quotedpriceid,
- sa_contractid: this.data.sa_contractid,
- where: {
- condition: ""
- }
- }
- })
- });
- setTimeout(() => {
- getApp().globalData.handleSelect = this.handleSelectProduct.bind(this);
- }, 1000)
- },
- /* 处理选择产品 */
- handleSelectProduct({
- list
- }) {
- let that = this;
- wx.showModal({
- title: getApp().globalData.Language.getMapText('提示'),
- content: getApp().globalData.Language.joint([{
- t: 1,
- v: '是否确认添加',
- r: " "
- }, {
- v: list.length,
- r: " "
- }, {
- t: 1,
- v: '件产品',
- r: "?"
- }]),
- cancelText: getApp().globalData.Language.getMapText('取消'),
- confirmText: getApp().globalData.Language.getMapText('确定'),
- complete: ({
- confirm
- }) => {
- if (confirm) _Http.basic({
- "id": 20221123164402,
- "content": {
- "sa_contractid": that.data.sa_contractid,
- items: list.map(v => {
- return {
- "itemid": v.itemid,
- "price": v.marketprice,
- "qty": v.orderminqty || 1,
- "marketprice": v.marketprice,
- "remarks": "",
- type: "指定单价"
- }
- })
- }
- }).then(res => {
- console.log("合同添加产品", res);
- wx.showToast({
- title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('添加成功') + '!',
- icon: "none"
- });
- if (res.code != '1') return;
- setTimeout(() => {
- wx.navigateBack();
- setTimeout(() => {
- that.getList(that.data.sa_contractid, true)
- }, 300)
- this.renewalAmount();
- }, 300)
- })
- }
- })
- },
- /* 删除产品 */
- deleteItems({
- detail
- }) {
- _Http.basic({
- "id": 20221123164502,
- "version": 1,
- "content": {
- "sa_contractid": this.data.sa_contractid,
- "sa_contract_itemsids": detail
- }
- }).then(res => {
- console.log("批量删除产品", res);
- wx.showToast({
- title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') + '!' : res.msg,
- icon: "none"
- })
- if (res.code == '1') this.setData({
- list: this.data.list.filter(v => detail.indexOf(v.sa_contract_itemsid) == -1)
- })
- this.renewalAmount();
- })
- },
- /* 生成修改队列 */
- changeQueue({
- detail
- }) {
- let i = queue.findIndex(v => v.sa_contract_itemsid == detail.sa_contract_itemsid);
- i == -1 ? queue.push(detail) : queue[i] = detail;
- clearTimeout(downCounter)
- downCounter = setTimeout(() => {
- this.changeItem(queue)
- }, 0);
- },
- changeItem(items) {
- console.log("修改", items)
- _Http.basic({
- "id": 20221122200302,
- "version": 1,
- "content": {
- "sa_contractid": this.data.sa_contractid,
- items
- }
- }, false).then(res => {
- console.log("合同批量修改产品清单", res)
- queue = [];
- let list = this.data.list;
- if (res.code != '1') {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- this.setData({
- list
- })
- return;
- }
- items.forEach(v => {
- v.discountrate = (v.discountrate * 100).toFixed(2);
- v.showAmount = CNY(v.showAmount)
- let i = list.findIndex(value => v.sa_contract_itemsid == value.sa_contract_itemsid);
- if (i != -1) this.data.list[i] = {
- ...list[i],
- ...v
- }
- });
- this.setData({
- list
- })
- this.renewalAmount();
- })
- },
- renewalAmount() {
- _Http.basic({
- "id": 20221121195102,
- "content": {
- nocache: true,
- "sa_contractid": this.data.sa_contractid
- },
- }).then(res => {
- console.log("更新金额", res)
- let page = getCurrentPages()[getCurrentPages().length - 1];
- if (res.code == '1' && page.__route__ == 'packageA/contract/detail') {
- let qy = page.data.briefs.findIndex(v => v.label == '签约金额(元)')
- let qy1 = page.data.list1.findIndex(v => v.label == '签约金额')
- page.setData({
- [`briefs[${qy}].value`]: CNY(res.data.signamount),
- [`list1[${qy1}].value`]: CNY(res.data.signamount),
- })
- }
- })
- },
- }
- })
|