const tipsStatus = function (item) { let obj = { class: "not-poiid", text: "", href: "javascript:void(0);", } if (item.is_stop_service == 1) { obj.text = "" } else if (!item.poiid && item.buy_type == 3 && item.is_white == 0) { obj.text = '优惠服务仅支持授权新店铺,请尽快授权!' } else if (!item.poiid) { obj.text = '未完成授权,请及时授权店铺' } else if (item.is_shenhe == 3) { obj.class = 'stop-service' obj.text = '店铺授权已失效' } else if (item.poiid && !item.sn) { obj.text = '第3步:设置打印小票模板并保存完成' obj.href = `addShop.php?pro=1&sid=${item.sid}&pid=${item.pid}` } return obj } 改进代码
时间: 2024-03-10 12:44:22 浏览: 104
AVR单片机项目-ADC键盘(源码+仿真+效果图).zip
可以将 obj 的初始值和属性的默认值放在一起,同时使用三元表达式简化代码:
```
const tipsStatus = function (item) {
const isStopService = item.is_stop_service === 1;
const isAuthorized = Boolean(item.poiid);
const isAuthorizedNewShop = !isAuthorized && item.buy_type === 3 && item.is_white === 0;
const isAuthorizationExpired = isAuthorized && item.is_shenhe === 3;
const isSetPrintTicketTemplate = isAuthorized && !item.sn;
const obj = {
class: isAuthorizationExpired ? 'stop-service' : 'not-poiid',
text: isStopService ? '' : isAuthorizedNewShop ? '优惠服务仅支持授权新店铺,请尽快授权!' :
!isAuthorized ? '未完成授权,请及时授权店铺' : isAuthorizationExpired ? '店铺授权已失效' :
isSetPrintTicketTemplate ? '第3步:设置打印小票模板并保存完成' : '',
href: isSetPrintTicketTemplate ? `addShop.php?pro=1&sid=${item.sid}&pid=${item.pid}` : 'javascript:void(0);',
};
return obj;
}
```
阅读全文