123
chenjingwu
2024-04-12 2cc792b5e113befc3c569ebb7eae9c8d03b9d0b6
force-app/main/default/lwc/lexAssignTaskButton/lexAssignTaskButton.js
@@ -4,17 +4,23 @@
 * @Author: chen jing wu
 * @Date: 2023-05-15 11:14:32
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-05-15 11:50:12
 * @LastEditTime: 2023-09-21 17:13:37
 */
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import init from '@salesforce/apex/OpportunityLightingButtonController.initForAssignTaskButtonButton';
export default class LexAssignTaskButton extends LightningElement {
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import RECORD_TYPE_NAME_BY_INQUIRY_FOLLOW_UP from '@salesforce/label/c.RECORD_TYPE_NAME_BY_INQUIRY_FOLLOW_UP';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class LexAssignTaskButton extends NavigationMixin(LightningElement) {
    @api recordId;
    accountName;
    accountId;
    oppName;
    recordTypeId;
    @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
             console.log(111);
@@ -31,12 +37,16 @@
         }
     }
     connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
           ]);
        init({
            recordId: this.recordId
        }).then(result=>{
            this.accountId = result.accountId;
            this.accountName = result.accountName;
            this.oppName = result.name;
            this.recordTypeId = RECORD_TYPE_NAME_BY_INQUIRY_FOLLOW_UP;
            this.assignTask();
        }).catch(error=>{
            console.log("error");
@@ -44,25 +54,52 @@
        });
     }
     assignTask(){
        //基础路径
        var url = '/setup/ui/recordtypeselect.jsp?ent=01I100000016llf';
        //记录类型
        url += '&p3=01210000000cWfw';
        url += '&retURL=%2F';
        url += '&save_new_url=%2Fa3V%2Fe%3FretURL%3D%252Fa3V%252Fo';
        //客户
        url += '&CF00N100000095tn6=' + this.accountName;
        url += '&CF00N100000095tn6_lkid=' + this.accountId;
        //询价
        url += '&CF00N100000095zcA=' + this.oppName;
        url += '&CF00N100000095zcA_lkid=' + this.recordId;
        //任务状态
        url += '&00N100000095tnR=01 分配';
        //任务区分
        url += '&00N100000095tnP=上级分配任务';
        //任务名称
        url += '&Name=*';
        window.open(url);
        // //基础路径
        // var url = '/setup/ui/recordtypeselect.jsp?ent=01I100000016llf';
        // //记录类型
        // url += '&p3=01210000000cWfw';
        // url += '&retURL=%2F';
        // url += '&save_new_url=%2Fa3V%2Fe%3FretURL%3D%252Fa3V%252Fo';
        // //客户
        // url += '&CF00N100000095tn6=' + this.accountName;
        // url += '&CF00N100000095tn6_lkid=' + this.accountId;
        // //询价
        // url += '&CF00N100000095zcA=' + this.oppName;
        // url += '&CF00N100000095zcA_lkid=' + this.recordId;
        // //任务状态
        // url += '&00N100000095tnR=01 分配';
        // //任务区分
        // url += '&00N100000095tnP=上级分配任务';
        // //任务名称
        // url += '&Name=*';
        // window.open(url);
        const defaultValues = encodeDefaultFieldValues({
            account__c: this.accountId,
            OpportunityId__c: this.recordId,
            taskStatus__c: '01 分配',
            taskDifferent__c: '上级分配任务',
            Name: '*'
        });
        let states =
                {
                    nooverride: '1',
                    navigationLocation: 'LIST_VIEW',
                    // backgroundContext: '/lightning/o/Account/list?filterName=Recent&0.source=alohaHeader',
                    backgroundContext: '/lightning/r/Opportunity/'+this.recordId+'/view',
                    defaultFieldValues: defaultValues,
                };
            // states['recordTypeId'] =  this.recordTypeId;
        states['useRecordTypeCheck'] =  true;
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'task__c',
                actionName: 'new'
            },
            state: states
        });
        this.dispatchEvent(new CloseActionScreenEvent());
     }
}